Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid setting RUSTC_BOOTSTRAP from build scripts #6608

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
32 changes: 32 additions & 0 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}