Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link-search-path doesn't have a way to specify priority / doesn't auto deprioritize OS link paths #137404

Closed
vlovich opened this issue Feb 21, 2025 · 1 comment
Labels
T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.

Comments

@vlovich
Copy link

vlovich commented Feb 21, 2025

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:

rustc --version --verbose
rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: x86_64-unknown-linux-gnu
release: 1.84.0
LLVM version: 19.1.5
@vlovich
Copy link
Author

vlovich commented Feb 22, 2025

Closing because this code does live in Cargo.

@vlovich vlovich closed this as completed Feb 22, 2025
@saethlin saethlin added T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants