link-search-path doesn't have a way to specify priority / doesn't auto deprioritize OS link paths #137404
Labels
T-cargo
Relevant to the cargo team, which will review and decide on the PR/issue.
I modified the llama.cpp repo that llama-cpp-2 has as a submodule to expose a new symbol & then added a method to call that new symbol in llama-cpp-2 via a Rust pub API. I then called the new Rust pub API in my code and added cpal as a dependency and the path to my local llama-cpp-2 as a dependency with the cuda feature on (cuda doesn't matter but right now that forces llama.cpp to be built as a shared library). I then tried to build my crate. I also installed libllama.so in my OS.
I expected to see this happen: Crate builds
Instead, this happened: Crate fails to link saying the new symbol I added to llama.cpp is missing.
The root cause is that cpal depends indirectly on alsa-sys which uses pkg-config which adds the location of the found library to the search path. This happens before llama-cpp-2 runs and thus the linker things it should use the OS dynamic library that doesn't have the symbol & fails. While there's no way to specify priority and while valuable, that feels like it would be a much larger discussion.
I was wondering if a more targeted fix would be to ensure that all paths under OUT_DIR are moved to the front (in an order-preserving way) while the remaining directories are moved later (in an order-preserving way). That way the linker ALWAYS looks for paths within OUT_DIR before looking in other locations.
I'm not sure if this bug is in rust itself or in Cargo. Now that I think about it I'll cross-file into Cargo and link these two bugs together (15220).
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: