3 Commits

Author SHA1 Message Date
Sebastian Zagrodzki
cb06b9fb0d Add a go.mod for v1.1.0. This will make the Go proxy (#86)
prefer v1.* (with a valid go.mod file) over the v2.1.0+incompatible version
(which doesn't have a go.mod file).
2020-11-09 10:57:35 +01:00
Sebastian Zagrodzki
76f12f69ac Refresh pacman in the appveyor build (#84)
...for updated Go package versions. Go 1.12 is gone from the MSYS2 repos.
2020-11-09 10:07:43 +01:00
Sebastian Zagrodzki
0995919da4 Since go 1.15 new() on CGo structs is no longer supported: (#85)
./fakelibusb_test.go:101:87: libusbContext can't be allocated in Go; it is incomplete (or unallocatable)
./fakelibusb_test.go:131:10: libusbDevHandle can't be allocated in Go; it is incomplete (or unallocatable)

Use CGo malloc to obtain unique pointers.
2020-11-09 09:50:43 +01:00
6 changed files with 28 additions and 5 deletions

View File

@@ -6,9 +6,11 @@ export GOROOT=/mingw64/lib/go
export GOPATH=/go
export CGO_ENABLED=1
set -x
pacman --noconfirm -S \
mingw64/mingw-w64-x86_64-go \
mingw64/mingw-w64-x86_64-libusb
mingw-w64-x86_64-go \
mingw-w64-x86_64-libusb
go version
go get -t github.com/google/gousb/...

8
.appveyor/upgrade_pacman.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
export PATH="/mingw64/bin:${PATH}"
set -x
curl -O https://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz
curl -O https://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig
pacman-key --verify msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig &&\
pacman --noconfirm -U msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz
pacman --noconfirm -Syy pacman

View File

@@ -3,6 +3,7 @@ platform: x64
clone_folder: C:\msys64\go\src\github.com\google\gousb
install:
- C:\msys64\usr\bin\bash.exe -lc "cd /go/src/github.com/google/gousb/ && .appveyor/./install.sh"
- C:\msys64\usr\bin\bash.exe -l /go/src/github.com/google/gousb/.appveyor/upgrade_pacman.sh
- C:\msys64\usr\bin\bash.exe -lc "cd /go/src/github.com/google/gousb/ && .appveyor/install.sh"
build: off

View File

@@ -98,7 +98,7 @@ type fakeLibusb struct {
claims map[*libusbDevice]map[uint8]bool
}
func (f *fakeLibusb) init() (*libusbContext, error) { return new(libusbContext), nil }
func (f *fakeLibusb) init() (*libusbContext, error) { return newContextPointer(), nil }
func (f *fakeLibusb) handleEvents(c *libusbContext, done <-chan struct{}) { <-done }
func (f *fakeLibusb) getDevices(*libusbContext) ([]*libusbDevice, error) {
ret := make([]*libusbDevice, 0, len(fakeDevices))
@@ -128,7 +128,7 @@ func (f *fakeLibusb) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
return nil, fmt.Errorf("invalid USB device %p", d)
}
func (f *fakeLibusb) open(d *libusbDevice) (*libusbDevHandle, error) {
h := new(libusbDevHandle)
h := newDevHandlePointer()
f.mu.Lock()
defer f.mu.Unlock()
f.handles[h] = d

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module github.com/google/gousb
go 1.13

View File

@@ -508,6 +508,7 @@ func libusbSetDebug(c *libusbContext, lvl int) {
C.gousb_set_debug((*C.libusb_context)(c), C.int(lvl))
}
// for obtaining unique CGo pointers.
func newDevicePointer() *libusbDevice {
return (*libusbDevice)(unsafe.Pointer(C.malloc(1)))
}
@@ -515,3 +516,11 @@ func newDevicePointer() *libusbDevice {
func newFakeTransferPointer() *libusbTransfer {
return (*libusbTransfer)(unsafe.Pointer(C.malloc(1)))
}
func newContextPointer() *libusbContext {
return (*libusbContext)(unsafe.Pointer(C.malloc(1)))
}
func newDevHandlePointer() *libusbDevHandle {
return (*libusbDevHandle)(unsafe.Pointer(C.malloc(1)))
}