Skip to content

Commit

Permalink
test: mock-std test case for shared dependencies without --target req
Browse files Browse the repository at this point in the history
Add a test case which ensures that -Zbuild-std without --target
correctly handles building a crate that has a shared dependency between
it's own build script, and std.
  • Loading branch information
harmou01 committed Sep 25, 2024
1 parent 3597f4c commit b6e1942
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/testsuite/mock-std/dep_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "dep_test"
version = "0.1.0"
edition = "2021"
1 change: 1 addition & 0 deletions tests/testsuite/mock-std/dep_test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions tests/testsuite/mock-std/library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2018"

[dependencies]
registry-dep-using-alloc = { version = "*", features = ['mockbuild'] }
dep_test = { path = "../../dep_test" }

[features]
feature1 = []
67 changes: 67 additions & 0 deletions tests/testsuite/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,73 @@ fn basic() {
p.cargo("test").build_std(&setup).target_host().run();
}

#[cargo_test(build_std_mock)]
fn shared_std_dependency_rebuild() {
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let setup = setup();
let p = project()
.file(
"Cargo.toml",
format!(
"
[package]
name = \"foo\"
version = \"0.1.0\"
edition = \"2021\"
[build-dependencies]
dep_test = {{ path = \"{}/tests/testsuite/mock-std/dep_test\" }}
",
manifest_dir
)
.as_str(),
)
.file(
"src/main.rs",
r#"
fn main() {
println!("Hello, World!");
}
"#,
)
.file(
"build.rs",
r#"
fn main() {
println!("cargo::rerun-if-changed=build.rs");
}
"#,
)
.build();

p.cargo("build -v")
.build_std(&setup)
.target_host()
.with_stderr_data(str![[r#"
...
[RUNNING] `[..] rustc --crate-name dep_test [..]`
...
[RUNNING] `[..] rustc --crate-name dep_test [..]`
...
"#]])
.run();

// TODO: Because of the way in which std is resolved, it's mandatory that this is left commented
// out as it will fail. This case should result in `dep_test` only being built once, however
// it's still being built twice. This is a bug.
//
// p.cargo("build -v")
// .build_std(&setup)
// .with_stderr_does_not_contain(str![[r#"
//...
//[RUNNING] `[..] rustc --crate-name dep_test [..]`
//...
//[RUNNING] `[..] rustc --crate-name dep_test [..]`
//...
//"#]])
// .run();
}

#[cargo_test(build_std_mock)]
fn simple_lib_std() {
let setup = setup();
Expand Down

0 comments on commit b6e1942

Please sign in to comment.