mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Restrict RUSTC_BOOTSTRAP in build.rs
This commit is contained in:
parent
8eb0e9a855
commit
6c422a2c0a
@ -562,7 +562,19 @@ impl BuildOutput {
|
||||
}
|
||||
}
|
||||
"rustc-cfg" => cfgs.push(value.to_string()),
|
||||
"rustc-env" => env.push(BuildOutput::parse_rustc_env(&value, &whence)?),
|
||||
"rustc-env" => {
|
||||
let (key, val) = BuildOutput::parse_rustc_env(&value, &whence)?;
|
||||
// See https://github.com/rust-lang/cargo/issues/7088
|
||||
if key == "RUSTC_BOOTSTRAP" {
|
||||
anyhow::bail!("Cannot set `RUSTC_BOOTSTRAP` from {}.\n\
|
||||
note: Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
|
||||
help: If you're sure you want to do this in your project, use `RUSTC_BOOTSTRAP=1 cargo build` instead.
|
||||
help: See https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-env for details.",
|
||||
whence
|
||||
);
|
||||
}
|
||||
env.push((key, val));
|
||||
}
|
||||
"warning" => warnings.push(value.to_string()),
|
||||
"rerun-if-changed" => rerun_if_changed.push(PathBuf::from(value)),
|
||||
"rerun-if-env-changed" => rerun_if_env_changed.push(value.to_string()),
|
||||
|
@ -106,3 +106,22 @@ fn rerun_if_env_or_file_changes() {
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn rustc_bootstrap_is_disallowed() {
|
||||
let p = project()
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.file(
|
||||
"build.rs",
|
||||
r#"
|
||||
fn main() {
|
||||
println!("cargo:rustc-env=RUSTC_BOOTSTRAP=1");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
p.cargo("build")
|
||||
.with_stderr_contains("error: Cannot set `RUSTC_BOOTSTRAP` [..]")
|
||||
.with_status(101)
|
||||
.run();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user