Skip to content

Commit 4ec1fea

Browse files
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.
1 parent 087c2f0 commit 4ec1fea

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,17 @@ jobs:
147147
env:
148148
GOOS: ${{ matrix.goos }}
149149
GOARCH: ${{ matrix.goarch }}
150+
ACTIONSOS: ${{ matrix.runson }}
150151
run: |
151152
mkdir dist out
153+
if [ "$ACTIONSOS" == "macos-latest" ] && [ "$GOOS" == "darwin" ]; then
154+
# When building for macOS _on_ macOS we must force CGo to get
155+
# correct hostname resolution behavior. (This must be conditional
156+
# because other cross-compiles won't have suitable headers
157+
# available to use CGo; darwin_amd64 has suitable headers to
158+
# cross-build for darwin_arm64.)
159+
export CGO_ENABLED=1
160+
fi
152161
go build -ldflags "-w -s" -o dist/ .
153162
zip -r -j out/${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip dist/
154163

0 commit comments

Comments
 (0)