Skip to content

Commit 04fa2f2

Browse files
committed
Don't give a hard error on RUSTC_BOOTSTRAP=crate_name
1 parent 163097c commit 04fa2f2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,15 @@ impl BuildOutput {
589589
// to set RUSTC_BOOTSTRAP.
590590
// If this is a nightly build, setting RUSTC_BOOTSTRAP wouldn't affect the
591591
// behavior, so still only give a warning.
592-
if nightly_features_allowed {
592+
// NOTE: cargo only allows nightly features on RUSTC_BOOTSTRAP=1, but we
593+
// want setting any value of RUSTC_BOOTSTRAP to downgrade this to a warning
594+
// (so that `RUSTC_BOOTSTRAP=pkg_name` will work)
595+
let rustc_bootstrap_allows = |name: &str| {
596+
std::env::var("RUSTC_BOOTSTRAP").map_or(false, |var| {
597+
var.split(',').any(|s| s == name)
598+
})
599+
};
600+
if nightly_features_allowed || rustc_bootstrap_allows(&*pkg_name) {
593601
warnings.push(format!("Cannot set `RUSTC_BOOTSTRAP={}` from {}.\n\
594602
note: Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.",
595603
val, whence

tests/testsuite/build_script_env.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,16 @@ fn rustc_bootstrap() {
129129
.masquerade_as_nightly_cargo()
130130
.with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
131131
.run();
132+
// RUSTC_BOOTSTRAP set to the name of the crate
133+
p.cargo("build")
134+
.env("RUSTC_BOOTSTRAP", "foo")
135+
.with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
136+
.run();
137+
// RUSTC_BOOTSTRAP set to some random value
138+
p.cargo("build")
139+
.env("RUSTC_BOOTSTRAP", "bar")
140+
.with_stderr_contains("error: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
141+
.with_stderr_contains("help: [..] set the environment variable `RUSTC_BOOTSTRAP=foo` [..]")
142+
.with_status(101)
143+
.run();
132144
}

0 commit comments

Comments
 (0)