Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macos: missing resolv.h #131

Closed
sluongng opened this issue Nov 1, 2023 · 8 comments
Closed

macos: missing resolv.h #131

sluongng opened this issue Nov 1, 2023 · 8 comments

Comments

@sluongng
Copy link

sluongng commented Nov 1, 2023

See https://buildbuddy.buildbuddy.io/invocation/c6420695-476d-426b-8a7d-579220dc612f?actionDigest=648cda0569553603f5dec696187ed931ff0c521bad72caa9cfbf3c32dab687a5%2F183&actionResultDigest=dfac351eeb1fd8186001dcf2088eec77d38f8b39576bdcf5f9d895c6cca643a0%2F183#action for detail of failing action.

ERROR: /private/var/tmp/_bazel_sluongng/06e573a93bc2d6a9cad4ad41f00b4310/external/io_bazel_rules_go/BUILD.bazel:42:7: GoStdlib external/io_bazel_rules_go/stdlib_/pkg [for tool] failed: (Exit 1): builder failed: error executing command (from target @io_bazel_rules_go//:stdlib)
  (cd /private/var/tmp/_bazel_sluongng/06e573a93bc2d6a9cad4ad41f00b4310/execroot/buildbuddy && \
  exec env - \
    CC=external/zig_sdk/tools/aarch64-macos-none/c++ \
    CGO_CFLAGS='-no-canonical-prefixes -Wno-builtin-macro-redefined -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" -mcpu=apple_m1 -O2 -DNDEBUG' \
    CGO_ENABLED=1 \
    CGO_LDFLAGS='-Wl,-headerpad_max_install_names -O2 -DNDEBUG' \
    GOARCH=arm64 \
    GOEXPERIMENT=nocoverageredesign \
    GOOS=darwin \
    GOPATH='' \
    GOROOT=external/go_sdk_darwin_arm64 \
    GOROOT_FINAL=GOROOT \
    GOTOOLCHAIN=local \
    PATH=external/zig_sdk/tools:external/zig_sdk/tools/aarch64-macos-none:/bin:/usr/bin \
  bazel-out/macos_arm64-opt-exec-5213AA54-ST-6d27f6f190b5/bin/external/go_sdk_darwin_arm64/builder_reset/builder stdlib -sdk external/go_sdk_darwin_arm64 -installsuffix darwin_arm64 -out bazel-out/macos_arm64-opt-exec-5213AA54-ST-6d27f6f190b5/bin/external/io_bazel_rules_go/stdlib_ -package std -package runtime/cgo -gcflags '')
# Configuration: fc8217665648e5b159391c23607348f6fa3f0b1fbff682755523ba4fafcb3d0c
# Execution platform: //platforms:macos_arm64
# net
bazel-out/macos_arm64-opt-exec-5213AA54-ST-6d27f6f190b5/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>
         ^~~~~~~~~~

Possibly related to ziglang/zig#16674 and/or ziglang/zig#12628

@motiejus
Copy link
Collaborator

motiejus commented Nov 1, 2023

Looking at ziglang/zig#17152, looks like resolv.h was removed by design. Is there something we can do besides #10?

Today's zig source (ziglang/zig@7c5d01b) shows that there is no MacOS-related resolv.h:

$ git ls-files | grep resolv.h
lib/libc/include/generic-glibc/resolv.h
lib/libc/include/generic-musl/resolv.h
lib/libc/musl/include/resolv.h
lib/libc/musl/src/include/resolv.h
lib/libc/wasi/libc-top-half/musl/include/resolv.h
lib/libc/wasi/libc-top-half/musl/src/include/resolv.h
$

@motiejus
Copy link
Collaborator

motiejus commented Nov 1, 2023

Also, ziglang/zig#12628 is linux-specific and is only linking step, so unrelated here.

@sluongng
Copy link
Author

sluongng commented Nov 2, 2023

We were using v2.1.2 of this repo, so we are only on Zig v0.11.0 and not yet affected by the change in
ziglang/zig#17152 ?

I am not sure if #10 is the only solution but it might be one solution.

> fd resolv.h /Library/Developer/CommandLineTools
/Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/usr/include/resolv.h
/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/resolv.h
/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include/resolv.h

@motiejus
Copy link
Collaborator

motiejus commented Nov 2, 2023

Same with 0.11.0:

$ git ls-files | grep resolv.h
lib/libc/include/generic-glibc/resolv.h
lib/libc/include/generic-musl/resolv.h
lib/libc/musl/include/resolv.h
lib/libc/musl/src/include/resolv.h
lib/libc/wasi/libc-top-half/musl/include/resolv.h
lib/libc/wasi/libc-top-half/musl/src/include/resolv.h
$ 

@JonathanHope
Copy link

JonathanHope commented Nov 30, 2023

I can into this as well. As near as I can tell there is no easy way to cross compile Go programs for macos because of this. It always fails with the error:

/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
#include <resolv.h>
         ^~~~~~~~~~
1 error generate

It would definitely be nice to be able to use the Zig compiler to handle the CGo cross compile duties.

@JonathanHope
Copy link

One thing I tried here was to use native Go network stack: -tags=netgo. Unfortunately 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

@oh-tarnished
Copy link

I guess we need to wait out until zig-12 gets released.

https://github.com/ziglang/zig/milestone/23

@motiejus
Copy link
Collaborator

As mentioned in #10, there are big, known problems when compiling to OSX. I clarified the link to #10 in #135, so this issue does not bring bring any extra value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants