Native path detection in Nix shell environment on macOS overrides desired framework path
Zig Version
0.12.0-dev.694+937e8cb70
Steps to Reproduce and Observed Behavior
Reproduction: https://github.com/mitchellh/zig-framework-bug
If you run zig build from within a nix shell, you'll get an error (shown below). If you run zig build outside a nix shell, it works.
zig build-lib harfbuzz Debug native: error: error(compilation): clang failed with stderr: In file included from /Users/mitchellh/code/go/src/github.com/mitchellh/zig-framework-bug/harfbuzz/src/harfbuzz.cc:8:
In file included from /Users/mitchellh/code/go/src/github.com/mitchellh/zig-framework-bug/harfbuzz/src/hb-coretext.cc:35:
In file included from /Users/mitchellh/code/go/src/github.com/mitchellh/zig-framework-bug/harfbuzz/src/hb-coretext.h:37:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/ApplicationServices.framework/Headers/ApplicationServices.h:27:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/ApplicationServices.framework/Frameworks/ATS.framework/Headers/ATS.h:28:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/ApplicationServices.framework/Frameworks/ATS.framework/Headers/ATSLayoutTypes.h:28:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/ApplicationServices.framework/Frameworks/ATS.framework/Headers/ATSTypes.h:24:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGGeometry.h:8:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBase.h:13:10: fatal error: 'CoreFoundation/CFCGTypes.h' file not found
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBase.h:13:10: note: did not find header 'CFCGTypes.h' in framework 'CoreFoundation' (loaded from '/nix/store/acx94cri4a9vf1i3zn1wrx0y7863saxv-apple-framework-CoreFoundation-11.0.0/Library/Frameworks')
zig build-lib harfbuzz Debug native: error: the following command failed with 1 compilation errors:
/nix/store/6ix0gk4ldijkgzy1yvsd3vbwy98bgfp9-zig-0.12.0-dev.694+937e8cb70/bin/zig build-lib -cflags -DHAVE_STDBOOL_H -DHAVE_UNISTD_H -DHAVE_SYS_MMAN_H -DHAVE_PTHREAD=1 -DHAVE_CORETEXT=1 -- /Users/mitchellh/code/go/src/github.com/mitchellh/zig-framework-bug/harfbuzz/src/harfbuzz.cc -lc++ -lc --cache-dir /Users/mitchellh/code/go/src/github.com/mitchellh/zig-framework-bug/zig-cache --global-cache-dir /Users/mitchellh/.cache/zig --name harfbuzz -static -I /Users/mitchellh/code/go/src/github.com/mitchellh/zig-framework-bug/harfbuzz/src -iframework /Users/mitchellh/code/go/src/github.com/mitchellh/zig-framework-bug/apple-sdk/zig-cache/xcode_frameworks/Frameworks -isystem /Users/mitchellh/code/go/src/github.com/mitchellh/zig-framework-bug/apple-sdk/zig-cache/xcode_frameworks/include -L /Users/mitchellh/code/go/src/github.com/mitchellh/zig-framework-bug/apple-sdk/zig-cache/xcode_frameworks/lib -framework ApplicationServices --listen=-
Build Summary: 1/4 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install harfbuzz transitive failure
└─ zig build-lib harfbuzz Debug native 1 errors
/Users/mitchellh/code/go/src/github.com/mitchellh/zig-framework-bug/harfbuzz/src/harfbuzz.cc:1:1: error: unable to build C object: clang exited with code 1
Expected Behavior
It is looking in my Xcode app path but it should be looking in the explicit framework path I specified in -iframework. It looks like this native path detection for Nix overrides what I requested in build.zig, or is an ordering issue: https://github.com/ziglang/zig/blob/62a0fbdaef575c857a7fa5f911447dd7275c9f22/lib/std/zig/system/NativePaths.zig#L21
As a workaround, if I specify a non-native arch or set a sysroot (to any dummy value), the build works fine because it forces Zig to NOT do native path detection.