Friday, March 1, 2024
HomeGolangCGo, Zig, netgo, and libresolv - Getting Assist

CGo, Zig, netgo, and libresolv – Getting Assist


I’m engaged on getting an app (GitHub – JonathanHope/armaria: Armaria is a quick, open, and native first bookmarks supervisor) constructing for MacOS. This app makes use of CGo, significantly mattn/sqlite. I’m delegating the CGO a part of the compilation to Zig which has been superior on the Linux/Home windows cross compilation entrance. Nevertheless I’m not satisfied that I can cross compile for MacOS (legally) from Linux.

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

/nix/retailer/dwmb0qcai52d0zkgpm6f5ifx2a8yvsdg-go-1.21.3/share/go/src/internet/cgo_unix_cgo_darwin.go:10:10: deadly error: 'resolv.h' file not discovered
   10 | #embody <resolv.h>
      |          ^~~~~~~~~~
1 error generated.

It is because Zig doesn’t embody libresolv for MacOS targets. After doing a little noodling I figured I’d simply use the Go community stack (netgo). Nevertheless doing that simply gave me a special error:

/nix/retailer/dwmb0qcai52d0zkgpm6f5ifx2a8yvsdg-go-1.21.3/share/go/pkg/instrument/linux_amd64/hyperlink: operating zig failed: exit standing 1
error: unable to seek out Dynamic system library 'resolv' utilizing technique 'paths_first'. searched paths: none


activity: Didn't run activity "release-snapshot": exit standing 1

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

To see if this was the one drawback I dropped the libresolv.tbd information from the Mac SDK in and linked them which really labored for amd64. Weirdly although the arm64 goal fails with new error:

error=didn't construct for darwin_arm64: exit standing 1: # github.com/jonathanhope/armaria/cmd/cli
/nix/retailer/dwmb0qcai52d0zkgpm6f5ifx2a8yvsdg-go-1.21.3/share/go/pkg/instrument/linux_amd64/hyperlink: operating zig failed: exit standing 1
error: unable to seek out framework 'CoreFoundation'. searched paths:  none

This takes me to my second query: Why does the amd64 goal not want CoreFoundation, however the arm64 goal does?

I’m conscious of the osxcross challenge, however I don’t suppose that utilizing the MacOS SDK is allowed underneath the license it falls underneath. The license seems (to my layperson eyes) to forbid internet hosting it in Github AND utilizing it to compile from a Linux host. It’s a disgrace as a result of I do know I may resolve this with that method.

I suppose that leaves me utilizing MacOS runners on Gitub. I’m not against the 10x minutes, nevertheless it’s a disgrace that I gained’t be capable to check the discharge pipeline domestically. I posted this on the off likelihood anybody had any concepts.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments