CGo, Zig, netgo, and libresolv

I’m working on getting an app (GitHub - JonathanHope/armaria: Armaria is a fast, open, and local first bookmarks manager) building for MacOS. This app uses CGo, particularly mattn/sqlite. I’m delegating the CGO part of the compilation to Zig which has been awesome on the Linux/Windows cross compilation front. However I am not convinced that I can cross compile for MacOS (legally) from Linux.

When I try to compile (zig cc -target x86_64-macos-none -g0) for MacOS I get the following:

/nix/store/dwmb0qcai52d0zkgpm6f5ifx2a8yvsdg-go-1.21.3/share/go/src/net/cgo_unix_cgo_darwin.go:10:10: fatal error: 'resolv.h' file not found
   10 | #include <resolv.h>
      |          ^~~~~~~~~~
1 error generated.

This is because Zig doesn’t include libresolv for MacOS targets. After doing some noodling I figured I would just use the Go network stack (netgo). However doing that just gave me a different error:

/nix/store/dwmb0qcai52d0zkgpm6f5ifx2a8yvsdg-go-1.21.3/share/go/pkg/tool/linux_amd64/link: running zig failed: exit status 1
error: unable to find Dynamic system library 'resolv' using strategy 'paths_first'. searched paths: none


task: Failed to run task "release-snapshot": exit status 1

This takes me to my first question: Why is libresolv being linked if I’m using netgo?

To see if this was the only problem I dropped the libresolv.tbd files from the Mac SDK in and linked them which actually worked for amd64. Weirdly though the arm64 target fails with new error:

error=failed to build for darwin_arm64: exit status 1: # github.com/jonathanhope/armaria/cmd/cli
/nix/store/dwmb0qcai52d0zkgpm6f5ifx2a8yvsdg-go-1.21.3/share/go/pkg/tool/linux_amd64/link: running zig failed: exit status 1
error: unable to find framework 'CoreFoundation'. searched paths:  none

This takes me to my second question: Why does the amd64 target not need CoreFoundation, but the arm64 target does?

I am aware of the osxcross project, but I don’t think that using the MacOS SDK is allowed under the license it falls under. The license appears (to my layperson eyes) to forbid hosting it in Github AND using it to compile from a Linux host. It’s a shame because I know I could solve this with that approach.

I guess that leaves me using MacOS runners on Gitub. I’m not opposed to the 10x minutes, but it’s a shame that I won’t be able to test the release pipeline locally. I posted this on the off chance anyone had any ideas.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.