Skip to content

Commit e1348cf

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

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,
@@ -56,8 +57,11 @@ fn expand_manifest_(
5657
.or_insert_with(|| toml::Table::new().into())
5758
.as_table_mut()
5859
.ok_or_else(|| anyhow::format_err!("`package` must be a table"))?;
59-
for key in ["workspace", "build", "links"] {
60-
if package.contains_key(key) {
60+
for key in ["workspace", "build", "links"]
61+
.iter()
62+
.chain(AUTO_FIELDS.iter())
63+
{
64+
if package.contains_key(*key) {
6165
anyhow::bail!("`package.{key}` is not allowed in embedded manifests")
6266
}
6367
}
@@ -84,6 +88,11 @@ fn expand_manifest_(
8488
package
8589
.entry("publish".to_owned())
8690
.or_insert_with(|| toml::Value::Boolean(DEFAULT_PUBLISH));
91+
for field in AUTO_FIELDS {
92+
package
93+
.entry(field.to_owned())
94+
.or_insert_with(|| toml::Value::Boolean(false));
95+
}
8796

8897
let mut bin = toml::Table::new();
8998
bin.insert("name".to_owned(), toml::Value::String(bin_name));
@@ -355,6 +364,10 @@ name = "test"
355364
path = "/home/me/test.rs"
356365
357366
[package]
367+
autobenches = false
368+
autobins = false
369+
autoexamples = false
370+
autotests = false
358371
edition = "2021"
359372
name = "test"
360373
publish = false
@@ -380,6 +393,10 @@ path = "/home/me/test.rs"
380393
time = "0.1.25"
381394
382395
[package]
396+
autobenches = false
397+
autobins = false
398+
autoexamples = false
399+
autotests = false
383400
edition = "2021"
384401
name = "test"
385402
publish = false

tests/testsuite/script.rs

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

524524
p.cargo("-Zscript script.rs --help")
525525
.masquerade_as_nightly_cargo(&["script"])
526-
.with_status(101)
526+
.with_stdout(
527+
r#"Hello world!
528+
"#,
529+
)
527530
.with_stderr(
528531
"\
529532
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
530-
[ERROR] `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key.
531-
available binaries: not-script, script
533+
[COMPILING] script v0.0.0 ([ROOT]/foo)
534+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
535+
[RUNNING] `[..]/debug/script[EXE] --help`
532536
",
533537
)
534538
.run();

0 commit comments

Comments
 (0)