Unable to compile master Zig from source on MacOS

Currently, following the directions on the github repository wiki, compilation fails with this:

[ 94%] Linking CXX executable zig2
...
ld: multiple errors: could not parse bitcode object file /opt/homebrew/opt/llvm/lib/libclangCodeGen.a(X86.cpp.o): 'Unknown attribute kind (102) (Producer: 'LLVM21.1.2' Reader: 'LLVM APPLE_1_1700.3.19.1_0')', using libLTO version 'LLVM version 17.0.0' in '/opt/homebrew/opt/llvm/lib/libclangCodeGen.a(X86.cpp.o)'; ...

Here is the full make log. I have llvm 21 and lld 21 installed, both /opt/homebrew/bin and /opt/homebrew/opt/llvm/bin at the beginning of my PATH, and I have LDFLAGS, CPPFLAGS, and CMAKE_PREFIX_PATH set according to brew info llvm.
I posted this in the Zig Programming Language Discord server, and someone mentioned that they got the exact same error when compiling, but they could compile 0.15.x fine. Did the compilation process change for 0.16?

Welcome to Ziggit!

Looks like the build process is trying to use Apple LLVM and homebrew LLVM at the same time? Using prebuilt LLVM versions is a bit of a pain especially on macOS since none of them seem to be fully suitable for building Zig.

I wouldn’t recommend using either to build Zig from source anyway, just use GitHub - ziglang/zig-bootstrap: take off every zig and compile everything from source. Works every time.

How would I use zig-bootstrap to contribute to zig? It doesn’t have zig as a submodule, it just vendors it into the repository directly - could I just replace the zig folder in zig-bootstrap with an actual clone of the Zig repository?

There’s a guide on how to obtain an optimized stage3 Zig build by using zig-bootstrap here.
You can then use that stage3 build to compile stage4 debug builds from within the regular Zig repository. I use this script:

$HOME/git/zig/build/stage3/bin/zig build -p "$HOME/git/zig/build/stage4" \
                                         --search-prefix "$HOME/git/zig-bootstrap/out/native-macos-none-native" \
                                         --zig-lib-dir "$HOME/git/zig/lib" \
                                         -Dstatic-llvm \
                                         -Denable-llvm \
                                         -Dno-lib \
                                         $@

1 Like