Look at zig for cross-platform CGO builds
Author: jonjohnsonjrCreated Dec 9, 2020Updated Jun 10, 2026
Labelshelp wantedgood first issuelifecycle/frozen
Most of the solutions I've seen for doing cross-platform builds involves doing virtualization inside docker containers for each target platform. This doesn't really work for ko, because I'd like to be able to use it in environments where I don't have (or want to have) docker installed.
I came across https://github.com/ziglang/zig/issues/7342 which seems to indicate that it's (almost?) possible to use zig with go to do this painlessly. I'd like for this to work without ko having any knowledge of what's happening, just some stuff users can set in their environment to make it work, e.g.:
# More likely in .ko.yaml, but the default "static" image lacks libc... maybe make default based on CGO_ENABLED?
KO_DEFAULTBASEIMAGE="gcr.io/distroless/base"
CGO_ENABLED=1
CC="zig cc"
# Proposal from current issue, subject to change
ZIG_CGO=1This way, we won't have to land any changes to ko for this to work (other than documenting it).
Source: ko-build/ko