You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One-click static-friendly musl-based GCC macOS-to-Linux cross-compilers
based on richfelker/musl-cross-make.
brew install filosottile/musl-cross/musl-cross
By default it will install full cross compiler toolchains targeting musl Linux amd64 and arm64.
You can then use x86_64-linux-musl- or aarch64-linux-musl- versions of the
tools to build for the target. For example x86_64-linux-musl-cc will compile C
code to run on musl Linux amd64.
The "musl" part of the target is important: the binaries will ONLY run on a
musl-based system, like Alpine. However, if you build them as static binaries by
passing -static as an LDFLAG they will run anywhere. Musl is specifically
engineered to support static binaries.
To use this as a Go cross-compiler for cgo, use CC, GOOS/GOARCH,
CGO_ENABLED, and -extldflags.
(Note: a custom build takes around ten minutes per architecture on an M2.
The installed size is between 150MB and 300MB per architecture.)
If you encounter issues with a missing musl-gcc binary, the build system might
be assuming the presence of the musl host compiler
wrapper. That
should be reported as an issue, but you might be able to workaround it by
creating a symlink: