Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use libusb 1.0.27 as backend on linux #50

Merged
merged 6 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,9 @@ and go-gettable.
Supported platforms at the moment are Linux, macOS and Windows (exclude constraints are also specified
for Android and iOS to allow smoother vendoring into cross platform projects).

## Dependencies

On linux, the 'libudev' package is required for building.

On Ubuntu:

apt install libudev-dev


On Fedora:

dnf install systemd-devel
The `hidapi` on linux unfortunately requires `libuddev` (`libudev-dev` on ubuntu, `systemd-devel` on fedora). Therefore,
this library includes [`libusb`](https://github.com/libusb/libusb) which we use as a backend on `linux`, and thus avoid
runtime dependencies.


## Cross-compiling
Expand All @@ -58,6 +49,7 @@ such, `gowchar` was also vendored in inline (copyright headers and origins prese
The components of `hid` are licensed as such:

* `hidapi` is released under the [three licenses](https://github.com/libusb/hidapi/blob/master/LICENSE.txt): [GPL-V3](https://github.com/libusb/hidapi/blob/master/LICENSE-gpl3.txt), [3-clause BSD](https://github.com/libusb/hidapi/blob/master/LICENSE-bsd.txt) and [original HIDAPI](https://github.com/libusb/hidapi/blob/master/LICENSE-orig.txt) license.
* `libusb` is released under [GPLv2.1](https://github.com/libusb/libusb/blob/master/COPYING)
* `go.hid` was released under the [2-clause BSD](https://github.com/GeertJohan/go.hid/blob/master/LICENSE) license.
* `gowchar` is released under the [3-clause BSD](https://github.com/orofarne/gowchar/blob/master/LICENSE) license.

Expand Down
9 changes: 0 additions & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ install:
- go version

for:
# Linux has its own script without -arch and -cc.
# The linux builder also runs lint.
- matrix:
only:
- image: Ubuntu
build_script:
- sudo apt-get -qy --no-install-recommends install libudev-dev
- gcc --version
- go build ./...
- CGO_ENABLED=0 go build ./...
Expand All @@ -33,12 +30,6 @@ for:
- go test -v ./...
- CGO_ENABLED=0 go test -v ./...

# linux/386 is disabled.
- matrix:
exclude:
- image: Ubuntu
GETH_ARCH: 386

# Windows builds for amd64 + 386.
- matrix:
only:
Expand Down
42 changes: 28 additions & 14 deletions hid_enabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,54 @@
package hid

/*
Linux uses the 'libudev' package.

On Fedora:

dnf install systemd-devel

On Ubuntu:

apt install libhidapi-dev

Linux/hidapi requires the 'libudev' package. Fedora:`dnf install systemd-devel`, Ubuntu `apt install libhidapi-dev`.
However, we prefer to not require libudev, which is why `libusb` is included, and enabled
specifically for the linux platform, below.
*/

/*

#cgo CFLAGS: -I./hidapi/hidapi
#cgo CFLAGS: -DDEFAULT_VISIBILITY=""
#cgo CFLAGS: -DPOLL_NFDS_TYPE=int

#cgo linux CFLAGS: -DOS_LINUX -D_GNU_SOURCE -DHAVE_SYS_TIME_H
#cgo linux,!android LDFLAGS: -lrt -ludev
#cgo linux CFLAGS: -I./libusb/libusb -DOS_LINUX -D_GNU_SOURCE -DHAVE_SYS_TIME_H -DHAVE_CLOCK_GETTIME
#cgo linux,!android LDFLAGS: -lrt

#cgo darwin CFLAGS: -DOS_DARWIN -DHAVE_SYS_TIME_H
#cgo darwin LDFLAGS: -framework CoreFoundation -framework IOKit -lobjc

#cgo windows CFLAGS: -DOS_WINDOWS
#cgo windows LDFLAGS: -lsetupapi

#cgo freebsd CFLAGS: -DOS_FREEBSD
#cgo freebsd LDFLAGS: -lusb

#cgo openbsd CFLAGS: -DOS_OPENBSD

#if defined(OS_LINUX) || defined(OS_DARWIN) || defined(DOS_FREEBSD) || defined(OS_OPENBSD)
#include <poll.h>
#endif

#ifdef OS_LINUX
#include "hidapi/linux/hid.c"
#include "os/events_posix.h"
#include "os/threads_posix.h"

#include "os/events_posix.c"
#include "os/threads_posix.c"

#include "os/linux_usbfs.c"
#include "os/linux_netlink.c"

#include "core.c"
#include "descriptor.c"
#include "hotplug.c"

#include "io.c"
#include "strerror.c"
#include "sync.c"

#include "hidapi/libusb/hid.c"

#elif OS_DARWIN
#include "hidapi/mac/hid.c"
#elif OS_WINDOWS
Expand Down
2 changes: 2 additions & 0 deletions hidapi/libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
https://github.com/libusb/hidapi .
********************************************************/

#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* needed for wcsdup() before glibc 2.10 */
#endif

/* C */
#include <stdio.h>
Expand Down
7 changes: 7 additions & 0 deletions libusb/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build dummy

// Package c contains only a C file.
//
// This Go file is part of a workaround for `go mod vendor`.
// Please see the file dummy.go at the root of the module for more information.
package libusb
3 changes: 3 additions & 0 deletions libusb/libusb/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ifndef CONFIG_H
#define CONFIG_H
#endif
Loading