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

Make sure search paths inside OUT_DIR precede external paths #15221

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6087,3 +6087,40 @@ fn directory_with_leading_underscore() {
.with_status(0)
.run();
}

#[cargo_test]
fn linker_search_path_preference() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice. Thank you!

Could we have one more test that: Has some dependencies, and those dependencies also emit cargo::rustc-link-search, and we ensure that the order from the dependencies is maintained?

// This isn't strictly the exact scenario that causes the issue, but it's the shortest demonstration
// of the issue.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2024"
build = "build.rs"
"#,
)
.file(
"build.rs",
r#"
fn main() {
let out_dir = std::env::var("OUT_DIR").unwrap();
println!("cargo::rustc-link-search=/usr/lib");
println!("cargo::rustc-link-search={}/libs2", out_dir);
println!("cargo::rustc-link-search=/lib");
println!("cargo::rustc-link-search={}/libs1", out_dir);
}
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("build -v").with_stderr_data(str![[r#"
...
[RUNNING] `rustc --crate-name foo [..] -L /usr/lib -L [ROOT]/foo/target/debug/build/foo-[HASH]/out/libs2 -L /lib -L [ROOT]/foo/target/debug/build/foo-[HASH]/out/libs1`
...
"#]]).run();
}