-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Zig passes incorrect sysroot to Clang when combined with Nix #14569
Comments
Excellent! Thanks for investigating and submitting a bug report! |
I'm running into a similar problem with sysroot and not finding headers on macOS with nix when building a project linking with C libraries. After some searching I've found that a standard
I work around the errors by manually specifying the sys root on the zig invocation like so:
|
Hey @winterqt, I am currently looking into this issue as part of a different issue, and have a design question for you. What would you say is the correct behavior for an impure build: should Zig see native macOS SDK or strictly link against Nix provided headers and libs? In other words, if we detect Nix on macOS when building natively, should we detect the Apple SDK or not? |
For context, here's the changeset I am correctly working on: https://github.com/ziglang/zig/compare/macos-autodetect-sdk-tmp The idea is that if we are targeting an Apple platform from an Apple device (well, mostly from macOS), we try to link against the Apple SDK provided it exists. With Nix coming into play, do we then create the following decision matrix:
I will see if I can hack on nixpkgs on macOS and see if my changeset makes sense. I am also trying to make sure that |
Zig Version
0.10.1
Steps to Reproduce and Observed Behavior
This is once again a bug that I've only been able to observe when compiling 0.10.1, but I believe it is still present in master, and should be fixed.
std.zig.system.NativePaths.detect
has special support for Nix, by searchingNIX_CFLAGS_COMPILE
. When this is done, it results in absolute include directories being returned.There are two codepaths that stage3's stage1 compilation for Darwin under Nix can take -- the sandboxed case and the non-sandboxed case:
zig/src/main.zig
Lines 2510 to 2527 in a5b34a6
The sandboxed case is when the macOS SDK cannot be found, resulting in
-isystem
being passed to specify include directories. The issue is when the sandbox is disabled, and Xcode is installed. This results in-isysroot
specifying a path to the macOS SDK, and absolute include directories being specified with-iwithsysroot
.For example, this results in
-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -iwithsysroot /nix/store/j88zc0bv69jpiyh3k2g6s67x3i3wgs24-llvm-15.0.7-dev/include
being passed to Clang, which results in the incorrect search path/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk//nix/store/j88zc0bv69jpiyh3k2g6s67x3i3wgs24-llvm-15.0.7-dev/include
being used.This manifests itself as failures to find headers such as
stdlib.h
when compiling stage1 from stage3, as @kubkon observed in #14559 (comment).There's at least a few ways to fix this, but I'm unsure which is the most optimal. For example, we can return the
is_nix
value fromNativePaths.detect
and special-casehas_sysroot
to always be false ifis_nix
is true (which I've confirmed does fix the issue).Expected Behavior
For it to pass the correct flags.
The text was updated successfully, but these errors were encountered: