From 99227b60cedfb278b1b6d6ac9ae965f47fce5ccf Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 28 Sep 2021 11:02:15 +0100 Subject: [PATCH] Update CI to use Go 1.17, produce Apple Silicon builds (closes #844) --- .circleci/config.yml | 16 ++++--- contrib/macos/create-pkg.sh | 4 ++ src/multicast/multicast_darwin.go | 40 ++-------------- src/multicast/multicast_darwin_cgo.go | 69 +++++++++++++++++++++++++++ src/multicast/multicast_other.go | 4 +- 5 files changed, 89 insertions(+), 44 deletions(-) create mode 100644 src/multicast/multicast_darwin_cgo.go diff --git a/.circleci/config.yml b/.circleci/config.yml index fa49c34d..065f2b0b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ version: 2.1 jobs: lint: docker: - - image: circleci/golang:1.16 + - image: circleci/golang:1.17 steps: - checkout @@ -23,7 +23,7 @@ jobs: build-linux: docker: - - image: circleci/golang:1.16 + - image: circleci/golang:1.17 steps: - checkout @@ -124,11 +124,11 @@ jobs: echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config - run: - name: Install Go 1.16 + name: Install Go 1.17 command: | cd /tmp - curl -LO https://dl.google.com/go/go1.16.darwin-amd64.pkg - sudo installer -pkg /tmp/go1.16.darwin-amd64.pkg -target / + curl -LO https://dl.google.com/go/go1.17.darwin-amd64.pkg + sudo installer -pkg /tmp/go1.17.darwin-amd64.pkg -target / #- run: # name: Install Gomobile @@ -142,11 +142,15 @@ jobs: GO111MODULE=on GOOS=darwin GOARCH=amd64 ./build cp yggdrasil /tmp/upload/$CINAME-$CIVERSION-darwin-amd64 cp yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-darwin-amd64; + GO111MODULE=on GOOS=darwin GOARCH=arm64 ./build + cp yggdrasil /tmp/upload/$CINAME-$CIVERSION-darwin-arm64 + cp yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-darwin-arm64; - run: name: Build for macOS (.pkg format) command: | PKGARCH=amd64 sh contrib/macos/create-pkg.sh + PKGARCH=arm64 sh contrib/macos/create-pkg.sh mv *.pkg /tmp/upload/ #- run: @@ -164,7 +168,7 @@ jobs: build-other: docker: - - image: circleci/golang:1.16 + - image: circleci/golang:1.17 steps: - checkout diff --git a/contrib/macos/create-pkg.sh b/contrib/macos/create-pkg.sh index cc9a74f7..919c45ed 100755 --- a/contrib/macos/create-pkg.sh +++ b/contrib/macos/create-pkg.sh @@ -15,6 +15,10 @@ command -v mkbom >/dev/null 2>&1 || ( sudo make install || (echo "Failed to build mkbom"; exit 1) ) +# Build Yggdrasil +echo "running GO111MODULE=on GOOS=darwin GOARCH=${PKGARCH-amd64} ./build" +GO111MODULE=on GOOS=darwin GOARCH=${PKGARCH-amd64} ./build + # Check if we can find the files we need - they should # exist if you are running this script from the root of # the yggdrasil-go repo and you have ran ./build diff --git a/src/multicast/multicast_darwin.go b/src/multicast/multicast_darwin.go index 7ad0c543..22cf3998 100644 --- a/src/multicast/multicast_darwin.go +++ b/src/multicast/multicast_darwin.go @@ -1,49 +1,17 @@ -//go:build darwin -// +build darwin +//go:build !cgo && (darwin || ios) +// +build !cgo +// +build darwin ios package multicast -/* -#cgo CFLAGS: -x objective-c -#cgo LDFLAGS: -framework Foundation -#import -NSNetServiceBrowser *serviceBrowser; -void StartAWDLBrowsing() { - if (serviceBrowser == nil) { - serviceBrowser = [[NSNetServiceBrowser alloc] init]; - serviceBrowser.includesPeerToPeer = YES; - } - [serviceBrowser searchForServicesOfType:@"_yggdrasil._tcp" inDomain:@""]; -} -void StopAWDLBrowsing() { - if (serviceBrowser == nil) { - return; - } - [serviceBrowser stop]; -} -*/ -import "C" import ( "syscall" - "time" "golang.org/x/sys/unix" ) func (m *Multicast) _multicastStarted() { - if !m.isOpen { - return - } - C.StopAWDLBrowsing() - for intf := range m._interfaces { - if intf == "awdl0" { - C.StartAWDLBrowsing() - break - } - } - time.AfterFunc(time.Minute, func() { - m.Act(nil, m._multicastStarted) - }) + } func (m *Multicast) multicastReuse(network string, address string, c syscall.RawConn) error { diff --git a/src/multicast/multicast_darwin_cgo.go b/src/multicast/multicast_darwin_cgo.go new file mode 100644 index 00000000..b7d7358c --- /dev/null +++ b/src/multicast/multicast_darwin_cgo.go @@ -0,0 +1,69 @@ +//go:build (darwin && cgo) || (ios && cgo) +// +build darwin,cgo ios,cgo + +package multicast + +/* +#cgo CFLAGS: -x objective-c +#cgo LDFLAGS: -framework Foundation +#import +NSNetServiceBrowser *serviceBrowser; +void StartAWDLBrowsing() { + if (serviceBrowser == nil) { + serviceBrowser = [[NSNetServiceBrowser alloc] init]; + serviceBrowser.includesPeerToPeer = YES; + } + [serviceBrowser searchForServicesOfType:@"_yggdrasil._tcp" inDomain:@""]; +} +void StopAWDLBrowsing() { + if (serviceBrowser == nil) { + return; + } + [serviceBrowser stop]; +} +*/ +import "C" +import ( + "syscall" + "time" + + "golang.org/x/sys/unix" +) + +func (m *Multicast) _multicastStarted() { + if !m.isOpen { + return + } + C.StopAWDLBrowsing() + for intf := range m._interfaces { + if intf == "awdl0" { + C.StartAWDLBrowsing() + break + } + } + time.AfterFunc(time.Minute, func() { + m.Act(nil, m._multicastStarted) + }) +} + +func (m *Multicast) multicastReuse(network string, address string, c syscall.RawConn) error { + var control error + var reuseport error + var recvanyif error + + control = c.Control(func(fd uintptr) { + reuseport = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1) + + // sys/socket.h: #define SO_RECV_ANYIF 0x1104 + recvanyif = unix.SetsockoptInt(int(fd), syscall.SOL_SOCKET, 0x1104, 1) + }) + + switch { + case reuseport != nil: + return reuseport + case recvanyif != nil: + return recvanyif + default: + return control + } +} diff --git a/src/multicast/multicast_other.go b/src/multicast/multicast_other.go index 9977951c..263f4ffc 100644 --- a/src/multicast/multicast_other.go +++ b/src/multicast/multicast_other.go @@ -1,5 +1,5 @@ -//go:build !linux && !darwin && !netbsd && !freebsd && !openbsd && !dragonflybsd && !windows -// +build !linux,!darwin,!netbsd,!freebsd,!openbsd,!dragonflybsd,!windows +//go:build !linux && !darwin && !ios && !netbsd && !freebsd && !openbsd && !dragonflybsd && !windows +// +build !linux,!darwin,!ios,!netbsd,!freebsd,!openbsd,!dragonflybsd,!windows package multicast