Skip to content

Commit d432dec

Browse files
committedAug 7, 2023
Auto merge of #12332 - hi-rustin:rustin-patch-syntax, r=arlosi
Bail out an error when using cargo:: in custom build script
2 parents abc1159 + 4bdeb53 commit d432dec

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
 

‎src/cargo/core/compiler/custom_build.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,17 @@ impl BuildOutput {
690690
continue;
691691
}
692692
let data = match iter.next() {
693-
Some(val) => val,
693+
Some(val) => {
694+
if val.starts_with(":") {
695+
// Line started with `cargo::`.
696+
bail!("unsupported output in {}: `{}`\n\
697+
Found a `cargo::key=value` build directive which is reserved for future use.\n\
698+
Either change the directive to `cargo:key=value` syntax (note the single `:`) or upgrade your version of Rust.\n\
699+
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
700+
for more information about build script outputs.", whence, line);
701+
}
702+
val
703+
}
694704
None => continue,
695705
};
696706

‎tests/testsuite/build_script.rs

+29
Original file line numberDiff line numberDiff line change
@@ -5140,6 +5140,35 @@ for more information about build script outputs.
51405140
.run();
51415141
}
51425142

5143+
#[cargo_test]
5144+
fn wrong_syntax_with_two_colons() {
5145+
let p = project()
5146+
.file("src/lib.rs", "")
5147+
.file(
5148+
"build.rs",
5149+
r#"
5150+
fn main() {
5151+
println!("cargo::foo=bar");
5152+
}
5153+
"#,
5154+
)
5155+
.build();
5156+
5157+
p.cargo("build")
5158+
.with_status(101)
5159+
.with_stderr(
5160+
"\
5161+
[COMPILING] foo [..]
5162+
error: unsupported output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo::foo=bar`
5163+
Found a `cargo::key=value` build directive which is reserved for future use.
5164+
Either change the directive to `cargo:key=value` syntax (note the single `:`) or upgrade your version of Rust.
5165+
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
5166+
for more information about build script outputs.
5167+
",
5168+
)
5169+
.run();
5170+
}
5171+
51435172
#[cargo_test]
51445173
fn custom_build_closes_stdin() {
51455174
// Ensure stdin is closed to prevent deadlock.

0 commit comments

Comments
 (0)
Please sign in to comment.