hylo-lang / llvm-build

LLVM library binaries that are compatible with the Swift runtime
2 stars 0 forks source link

Do something about the findability of zstd for the macOS builds #8

Open dabrahams opened 6 months ago

dabrahams commented 6 months ago
dave@DaveA-MBP14-5 Swifty-LLVM % ~/Downloads/llvm-17.0.6-arm64-apple-darwin23.3.0-Debug/bin/llvm-config 
~/Downloads/llvm-17.0.6-arm64-apple-darwin23.3.0-Debug/bin/llvm-config 
dyld[27721]: Library not loaded: /opt/local/lib/libzstd.1.dylib
  Referenced from: <80280D10-861C-3C78-A1C8-3E5E93E9E2B9> /Users/dave/Downloads/llvm-17.0.6-arm64-apple-darwin23.3.0-Debug/bin/llvm-config
  Reason: tried: '/opt/local/lib/libzstd.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/local/lib/libzstd.1.dylib' (no such file), '/opt/local/lib/libzstd.1.dylib' (no such file), '/usr/local/lib/libzstd.1.dylib' (no such file), '/usr/lib/libzstd.1.dylib' (no such file, not in dyld cache)
zsh: abort      ~/Downloads/llvm-17.0.6-arm64-apple-darwin23.3.0-Debug/bin/llvm-config

Workaround for me is:

zstd_dir="$(pkg-config --libs-only-L libzstd)"
export DYLD_LIBRARY_PATH="${zstd_dir#-L}:$DYLD_LIBRARY_PATH"

but you have to embed it in the script invoking llvm-config because of this security feature.

dabrahams commented 6 months ago

I think part of the deal is that homebrew installs its libraries in a nonstandard location on Apple Silicon (/opt/homebrew/lib)—but not on Intel. It's not in the default search path for libraries, so anything that is built without brew specifically in mind will fail to find dynamic libs installed by brew. It might not be the most principled approach, but I'm thinking of taking suggestion #1, if there's a way to get CMAKE to inject /opt/homebrew/lib at the end of all RUNPATHs it creates.

https://cmake.org/cmake/help/latest/prop_tgt/INSTALL_RPATH.html. When that's done we can undo https://github.com/hylo-lang/Swifty-LLVM/commit/2ac3ac714af