Skip to content

Commit 09cfc13

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 b32d24a commit 09cfc13

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,70 @@ 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+
[package]
258+
name = \"foo\"
259+
version = \"0.1.0\"
260+
edition = \"2021\"
261+
262+
[build-dependencies]
263+
dep_test = {{ path = \"{}/tests/testsuite/mock-std/dep_test\" }}
264+
", manifest_dir).as_str()
265+
)
266+
.file(
267+
"src/main.rs",
268+
r#"
269+
fn main() {
270+
println!("Hello, World!");
271+
}
272+
"#,
273+
)
274+
.file(
275+
"build.rs",
276+
r#"
277+
fn main() {
278+
println!("cargo::rerun-if-changed=build.rs");
279+
}
280+
"#,
281+
)
282+
.build();
283+
284+
p.cargo("build -v")
285+
.build_std(&setup)
286+
.target_host()
287+
.with_stderr_data(str![[r#"
288+
...
289+
[RUNNING] `[..] rustc --crate-name dep_test [..]`
290+
...
291+
[RUNNING] `[..] rustc --crate-name dep_test [..]`
292+
...
293+
"#]])
294+
.run();
295+
296+
// TODO: Because of the way in which std is resolved, it's mandatory that this is left commented
297+
// out as it will fail. This case should result in `dep_test` only being built once, however
298+
// it's still being built twice. This is a bug.
299+
//
300+
// p.cargo("build -v")
301+
// .build_std(&setup)
302+
// .with_stderr_does_not_contain(str![[r#"
303+
//...
304+
//[RUNNING] `[..] rustc --crate-name dep_test [..]`
305+
//...
306+
//[RUNNING] `[..] rustc --crate-name dep_test [..]`
307+
//...
308+
//"#]])
309+
// .run();
310+
311+
}
312+
249313
#[cargo_test(build_std_mock)]
250314
fn simple_lib_std() {
251315
let setup = setup();

0 commit comments

Comments
 (0)