Skip to content

Commit 95bb3c9

Browse files
committed
Auto merge of #10243 - hi-rustin:rustin-patch-collision, r=ehuss
Error when setting crate type of both dylib and cdylib in library close #10231 Error when setting crate type of both dylib and cdylib in library. Cargo can't support that at this time, since they both output the same filename.
2 parents 528ab12 + 3738002 commit 95bb3c9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/cargo/util/toml/targets.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ fn clean_lib(
215215
// A plugin requires exporting plugin_registrar so a crate cannot be
216216
// both at once.
217217
let crate_types = match (lib.crate_types(), lib.plugin, lib.proc_macro()) {
218+
(Some(kinds), _, _)
219+
if kinds.contains(&CrateType::Dylib.as_str().to_owned())
220+
&& kinds.contains(&CrateType::Cdylib.as_str().to_owned()) =>
221+
{
222+
anyhow::bail!(format!(
223+
"library `{}` cannot set the crate type of both `dylib` and `cdylib`",
224+
lib.name()
225+
));
226+
}
218227
(Some(kinds), _, _) if kinds.contains(&"proc-macro".to_string()) => {
219228
if let Some(true) = lib.plugin {
220229
// This is a warning to retain backwards compatibility.

tests/testsuite/build.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,39 @@ fn many_crate_types_correct() {
16331633
assert!(p.root().join("target/debug").join(&fname).is_file());
16341634
}
16351635

1636+
#[cargo_test]
1637+
fn set_both_dylib_and_cdylib_crate_types() {
1638+
let p = project()
1639+
.file(
1640+
"Cargo.toml",
1641+
r#"
1642+
[project]
1643+
1644+
name = "foo"
1645+
version = "0.5.0"
1646+
authors = ["[email protected]"]
1647+
1648+
[lib]
1649+
1650+
name = "foo"
1651+
crate_type = ["cdylib", "dylib"]
1652+
"#,
1653+
)
1654+
.file("src/lib.rs", "pub fn foo() {}")
1655+
.build();
1656+
p.cargo("build")
1657+
.with_status(101)
1658+
.with_stderr(
1659+
"\
1660+
error: failed to parse manifest at `[..]`
1661+
1662+
Caused by:
1663+
library `foo` cannot set the crate type of both `dylib` and `cdylib`
1664+
",
1665+
)
1666+
.run();
1667+
}
1668+
16361669
#[cargo_test]
16371670
fn self_dependency() {
16381671
let p = project()

0 commit comments

Comments
 (0)