Unable to build Zig from source after LLVM21 update (macOS aarch64, homebrew)

Here is the current script I’ve been using:

  (cd ~/src/zig/build && 
  cmake .. \
     -DZIG_STATIC_LLVM=ON \
     -DCMAKE_C_COMPILER="$(brew --prefix llvm)/bin/clang" \
     -DCMAKE_CXX_COMPILER="$(brew --prefix llvm)/bin/clang++" \
     -DCMAKE_PREFIX_PATH="$(brew --prefix llvm);$(brew --prefix lld);$(brew --prefix zstd)" \
     -DZIG_STATIC_ZSTD=ON \
     -DZIG_NO_LIB=ON \
     -DCMAKE_BUILD_TYPE=Release \
     -DCMAKE_CXX_FLAGS="-I/opt/homebrew/opt/llvm/include/c++/v1" \
     -GNinja &&
   ninja install/local)

I think I only had to add the -DCMAKE_C_COMPILER and -DCMAKE_CXX_COMPILER flags to get it to start compiling in the first place; I didn’t need either of those flags back when building against LLVM20. Without those flags, cmake wanted to use the XCode versions.

I started with an empty ~/src/zig/build directory before running that script.

The couple of relevant snippets of output are:

[18/20] Linking CXX executable zig2
FAILED: zig2
: && /opt/homebrew/opt/llvm/bin/clang++ -I/opt/homebrew/opt/llvm/include/c++/v1 -O3 -DNDEBUG -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX15.2.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Wl,-stack_size,0x10000000 CMakeFiles/zig2.dir/zig2.c.o CMakeFiles/zig2.dir/compiler_rt.c.o -o zig2 -L/opt/homebrew/Cellar/llvm/21.1.0/lib -Wl,-rpath,/opt/homebrew/Cellar/llvm/21.1.0/lib  zigcpp/libzigcpp.a  /opt/homebrew/opt/llvm/lib/libclangFrontendTool.a  /opt/homebrew/opt/llvm/lib/libclangCodeGen.a  /opt/homebrew/opt/llvm/lib/libclangFrontend.a  /opt/homebrew/opt/llvm/lib/libclangDriver.a  /opt/homebrew/opt/llvm/lib/libclangSerialization.a  /opt/homebrew/opt/llvm/lib/libclangSema.a  < --- SNIP --- >
Undefined symbols for architecture arm64:
  "clang::CodeGen::CodeGenFunction::EmitX86CpuIs(llvm::StringRef)", referenced from:
      clang::CodeGen::CodeGenFunction::FormX86ResolverCondition(clang::CodeGen::CodeGenFunction::FMVResolverOption const&) in libclangCodeGen.a[46](CodeGenFunction.cpp.o)

I put the full output in a gist.

AFAICT, I have LLVM21 properly installed. I’m not sure what else would have changed in the migration from 20 to 21 that would suddenly cause these undefined codegen symbols.

I already checked the Wiki links for building from source, and troubleshooting builds; neither of those have any recent relevant updates here.

Is anyone else able to build master from source on macOS? I would prefer to avoid building LLVM from source, since it was working fine with LLVM20 from Homebrew.

Or do you think I am missing a dependency somewhere? I wasn’t able to find any information online about these particular missing symbols.

Since it works fine if you build LLVM/Clang/LLD from source, I think this is a Homebrew issue.