I'm building a Go application with native (CGO_ENABLED=1) SQLite support using https://github.com/mattn/go-sqlite3.
I'm trying to get the builder docker image to a reasonable size. (goreleaser/goreleaser-cross works for all platforms, but is over 8GB).
When using Zig (0.14.0) as the cross compiler, Linux and Windows targets build/run fine on both an Alpine and Debian/bookworm-image (go 1.24.1) but mac compilation fails with:
/usr/local/go/pkg/tool/linux_amd64/link: running zig failed: exit status 1
/opt/zig/zig cc -target x86_64-macos -arch x86_64 -m64 -Wl,-headerpad,1144 -o $WORK/b001/exe/a.out /tmp/go-link-2504977538/go.o /tmp/go-link-2504977538/000000.o /tmp/go-link-2504977538/000001.o /tmp/go-link-2504977538/000002.o /tmp/go-link-2504977538/000003.o /tmp/go-link-2504977538/000004.o /tmp/go-link-2504977538/000005.o /tmp/go-link-2504977538/000006.o /tmp/go-link-2504977538/000007.o /tmp/go-link-2504977538/000008.o /tmp/go-link-2504977538/000009.o /tmp/go-link-2504977538/000010.o /tmp/go-link-2504977538/000011.o /tmp/go-link-2504977538/000012.o /tmp/go-link-2504977538/000013.o /tmp/go-link-2504977538/000014.o /tmp/go-link-2504977538/000015.o /tmp/go-link-2504977538/000016.o /tmp/go-link-2504977538/000017.o /tmp/go-link-2504977538/000018.o /tmp/go-link-2504977538/000019.o /tmp/go-link-2504977538/000020.o /tmp/go-link-2504977538/000021.o /tmp/go-link-2504977538/000022.o -lresolv -O2 -g -O2 -g -lpthread -framework CoreFoundation -framework Security
error: unable to find dynamic system library 'resolv' using strategy 'paths_first'. searched paths: none
What I understand is the resolv-library is supposed to be part of libc, so if Zig doesn't provide it (by not having a musl-implementation for Mac), it should come from a Mac SDK.
I've also tried supplying it with:
(export GOOS=darwin && export GOARCH=amd64 && export CC="zig cc -target x86_64-macos --sysroot ${MACOS_SDK} -isysroot ${MACOS_SDK} -I${MACOS_SDK}/usr/include -Wno-nullability-completeness" && go build -o dist/$GOOS/$GOARCH/)
To no avail, still getting the "unable to find dynamic system library"...
What might be missing? How can I get CGO Linux→Mac cross-compilation working with a recent Zig and Go?
libc6*-cross
packages matching the C cross-compiler called by zig for macosx target.