Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(embedded): Ensure we don't auto-discover any targets
  • Loading branch information
epage committed Jun 17, 2023
commit 5ed07925cc24f1c0fa289d0f65f38ed47435391d
21 changes: 19 additions & 2 deletions src/cargo/util/toml/embedded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const DEFAULT_EDITION: crate::core::features::Edition =
crate::core::features::Edition::LATEST_STABLE;
const DEFAULT_VERSION: &str = "0.0.0";
const DEFAULT_PUBLISH: bool = false;
const AUTO_FIELDS: &[&str] = &["autobins", "autoexamples", "autotests", "autobenches"];

pub fn expand_manifest(
content: &str,
Expand Down Expand Up @@ -57,8 +58,11 @@ fn expand_manifest_(
.or_insert_with(|| toml::Table::new().into())
.as_table_mut()
.ok_or_else(|| anyhow::format_err!("`package` must be a table"))?;
for key in ["workspace", "build", "links"] {
if package.contains_key(key) {
for key in ["workspace", "build", "links"]
.iter()
.chain(AUTO_FIELDS.iter())
{
if package.contains_key(*key) {
anyhow::bail!("`package.{key}` is not allowed in embedded manifests")
}
}
Expand Down Expand Up @@ -88,6 +92,11 @@ fn expand_manifest_(
package
.entry("publish".to_owned())
.or_insert_with(|| toml::Value::Boolean(DEFAULT_PUBLISH));
for field in AUTO_FIELDS {
package
.entry(field.to_owned())
.or_insert_with(|| toml::Value::Boolean(false));
}

let mut bin = toml::Table::new();
bin.insert("name".to_owned(), toml::Value::String(bin_name));
Expand Down Expand Up @@ -363,6 +372,10 @@ name = "test-"
path = "test.rs"

[package]
autobenches = false
autobins = false
autoexamples = false
autotests = false
edition = "2021"
name = "test-"
publish = false
Expand All @@ -388,6 +401,10 @@ path = "test.rs"
time = "0.1.25"

[package]
autobenches = false
autobins = false
autoexamples = false
autotests = false
edition = "2021"
name = "test-"
publish = false
Expand Down
10 changes: 7 additions & 3 deletions tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,16 @@ fn main() {

p.cargo("-Zscript script.rs --help")
.masquerade_as_nightly_cargo(&["script"])
.with_status(101)
.with_stdout(
r#"Hello world!
"#,
)
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[ERROR] `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key.
available binaries: not-script, script
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[..]/debug/script[EXE] --help`
",
)
.run();
Expand Down