Docker image configured for cross-compiling Go programs with CGO support as needed by exo. May be useful for others as well.
See entrypoint for supported operating systems and architectures.
See Dockerfile for details on which MacOS SDK is used.
The cross-compilation toolchain is provided by Zig.
Based on the official golang image, so you
use this image in much the same way. Primarily, the go is rooted at
/go
, so you put your code into /go/src/YOURAPP
.
Cross-compilation is driven by the GOOS
and GOARCH
variables.
Example:
docker run \
-e GOOS=darwin \
-e GOARCH=amd64 \
--mount "type=bind,source=${PWD},target=/go/src/example" \
-w /go/src/example \
ghcr.io/deref/golang-cross \
go build .
To speed up builds, you can use cached package sources by adding another mount:
--mount "type=bind,source=${GOPATH}/pkg/mod,target=/go/pkg/mod"
Pushing a version tag to this repository to build a new release using Github Actions. See ./.github/workflows/publish.yml for details.