Skip to content

Commit e56b873

Browse files
committed
fix(embedded): Ensure we don't auto-discover any targets
1 parent ab590b8 commit e56b873

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/cargo/util/toml/embedded.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const DEFAULT_EDITION: crate::core::features::Edition =
77
crate::core::features::Edition::LATEST_STABLE;
88
const DEFAULT_VERSION: &str = "0.0.0";
99
const DEFAULT_PUBLISH: bool = false;
10+
const AUTO_FIELDS: &[&str] = &["autobins", "autoexamples", "autotests", "autobenches"];
1011

1112
pub fn expand_manifest(
1213
content: &str,
@@ -57,8 +58,11 @@ fn expand_manifest_(
5758
.or_insert_with(|| toml::Table::new().into())
5859
.as_table_mut()
5960
.ok_or_else(|| anyhow::format_err!("`package` must be a table"))?;
60-
for key in ["workspace", "build", "links"] {
61-
if package.contains_key(key) {
61+
for key in ["workspace", "build", "links"]
62+
.iter()
63+
.chain(AUTO_FIELDS.iter())
64+
{
65+
if package.contains_key(*key) {
6266
anyhow::bail!("`package.{key}` is not allowed in embedded manifests")
6367
}
6468
}
@@ -86,6 +90,11 @@ fn expand_manifest_(
8690
package
8791
.entry("publish".to_owned())
8892
.or_insert_with(|| toml::Value::Boolean(DEFAULT_PUBLISH));
93+
for field in AUTO_FIELDS {
94+
package
95+
.entry(field.to_owned())
96+
.or_insert_with(|| toml::Value::Boolean(false));
97+
}
8998

9099
let mut bin = toml::Table::new();
91100
bin.insert("name".to_owned(), toml::Value::String(bin_name));
@@ -361,6 +370,10 @@ name = "test_a472c7a31645d310613df407eab80844346938a3b8fe4f392cae059cb181aa85"
361370
path = "/home/me/test.rs"
362371
363372
[package]
373+
autobenches = false
374+
autobins = false
375+
autoexamples = false
376+
autotests = false
364377
edition = "2021"
365378
name = "test"
366379
publish = false
@@ -386,6 +399,10 @@ path = "/home/me/test.rs"
386399
time = "0.1.25"
387400
388401
[package]
402+
autobenches = false
403+
autobins = false
404+
autoexamples = false
405+
autotests = false
389406
edition = "2021"
390407
name = "test"
391408
publish = false

tests/testsuite/script.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,16 @@ fn main() {
529529

530530
p.cargo("-Zscript script.rs --help")
531531
.masquerade_as_nightly_cargo(&["script"])
532-
.with_status(101)
532+
.with_stdout(
533+
r#"Hello world!
534+
"#,
535+
)
533536
.with_stderr(
534537
"\
535538
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
536-
[ERROR] `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key.
537-
available binaries: script, script_[..]
539+
[COMPILING] script v0.0.0 ([ROOT]/foo)
540+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
541+
[RUNNING] `target/debug/script_[..] --help`
538542
",
539543
)
540544
.run();

0 commit comments

Comments
 (0)