Skip to content

Commit e518f7c

Browse files
committed
Auto merge of #12283 - epage:build, r=weihanglo
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.
2 parents 81a7392 + 3f93030 commit e518f7c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/cargo/util/toml/embedded.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ fn expand_manifest_(
8989
));
9090
toml::Value::String(DEFAULT_EDITION.to_string())
9191
});
92+
package
93+
.entry("build".to_owned())
94+
.or_insert_with(|| toml::Value::Boolean(false));
9295
package
9396
.entry("publish".to_owned())
9497
.or_insert_with(|| toml::Value::Boolean(DEFAULT_PUBLISH));
@@ -491,6 +494,7 @@ autobenches = false
491494
autobins = false
492495
autoexamples = false
493496
autotests = false
497+
build = false
494498
edition = "2021"
495499
name = "test-"
496500
publish = false
@@ -520,6 +524,7 @@ autobenches = false
520524
autobins = false
521525
autoexamples = false
522526
autotests = false
527+
build = false
523528
edition = "2021"
524529
name = "test-"
525530
publish = false

tests/testsuite/script.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,35 @@ fn main() {
509509
.run();
510510
}
511511

512+
#[cargo_test]
513+
fn test_no_build_rs() {
514+
let script = r#"#!/usr/bin/env cargo
515+
516+
fn main() {
517+
println!("Hello world!");
518+
}"#;
519+
let p = cargo_test_support::project()
520+
.file("script.rs", script)
521+
.file("build.rs", "broken")
522+
.build();
523+
524+
p.cargo("-Zscript script.rs --help")
525+
.masquerade_as_nightly_cargo(&["script"])
526+
.with_stdout(
527+
r#"Hello world!
528+
"#,
529+
)
530+
.with_stderr(
531+
"\
532+
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
533+
[COMPILING] script v0.0.0 ([ROOT]/foo)
534+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
535+
[RUNNING] `[..]/debug/script[EXE] --help`
536+
",
537+
)
538+
.run();
539+
}
540+
512541
#[cargo_test]
513542
fn test_no_autobins() {
514543
let script = r#"#!/usr/bin/env cargo

0 commit comments

Comments
 (0)