Cannot build for musl target
Building llvm-sys for the musl target (on Linux) fails with the following error:
❯ cargo build --target x86_64-unknown-linux-musl
Compiling llvm-sys v160.0.2 (/home/vadorovsky/repos/llvm-sys.rs)
error: could not find native static library `rt`, perhaps an -L flag is missing?
error: could not compile `llvm-sys` due to previous error
That's because for musl targets, we also try to link libraries mentioned by llvm-config --system-libs
dynamically. However, Rust doesn't look up for static libraries in /usr/lib or /usr/lib64 by default. It has to be pointed to all directories with static libraries with cargo:rustc-link-search
, even the system-wide ones.
So the proper fix would be specify cargo:rustc-link-search=/usr/lib64
or cargo:rustc-link-search=/usr/lib
when linking system libs statically.