Skip to content

Commit b6e1942

Browse files
committed
test: mock-std test case for shared dependencies without --target req
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.
1 parent 3597f4c commit b6e1942

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
name = "dep_test"
3+
version = "0.1.0"
4+
edition = "2021"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/testsuite/mock-std/library/std/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2018"
66

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

1011
[features]
1112
feature1 = []

tests/testsuite/standard_lib.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,73 @@ fn basic() {
246246
p.cargo("test").build_std(&setup).target_host().run();
247247
}
248248

249+
#[cargo_test(build_std_mock)]
250+
fn shared_std_dependency_rebuild() {
251+
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
252+
let setup = setup();
253+
let p = project()
254+
.file(
255+
"Cargo.toml",
256+
format!(
257+
"
258+
[package]
259+
name = \"foo\"
260+
version = \"0.1.0\"
261+
edition = \"2021\"
262+
263+
[build-dependencies]
264+
dep_test = {{ path = \"{}/tests/testsuite/mock-std/dep_test\" }}
265+
",
266+
manifest_dir
267+
)
268+
.as_str(),
269+
)
270+
.file(
271+
"src/main.rs",
272+
r#"
273+
fn main() {
274+
println!("Hello, World!");
275+
}
276+
"#,
277+
)
278+
.file(
279+
"build.rs",
280+
r#"
281+
fn main() {
282+
println!("cargo::rerun-if-changed=build.rs");
283+
}
284+
"#,
285+
)
286+
.build();
287+
288+
p.cargo("build -v")
289+
.build_std(&setup)
290+
.target_host()
291+
.with_stderr_data(str![[r#"
292+
...
293+
[RUNNING] `[..] rustc --crate-name dep_test [..]`
294+
...
295+
[RUNNING] `[..] rustc --crate-name dep_test [..]`
296+
...
297+
"#]])
298+
.run();
299+
300+
// TODO: Because of the way in which std is resolved, it's mandatory that this is left commented
301+
// out as it will fail. This case should result in `dep_test` only being built once, however
302+
// it's still being built twice. This is a bug.
303+
//
304+
// p.cargo("build -v")
305+
// .build_std(&setup)
306+
// .with_stderr_does_not_contain(str![[r#"
307+
//...
308+
//[RUNNING] `[..] rustc --crate-name dep_test [..]`
309+
//...
310+
//[RUNNING] `[..] rustc --crate-name dep_test [..]`
311+
//...
312+
//"#]])
313+
// .run();
314+
}
315+
249316
#[cargo_test(build_std_mock)]
250317
fn simple_lib_std() {
251318
let setup = setup();

0 commit comments

Comments
 (0)