Skip to content

Commit 9c3ba86

Browse files
committed
Add test verifying behavior of links_overrides with target-applies-to-host and an implicit target
1 parent 6d68563 commit 9c3ba86

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

tests/testsuite/build_script.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5777,3 +5777,78 @@ hello
57775777
"#]])
57785778
.run();
57795779
}
5780+
5781+
#[cargo_test]
5782+
fn links_overrides_with_target_applies_to_host() {
5783+
let p = project()
5784+
// mylib-c is just a shared library to link against
5785+
.file(
5786+
"mylib-c/Cargo.toml",
5787+
r#"
5788+
[package]
5789+
name = "mylib"
5790+
edition = "2021"
5791+
version = "0.0.1"
5792+
authors = []
5793+
5794+
[lib]
5795+
crate-type = ["cdylib"]
5796+
"#,
5797+
)
5798+
.file(
5799+
"mylib-c/src/lib.rs",
5800+
r#"
5801+
#[no_mangle]
5802+
pub extern "C" fn foo() { println!("Hello, World!") }
5803+
"#,
5804+
)
5805+
.file(
5806+
"Cargo.toml",
5807+
r#"
5808+
[package]
5809+
name = "mylib-sys"
5810+
edition = "2021"
5811+
version = "0.0.1"
5812+
authors = []
5813+
links = "mylib"
5814+
"#,
5815+
)
5816+
.file(
5817+
// Use a binary that uses a symbol in mylib to force the linker to actually link it.
5818+
"src/main.rs",
5819+
r#"
5820+
extern "C" { fn foo(); }
5821+
pub fn main() { unsafe{ foo() } }
5822+
"#,
5823+
)
5824+
.file("build.rs", r#"fn main() { panic!("build.rs called") }"#)
5825+
.build();
5826+
5827+
p.cargo("build --manifest-path mylib-c/Cargo.toml")
5828+
.with_status(0)
5829+
.run();
5830+
5831+
p.cargo("build")
5832+
.masquerade_as_nightly_cargo(&["target-applies-to-host"])
5833+
.args(&[
5834+
"-Ztarget-applies-to-host",
5835+
"--config",
5836+
"target-applies-to-host=false",
5837+
])
5838+
.args(&[
5839+
"--config",
5840+
&format!(r#"target.{}.mylib.rustc-link-lib=["mylib"]"#, rustc_host()),
5841+
"--config",
5842+
&format!(
5843+
r#"target.{}.mylib.rustc-link-search=["mylib-c/target/debug"]"#,
5844+
rustc_host()
5845+
),
5846+
])
5847+
.with_status(101)
5848+
.with_stderr_data(
5849+
"thread 'main' panicked at src/cargo/core/compiler/custom_build.rs:256:10:
5850+
running a script not depending on an actual script
5851+
...",
5852+
)
5853+
.run();
5854+
}

0 commit comments

Comments
 (0)