Skip to content

Commit

Permalink
Auto merge of #10243 - hi-rustin:rustin-patch-collision, r=ehuss
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jan 18, 2022
2 parents 528ab12 + 3738002 commit 95bb3c9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/cargo/util/toml/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ fn clean_lib(
// A plugin requires exporting plugin_registrar so a crate cannot be
// both at once.
let crate_types = match (lib.crate_types(), lib.plugin, lib.proc_macro()) {
(Some(kinds), _, _)
if kinds.contains(&CrateType::Dylib.as_str().to_owned())
&& kinds.contains(&CrateType::Cdylib.as_str().to_owned()) =>
{
anyhow::bail!(format!(
"library `{}` cannot set the crate type of both `dylib` and `cdylib`",
lib.name()
));
}
(Some(kinds), _, _) if kinds.contains(&"proc-macro".to_string()) => {
if let Some(true) = lib.plugin {
// This is a warning to retain backwards compatibility.
Expand Down
33 changes: 33 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,39 @@ fn many_crate_types_correct() {
assert!(p.root().join("target/debug").join(&fname).is_file());
}

#[cargo_test]
fn set_both_dylib_and_cdylib_crate_types() {
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.5.0"
authors = ["[email protected]"]
[lib]
name = "foo"
crate_type = ["cdylib", "dylib"]
"#,
)
.file("src/lib.rs", "pub fn foo() {}")
.build();
p.cargo("build")
.with_status(101)
.with_stderr(
"\
error: failed to parse manifest at `[..]`
Caused by:
library `foo` cannot set the crate type of both `dylib` and `cdylib`
",
)
.run();
}

#[cargo_test]
fn self_dependency() {
let p = project()
Expand Down

0 comments on commit 95bb3c9

Please sign in to comment.