From 04fa2f2a3bab064eb4a71a73be579b5672f26d51 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 16 Apr 2021 11:48:44 -0400 Subject: [PATCH] Don't give a hard error on RUSTC_BOOTSTRAP=crate_name --- src/cargo/core/compiler/custom_build.rs | 10 +++++++++- tests/testsuite/build_script_env.rs | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index a7a5ca1ba..4f8e92ccc 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -589,7 +589,15 @@ impl BuildOutput { // to set RUSTC_BOOTSTRAP. // If this is a nightly build, setting RUSTC_BOOTSTRAP wouldn't affect the // behavior, so still only give a warning. - if nightly_features_allowed { + // NOTE: cargo only allows nightly features on RUSTC_BOOTSTRAP=1, but we + // want setting any value of RUSTC_BOOTSTRAP to downgrade this to a warning + // (so that `RUSTC_BOOTSTRAP=pkg_name` will work) + let rustc_bootstrap_allows = |name: &str| { + std::env::var("RUSTC_BOOTSTRAP").map_or(false, |var| { + var.split(',').any(|s| s == name) + }) + }; + if nightly_features_allowed || rustc_bootstrap_allows(&*pkg_name) { warnings.push(format!("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.", val, whence diff --git a/tests/testsuite/build_script_env.rs b/tests/testsuite/build_script_env.rs index f03a3024a..01dc6452e 100644 --- a/tests/testsuite/build_script_env.rs +++ b/tests/testsuite/build_script_env.rs @@ -129,4 +129,16 @@ fn rustc_bootstrap() { .masquerade_as_nightly_cargo() .with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]") .run(); + // RUSTC_BOOTSTRAP set to the name of the crate + p.cargo("build") + .env("RUSTC_BOOTSTRAP", "foo") + .with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]") + .run(); + // RUSTC_BOOTSTRAP set to some random value + p.cargo("build") + .env("RUSTC_BOOTSTRAP", "bar") + .with_stderr_contains("error: Cannot set `RUSTC_BOOTSTRAP=1` [..]") + .with_stderr_contains("help: [..] set the environment variable `RUSTC_BOOTSTRAP=foo` [..]") + .with_status(101) + .run(); }