From e141e713d61ea33e47b98c1b1f438d772a63e167 Mon Sep 17 00:00:00 2001 From: Barrie Bremner Date: Fri, 26 Mar 2021 18:58:28 +0000 Subject: [PATCH] Set flags to cross-compile darwin/arm64 on darwin/amd64 and vice versa This is an attempt to fix a lack of keychain support in darwin/arm64 binaries that have been cross-compiled on other platforms as described in https://github.com/99designs/aws-vault/issues/758 and hinted at in the linked https://github.com/99designs/keyring/commit/756c48deecbd97e8fe3581f20efbaa136689cf80 Given the keychain support from keyring[1] is provided by cgo, and CGO is disabled by default in cross-compilation, we need to enable that, and deal with dev tooling/libraries. I dug this solution from the Go issues, specifically https://github.com/golang/go/issues/44112 Be warned, I am not familiar with the ins and outs of Go compilation, especially when it comes to cross-compilation of CGO code, but at least in this case, this change allows for a functional cross-compiled binary. I fully expect that attempting to cross-compile darwin/arm64 on anything other than darwin/amd64 (or the opposite way around) is going to end badly. [1] https://github.com/99designs/keyring --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f010b2b78..d50d4db87 100644 --- a/Makefile +++ b/Makefile @@ -24,10 +24,10 @@ release: binaries dmgs SHA256SUMS @echo "\nTo update homebrew-cask run\n\n brew bump-cask-pr --version $(shell echo $(VERSION) | sed 's/v\(.*\)/\1/') aws-vault\n" aws-vault-darwin-amd64: $(SRC) - GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -o $@ . + GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 SDKROOT=$(shell xcrun --sdk macosx --show-sdk-path) go build $(BUILD_FLAGS) -o $@ . aws-vault-darwin-arm64: $(SRC) - GOOS=darwin GOARCH=arm64 go build $(BUILD_FLAGS) -o $@ . + GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 SDKROOT=$(shell xcrun --sdk macosx --show-sdk-path) go build $(BUILD_FLAGS) -o $@ . aws-vault-freebsd-amd64: $(SRC) GOOS=freebsd GOARCH=amd64 go build $(BUILD_FLAGS) -o $@ .