| Issue |
240026
|
| Summary |
[Packaging][macOS] Release archives embed runner path '/opt/homebrew/lib/libzstd.a' in 'llvm-config --system-libs'
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
zhibisora
|
### Description
In the official macOS release archives (e.g. `LLVM-23.1.5-macOS-ARM64.tar.xz` from `llvmorg-23.1.5`), running `bin/llvm-config --link-static --system-libs` outputs a hardcoded absolute path from the GitHub Actions build runner:
```console
$ ./bin/llvm-config --link-static --system-libs
-lm -lz /opt/homebrew/lib/libzstd.a -lxml2
```
However, `libzstd.a` is not bundled inside the release archive, and on macOS machines that do not use Homebrew (or install `zstd` under a different prefix such as `~/.local/lib` or `/usr/local/lib`), linking against LLVM's static archives via `llvm-config` fails immediately:
```console
$ clang test.c $(./bin/llvm-config --cflags --ldflags --libs core --system-libs)
clang: error: no such file or directory: '/opt/homebrew/lib/libzstd.a'
```
Downstream build scripts that parse `llvm-config --system-libs` (such as Rust's `llvm-sys` crate) also panic when `/opt/homebrew/lib/libzstd.a` does not exist on disk:
```text
Unable to parse result of llvm-config --system-libs: /opt/homebrew/lib/libzstd.a
```
### Root Cause
1. `clang/cmake/caches/Release.cmake` sets:
```cmake
set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL)
```
(which nicely avoids a runtime dynamic library dependency on `/opt/homebrew/opt/zstd/lib/libzstd.1.dylib` for the prebuilt executables like `clang` and `lld`).
2. However, in `llvm/lib/Support/CMakeLists.txt`:
```cmake
if (zstd_target STREQUAL zstd::libzstd_shared)
get_library_name(${zstd_library} zstd_library)
set(llvm_system_libs ${llvm_system_libs} "${zstd_library}")
else()
set(llvm_system_libs ${llvm_system_libs} "${zstd_STATIC_LIBRARY}")
endif()
```
When `zstd_target` is `zstd::libzstd_static`, `LLVM_SYSTEM_LIBS` records the raw build-host path `${zstd_STATIC_LIBRARY}` (`/opt/homebrew/lib/libzstd.a` on the macOS runner) instead of a portable library name or a bundled archive inside the release prefix.
### Steps to Reproduce
1. Download `LLVM-23.1.5-macOS-ARM64.tar.xz` from the `llvmorg-23.1.5` release on an Apple Silicon Mac without Homebrew `/opt/homebrew/lib/libzstd.a`.
2. Run:
```sh
tar -xf LLVM-23.1.5-macOS-ARM64.tar.xz
./LLVM-23.1.5-macOS-ARM64/bin/llvm-config --link-static --system-libs
```
3. Observe `-lm -lz /opt/homebrew/lib/libzstd.a -lxml2`.
### Expected Behavior
Official standalone release archives should not embed build-machine `/opt/homebrew/...` paths in `llvm-config --system-libs` (either by emitting `-lzstd` via `get_library_name`, bundling `libzstd.a` in the release archive's `lib/` directory, or building zstd in-tree as discussed in #106010).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs