Skip to content

Commit c9a8199

Browse files
committed
Auto merge of #10372 - weihanglo:issue-9325, r=ehuss
Test: ensure dep-infos do not collide when cdylib and bin coexist
2 parents 263cc2b + e214248 commit c9a8199

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/testsuite/build.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4541,6 +4541,54 @@ fn cdylib_final_outputs() {
45414541
}
45424542
}
45434543

4544+
#[cargo_test]
4545+
// NOTE: Windows MSVC and wasm32-unknown-emscripten do not use metadata. Skip them.
4546+
// See <https://github.com/rust-lang/cargo/issues/9325#issuecomment-1030662699>
4547+
#[cfg(not(all(target_os = "windows", target_env = "msvc")))]
4548+
fn no_dep_info_collision_when_cdylib_and_bin_coexist() {
4549+
let p = project()
4550+
.file(
4551+
"Cargo.toml",
4552+
r#"
4553+
[package]
4554+
name = "foo"
4555+
version = "1.0.0"
4556+
4557+
[lib]
4558+
crate-type = ["cdylib"]
4559+
"#,
4560+
)
4561+
.file("src/main.rs", "fn main() {}")
4562+
.file("src/lib.rs", "")
4563+
.build();
4564+
4565+
p.cargo("build -v")
4566+
.with_stderr_unordered(
4567+
"\
4568+
[COMPILING] foo v1.0.0 ([CWD])
4569+
[RUNNING] `rustc [..] --crate-type bin [..] -C metadata=[..]`
4570+
[RUNNING] `rustc [..] --crate-type cdylib [..] -C metadata=[..]`
4571+
[FINISHED] [..]
4572+
",
4573+
)
4574+
.run();
4575+
4576+
let deps_dir = p.target_debug_dir().join("deps");
4577+
assert!(deps_dir.join("foo.d").exists());
4578+
let dep_info_count = deps_dir
4579+
.read_dir()
4580+
.unwrap()
4581+
.filter(|e| {
4582+
let filename = e.as_ref().unwrap().file_name();
4583+
let filename = filename.to_str().unwrap();
4584+
filename.starts_with("foo") && filename.ends_with(".d")
4585+
})
4586+
.count();
4587+
// cdylib -> foo.d
4588+
// bin -> foo-<meta>.d
4589+
assert_eq!(dep_info_count, 2);
4590+
}
4591+
45444592
#[cargo_test]
45454593
fn deterministic_cfg_flags() {
45464594
// This bug is non-deterministic.

0 commit comments

Comments
 (0)