Skip to content

Commit

Permalink
Auto merge of #12283 - epage:build, r=weihanglo
Browse files Browse the repository at this point in the history
fix(embedded): Don't auto-discover build.rs files

With #12268, we moved the manifest root to be the scripts parent
directory, making it so auto-discovery might pick some things up.

We previously ensured `auto*` don't pick things up but missed `build.rs`
This is now addressed.
  • Loading branch information
bors committed Jun 17, 2023
2 parents 81a7392 + 3f93030 commit e518f7c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cargo/util/toml/embedded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ fn expand_manifest_(
));
toml::Value::String(DEFAULT_EDITION.to_string())
});
package
.entry("build".to_owned())
.or_insert_with(|| toml::Value::Boolean(false));
package
.entry("publish".to_owned())
.or_insert_with(|| toml::Value::Boolean(DEFAULT_PUBLISH));
Expand Down Expand Up @@ -491,6 +494,7 @@ autobenches = false
autobins = false
autoexamples = false
autotests = false
build = false
edition = "2021"
name = "test-"
publish = false
Expand Down Expand Up @@ -520,6 +524,7 @@ autobenches = false
autobins = false
autoexamples = false
autotests = false
build = false
edition = "2021"
name = "test-"
publish = false
Expand Down
29 changes: 29 additions & 0 deletions tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,35 @@ fn main() {
.run();
}

#[cargo_test]
fn test_no_build_rs() {
let script = r#"#!/usr/bin/env cargo
fn main() {
println!("Hello world!");
}"#;
let p = cargo_test_support::project()
.file("script.rs", script)
.file("build.rs", "broken")
.build();

p.cargo("-Zscript script.rs --help")
.masquerade_as_nightly_cargo(&["script"])
.with_stdout(
r#"Hello world!
"#,
)
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[..]/debug/script[EXE] --help`
",
)
.run();
}

#[cargo_test]
fn test_no_autobins() {
let script = r#"#!/usr/bin/env cargo
Expand Down

0 comments on commit e518f7c

Please sign in to comment.