Skip to content

Commit

Permalink
Fix vendoring
Browse files Browse the repository at this point in the history
There is a rule for go build: all sources files of a given package must
be in the directory of that package. Not in subdirectories.
Which means that {#include "hidapi/mac/hid.c"} is not correct as hid.c
is not in the package directory, so "go build" will not notice its
changes and go mod -vendor will not work (golang/go#26366).

So this patch creates 3 files (hidapi_linux.h, hidapi_windows.h,
hidapi_mac.h) which are go-generated by internal/gen.go. The generator
just inlines any includes from the libusb/ and hidapi/ directories.
This means that the libusb/ and hidapi/ are not needed anymore for
distribution (and for go mod -vendor): they are used only for the "go
generate" phase.
  • Loading branch information
dolmen committed Feb 20, 2022
1 parent 8596c6a commit 56a6faf
Show file tree
Hide file tree
Showing 7 changed files with 19,383 additions and 19 deletions.
25 changes: 6 additions & 19 deletions hid_enabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

package hid

/*
#cgo CFLAGS: -I./hidapi/hidapi
//go:generate go run ./internal/gen.go

#cgo linux CFLAGS: -I./libusb/libusb -DDEFAULT_VISIBILITY="" -DOS_LINUX -D_GNU_SOURCE -DPOLL_NFDS_TYPE=int
/*
#cgo linux CFLAGS: -DDEFAULT_VISIBILITY="" -DOS_LINUX -D_GNU_SOURCE -DPOLL_NFDS_TYPE=int
#cgo linux,!android LDFLAGS: -lrt
#cgo darwin CFLAGS: -DOS_DARWIN
#cgo darwin LDFLAGS: -framework CoreFoundation -framework IOKit
Expand All @@ -21,24 +21,11 @@ package hid
#ifdef OS_LINUX
#include <poll.h>
#include "os/threads_posix.c"
#include "os/poll_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"
#include "hidapi_linux.h"
#elif OS_DARWIN
#include "hidapi/mac/hid.c"
#include "hidapi_mac.h"
#elif OS_WINDOWS
#include "hidapi/windows/hid.c"
#include "hidapi_windows.h"
#endif
*/
import "C"
Expand Down
Loading

0 comments on commit 56a6faf

Please sign in to comment.