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
Using hermetic_cc_toolchain to cross-compile a Go application for Darwin/Mac OS X using Go 1.21 fails with the following error:
ERROR: /home/bits/.cache/bazel/_bazel_bits/031ab286c04183ba9beae60237d64a79/external/io_bazel_rules_go/BUILD.bazel:42:7: GoStdlib external/io_bazel_rules_go/stdlib_/pkg failed: (Exit 1): builder failed: error executing command (from target @io_bazel_rules_go//:stdlib) bazel-out/k8-opt-exec-2B5CBBC6-ST-b33d65c724e6/bin/external/go_sdk/builder_reset/builder stdlib -sdk external/go_sdk -installsuffix darwin_arm64 -out ... (remaining 7 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
# net
bazel-out/k8-fastbuild-ST-b33d65c724e6/bin/external/io_bazel_rules_go/stdlib_/src/net/cgo_unix_cgo_darwin.go:10:10: fatal error: 'resolv.h' file not found
#include <resolv.h>
^~~~~~~~~~
1 error generated.
stdlib: error running subcommand external/go_sdk/bin/go: exit status 1
Target //hello:hello failed to build
Use --verbose_failures to see the command lines of failed build steps.
It appears that Go 1.21 added #include <resolv.h> to the Darwin build in the net package. This header does not appear to be included in the Zig sandbox, and looking really quickly: it may be missing from the upstream Zig project also, although it does exist for musl and glibc. Sadly I don't have enough understanding of how this cross compilation magic works to understand how to fix this, but I suspect Zig may need to add this header file?
A workaround is to set pure="on" on the go_binary rule, which causes the standard library to be compiled with CGO_ENABLED=0, which avoids the problematic include.
This header does not appear to be included in the Zig sandbox, and looking really quickly: it may be missing from the upstream Zig project also,
Upstream zig includes only what is necessary to build zig itself for MacOS. resolv.h is not in scope, so it is not included. zig cc accepts -F, which can be used for all those extra headers and sweet tbd files.
Thanks for the context! I figured it was something like that. I now see the README.md does in fact document this, and I just didn't find it. I may try to make an edit that mentions the Go standard library, resolv.h and CoreFoundation, since those are the errors that show up when attempting to use this, in the hopes that search results may lead future people to the fact that this is known to not work. Thanks!
Using hermetic_cc_toolchain to cross-compile a Go application for Darwin/Mac OS X using Go 1.21 fails with the following error:
It appears that Go 1.21 added
#include <resolv.h>
to the Darwin build in thenet
package. This header does not appear to be included in the Zig sandbox, and looking really quickly: it may be missing from the upstream Zig project also, although it does exist for musl and glibc. Sadly I don't have enough understanding of how this cross compilation magic works to understand how to fix this, but I suspect Zig may need to add this header file?A workaround is to set
pure="on"
on thego_binary
rule, which causes the standard library to be compiled withCGO_ENABLED=0
, which avoids the problematic include.To reproduce, see my example project: https://github.com/evanj/rulesgotest
The following works and produces a correct binary with Go 1.20.6, but fails with Go 1.21rc3:
The text was updated successfully, but these errors were encountered: