From 4ec1feaa3d41a516b87fbf80191203081a8de62e Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 5 Jan 2022 15:10:05 -0800 Subject: [PATCH] build: CGO_ENABLED when building for macOS Normally when we cross-compile we do so without CGo, because we don't have suitable C headers available for systems other than the host. However, building for macOS on macOS is special because there are sufficient headers available on darwin_amd64 to build for both darwin_amd64 _and_ darwin_arm64. Also, we _must_ use CGo on macOS because the system resolver is only available via darwin's libc, and so building without CGo produces executables that don't resolve hostnames correctly. This is a conditional in bash to avoid having to duplicate the entire step. Perhaps later we'll find a more general version of this which can avoid the special case, but this is sufficient for the moment. --- .github/workflows/build.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c0fd888b3..0aefa68c2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -147,8 +147,17 @@ jobs: env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} + ACTIONSOS: ${{ matrix.runson }} run: | mkdir dist out + if [ "$ACTIONSOS" == "macos-latest" ] && [ "$GOOS" == "darwin" ]; then + # When building for macOS _on_ macOS we must force CGo to get + # correct hostname resolution behavior. (This must be conditional + # because other cross-compiles won't have suitable headers + # available to use CGo; darwin_amd64 has suitable headers to + # cross-build for darwin_arm64.) + export CGO_ENABLED=1 + fi go build -ldflags "-w -s" -o dist/ . zip -r -j out/${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip dist/