diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index c413ddcb66a..09b046bcc59 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -549,6 +549,9 @@ impl BuildOutput { let name = iter.next(); let val = iter.next(); match (name, val) { + (Some("RUSTC_BOOTSTRAP"), _) => { + failure::bail!("Build scripts are forbidden from setting RUSTC_BOOTSTRAP") + } (Some(n), Some(v)) => Ok((n.to_owned(), v.to_owned())), _ => failure::bail!("Variable rustc-env has no value in {}: {}", whence, value), } diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 9c4dd7031f1..78ba4c5cd1b 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -3696,3 +3696,35 @@ fn optional_build_dep_and_required_normal_dep() { ) .run(); } + +#[test] +fn say_no_to_bootstrap() { + project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.0.0" + "#, + ) + .file( + "build.rs", + r#" + fn main() { + println!("cargo:rustc-env=RUSTC_BOOTSTRAP=1"); + } + "#, + ) + .file("src/lib.rs", "") + .build() + .cargo("build -v") + .with_status(101) + .with_stderr("\ +[COMPILING] foo v0.0.0 ([..]) +[RUNNING] `rustc --crate-name build_script_build build.rs --color never --crate-type bin [..]` +[RUNNING] `[..]/build-script-build` +error: Build scripts are forbidden from setting RUSTC_BOOTSTRAP", + ) + .run(); +}