Skip to content

Commit 8cfdba9

Browse files
committed
Add test case for current behavior.
1 parent c1f7bb9 commit 8cfdba9

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

tests/testsuite/build_script.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6087,3 +6087,91 @@ fn directory_with_leading_underscore() {
60876087
.with_status(0)
60886088
.run();
60896089
}
6090+
6091+
#[cargo_test]
6092+
fn linker_search_path_preference() {
6093+
// This isn't strictly the exact scenario that causes the issue, but it's the shortest demonstration
6094+
// of the issue.
6095+
let p = project()
6096+
.file(
6097+
"Cargo.toml",
6098+
r#"
6099+
[package]
6100+
name = "foo"
6101+
version = "0.1.0"
6102+
edition = "2024"
6103+
build = "build.rs"
6104+
6105+
[dependencies]
6106+
a = { path = "a" }
6107+
b = { path = "b" }
6108+
"#,
6109+
)
6110+
.file(
6111+
"build.rs",
6112+
r#"
6113+
fn main() {
6114+
let out_dir = std::env::var("OUT_DIR").unwrap();
6115+
println!("cargo::rustc-link-search=/usr/lib");
6116+
println!("cargo::rustc-link-search={}/libs2", out_dir);
6117+
println!("cargo::rustc-link-search=/lib");
6118+
println!("cargo::rustc-link-search={}/libs1", out_dir);
6119+
}
6120+
"#,
6121+
)
6122+
.file("src/main.rs", "fn main() {}")
6123+
.file(
6124+
"a/Cargo.toml",
6125+
r#"
6126+
[package]
6127+
name = "a"
6128+
version = "0.1.0"
6129+
edition = "2024"
6130+
build = "build.rs"
6131+
"#,
6132+
)
6133+
.file("a/src/lib.rs", "")
6134+
.file(
6135+
"a/build.rs",
6136+
r#"
6137+
fn main() {
6138+
let out_dir = std::env::var("OUT_DIR").unwrap();
6139+
println!("cargo::rustc-link-search=/usr/lib3");
6140+
println!("cargo::rustc-link-search={}/libsA.2", out_dir);
6141+
println!("cargo::rustc-link-search=/lib3");
6142+
println!("cargo::rustc-link-search={}/libsA.1", out_dir);
6143+
}
6144+
"#,
6145+
)
6146+
.file(
6147+
"b/Cargo.toml",
6148+
r#"
6149+
[package]
6150+
name = "b"
6151+
version = "0.1.0"
6152+
edition = "2024"
6153+
build = "build.rs"
6154+
"#,
6155+
)
6156+
.file("b/src/lib.rs", "")
6157+
.file(
6158+
"b/build.rs",
6159+
r#"
6160+
fn main() {
6161+
let out_dir = std::env::var("OUT_DIR").unwrap();
6162+
println!("cargo::rustc-link-search=/usr/lib2");
6163+
println!("cargo::rustc-link-search={}/libsB.1", out_dir);
6164+
println!("cargo::rustc-link-search=/lib2");
6165+
println!("cargo::rustc-link-search={}/libsB.2", out_dir);
6166+
}
6167+
"#,
6168+
)
6169+
.build();
6170+
6171+
// -L /usr/lib2 -L [ROOT]/foo/target/debug/build/a-[HASH]/out/libsB.1 -L /lib2 -L [ROOT]/foo/target/debug/build/a-[HASH]/out/libsB.2
6172+
p.cargo("build -v").with_stderr_data(str![[r#"
6173+
...
6174+
[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 -L /usr/lib3 -L [ROOT]/foo/target/debug/build/a-[HASH]/out/libsA.2 -L /lib3 -L [ROOT]/foo/target/debug/build/a-[HASH]/out/libsA.1 -L /usr/lib2 -L [ROOT]/foo/target/debug/build/b-[HASH]/out/libsB.1 -L /lib2 -L [ROOT]/foo/target/debug/build/b-[HASH]/out/libsB.2`
6175+
...
6176+
"#]]).run();
6177+
}

0 commit comments

Comments
 (0)