test: show runtime-dep and build-dep collides

See rust-lang/cargo 14253
This commit is contained in:
Weihang Lo 2024-08-20 17:49:12 -04:00
parent 9e152bba50
commit dba34d4552
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -1642,3 +1642,74 @@ fn target_applies_to_host_rustdocflags_works() {
)
.run();
}
#[cargo_test]
fn host_config_shared_build_dep() {
// rust-lang/cargo#14253
Package::new("cc", "1.0.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bootstrap"
edition = "2021"
[dependencies]
cc = "1.0.0"
[build-dependencies]
cc = "1.0.0"
[profile.dev]
debug = 0
"#,
)
.file("src/lib.rs", "")
.file("build.rs", "fn main() {}")
.file(
".cargo/config.toml",
"
target-applies-to-host=false
[host]
rustflags = ['--cfg', 'from_host']
[build]
rustflags = ['--cfg', 'from_target']
",
)
.build();
p.cargo("build -v")
.masquerade_as_nightly_cargo(&["target-applies-to-host"])
.arg("-Ztarget-applies-to-host")
.arg("-Zhost-config")
// Sometimes it compiles. Not deterministic...
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] cc v1.0.0 (registry `dummy-registry`)
[WARNING] output filename collision.
The lib target `cc` in package `cc v1.0.0` has the same output filename as the lib target `cc` in package `cc v1.0.0`.
Colliding filename is: [ROOT]/foo/target/debug/deps/libcc-[HASH].rlib
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
[WARNING] output filename collision.
The lib target `cc` in package `cc v1.0.0` has the same output filename as the lib target `cc` in package `cc v1.0.0`.
Colliding filename is: [ROOT]/foo/target/debug/deps/libcc-[HASH].rmeta
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
[COMPILING] cc v1.0.0
[RUNNING] `rustc --crate-name cc [..]--cfg from_host[..]`
[RUNNING] `rustc --crate-name cc [..]--cfg from_target[..]`
[ERROR] failed to build archive: No such file or directory
[ERROR] could not compile `cc` (lib) due to 1 previous error
"#]])
.run();
}