zig
zig copied to clipboard
Build failure on macos with homebrew in non-standard location
Zig Version
0b47e69b7c0aedbc142400305cda86ef58b41656
Steps to Reproduce
I have homebrew in ~/homebrew instead of /opt/homebrew. Because of reasons, my company puts its own files in /opt/homebrew...
This was working a few weeks ago, if I had to guess, it stopped around the time of the llvm15 merge
$ git clone https://github.com/ziglang/zig.git
$ cmake -S . -B build -DZIG_STATIC_LLVM=ON
$ cmake --build build
[...]
[ 81%] Built target embedded_softfloat
[ 85%] Built target zigcpp
[ 86%] Built target opt_c_util
[ 97%] Built target zigstage1
Consolidate compiler generated dependencies of target zig1
make[2]: *** No rule to make target `/opt/homebrew/lib/libz3.dylib', needed by `zig1'. Stop.
make[1]: *** [CMakeFiles/zig1.dir/all] Error 2
make: *** [all] Error 2
~/homebrew/lib/libz3.dylib does exist
Expected Behavior
zig gets built
Actual Behavior
can't build because of missing file
Try passing
-DCMAKE_PREFIX_PATH="$HOME/homebrew"
to cmake.
Doing a clean build from latest master, no luck :(
$ git pull
$ git clean -fdx
$ cmake -S . -B build -DZIG_STATIC_LLVM=ON -DCMAKE_PREFIX_PATH="$HOME/homebrew"
$ cmake --build build
[...]
[ 97%] Built target zigstage1
[ 98%] Building CXX object CMakeFiles/zig1.dir/src/stage1/zig0.cpp.o
make[2]: *** No rule to make target `/opt/homebrew/lib/libz3.dylib', needed by `zig1'. Stop.
-DZIG_STATIC_ZLIB=ON ?
Also no :(
(Does anyone know how the "path to libz3.dylib" is calculated - so we can at least figure out if this is "a problem for all people who put homebrew in $HOME" or just "a problem for people with non-standard homebrew and some misleading fake files placed in the standard homebrew location"? I tried reading the source but couldn't track it down...)
pkg-config --cflags --libs zlib afaik
I've found the underlying issue. The llvm dependency is downloaded as a prebuilt package in homebrew instead of of built from source. The resolution of the dependencies in zig is resolved via llvm-config (for e.g. llvm-config --ldflags --link-static --system-libs). This results in the wrong path as the system where the packages were built has homebrew installed on /opt/homebrew/.
Solution:
Reinstall llvm from source so that llvm-config outputs the correct path.
brew install llvm --build-from-source before installing zig.
So looks like this is a homebrew issue, but they explicitly reject supporting people who install in non-default locations, and I can't imagine zig wanting to add a specific hack for this one weird situation -- so I guess there's nothing that can be done except "everybody who wants to build zig with ~/homebrew needs to hit the error, google, find this thread, then uninstall binary llvm and re-install from source" D: