Open carlocab opened 2 years ago
This is probably related to #10946. I haven't been able to dig deeply into it, but I think the behaviour we're seeing in Zig 0.9.1 on Darwin is that:
This leads to the rather undesirable situation that it uses non-system headers (e.g. provided by Homebrew) but links with system libraries, which sounds like a recipe for disaster.
This comment seems to be a good summary of what's happening:
Note that the issue occurs with existing
zig 0.9.0
bottle. It appears to work on previouszig 0.8.1
, so breakage may be changes between those releases.With
zig 0.8.1
,fastfec
build uses sysroot and SDK paths (snippets of command):/opt/homebrew/Cellar/zig/0.8.1_1/bin/zig clang -fno-caret-diagnostics -target aarch64-unknown-macosx-gnu -nostdinc -fno-spell-checking -isystem /opt/homebrew/Cellar/zig/0.8.1_1/lib/zig/include -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include -Xclang ........... -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -iwithsysroot /usr/include -iwithsysroot /usr/local/include -iframeworkwithsysroot /Library/Frameworks -iframeworkwithsysroot /System/Library/Frameworks ...........
With
zig 0.9+
, there is nosysroot
or SDK paths/opt/homebrew/Cellar/zig/0.9.0/bin/zig clang -fno-caret-diagnostics -target aarch64-unknown-macosx-gnu -nostdinc -fno-spell-checking -isystem /opt/homebrew/Cellar/zig/0.9.0/lib/zig/include -isystem /opt/homebrew/Cellar/zig/0.9.0/lib/zig/libc/include/aarch64-macos.12-gnu -isystem /opt/homebrew/Cellar/zig/0.9.0/lib/zig/libc/include/any-macos.12-any -isystem /opt/homebrew/Cellar/zig/0.9.0/lib/zig/libc/include/any-macos-any .......... -I /opt/homebrew/Cellar/pcre/8.45/include -isystem /usr/include /System/Library/Frameworks .........
Zig seems to want to replace headers from the macOS SDK with its own bundled ones, but then only provides a limited subset of them.
I guess this might be fine (albeit not ideal) if the linker avoids linkage with system libraries too, but the linker seems to do the exact opposite vis a vis the system headers here.
Zig Version
0.9.0
Steps to Reproduce
First, try to build
fastfec
0.0.4 with onlyzig build -Dvendored-pcre=false
:if you don't have
pcre
installed, this will fail with the following error:Now, do the same after installing
pcre
andpkg-config
(e.g.brew install pcre pkg-config
). Compilation succeeds, butfastfec
links with/usr/lib/libpcre.dylib
:The macOS SDK does not provide headers for PCRE, which means that
zig
used the headers from Homebrew except linked with the systemlibpcre
.Expected Behavior
I expected my build to link with Homebrew
pcre
. This was the behaviour under Zig 0.8.1:Actual Behavior
Linkage with macOS
libpcre
.