mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Auto merge of #5204 - lukaslueg:issue5199, r=alexcrichton
Do not allow crate-type or proc-macro for [[bin]]-targets Fixes #5199 This simply disallows `proc-macro` and `crate-type` to be set to anything for binary targets. Is this the best way to go or does a warning about the unused setting suffice?
This commit is contained in:
commit
4dde7264b5
@ -44,6 +44,7 @@ pub fn targets(
|
||||
package_root,
|
||||
package_name,
|
||||
warnings,
|
||||
errors,
|
||||
has_lib,
|
||||
)?);
|
||||
|
||||
@ -164,6 +165,7 @@ fn clean_bins(
|
||||
package_root: &Path,
|
||||
package_name: &str,
|
||||
warnings: &mut Vec<String>,
|
||||
errors: &mut Vec<String>,
|
||||
has_lib: bool,
|
||||
) -> CargoResult<Vec<Target>> {
|
||||
let inferred = inferred_bins(package_root, package_name);
|
||||
@ -183,6 +185,26 @@ fn clean_bins(
|
||||
validate_has_name(bin, "binary", "bin")?;
|
||||
|
||||
let name = bin.name();
|
||||
|
||||
if let Some(crate_types) = bin.crate_types() {
|
||||
if !crate_types.is_empty() {
|
||||
errors.push(format!(
|
||||
"the target `{}` is a binary and can't have any \
|
||||
crate-types set (currently \"{}\")",
|
||||
name,
|
||||
crate_types.join(", ")
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if bin.proc_macro() == Some(true) {
|
||||
errors.push(format!(
|
||||
"the target `{}` is a binary and can't have `proc-macro` \
|
||||
set `true`",
|
||||
name
|
||||
));
|
||||
}
|
||||
|
||||
if is_bad_artifact_name(&name) {
|
||||
bail!("the binary target name `{}` is forbidden", name)
|
||||
}
|
||||
|
@ -449,6 +449,71 @@ Caused by:
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cargo_compile_with_bin_and_crate_type() {
|
||||
let p = project("foo")
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
authors = []
|
||||
version = "0.0.0"
|
||||
|
||||
[[bin]]
|
||||
name = "the_foo_bin"
|
||||
path = "src/foo.rs"
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
"#,
|
||||
)
|
||||
.file("src/foo.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
assert_that(
|
||||
p.cargo("build"),
|
||||
execs().with_status(101).with_stderr(
|
||||
"\
|
||||
[ERROR] failed to parse manifest at `[..]`
|
||||
|
||||
Caused by:
|
||||
the target `the_foo_bin` is a binary and can't have any crate-types set \
|
||||
(currently \"cdylib, rlib\")",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cargo_compile_with_bin_and_proc() {
|
||||
let p = project("foo")
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
authors = []
|
||||
version = "0.0.0"
|
||||
|
||||
[[bin]]
|
||||
name = "the_foo_bin"
|
||||
path = "src/foo.rs"
|
||||
proc-macro = true
|
||||
"#,
|
||||
)
|
||||
.file("src/foo.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
assert_that(
|
||||
p.cargo("build"),
|
||||
execs().with_status(101).with_stderr(
|
||||
"\
|
||||
[ERROR] failed to parse manifest at `[..]`
|
||||
|
||||
Caused by:
|
||||
the target `the_foo_bin` is a binary and can't have `proc-macro` set `true`",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cargo_compile_with_invalid_lib_target_name() {
|
||||
let p = project("foo")
|
||||
|
Loading…
x
Reference in New Issue
Block a user