From b0ea4e74cbcb7e4e42f622cda098b95e583f62d9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 22 May 2022 08:30:56 -0500 Subject: [PATCH 1/2] Avoid accidentally enabling unstable features in compilers (take 2) This allows rustbuild to control whether crates can use nightly features or not. It also prevents rustbuild from using nightly features itself. --- src/bootstrap/bootstrap.py | 1 - src/bootstrap/doc.rs | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index e38a574ca2310..7a684c89fe31f 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -1171,7 +1171,6 @@ def bootstrap(help_triggered): env = os.environ.copy() env["BOOTSTRAP_PARENT_ID"] = str(os.getpid()) env["BOOTSTRAP_PYTHON"] = sys.executable - env["RUSTC_BOOTSTRAP"] = '1' if build.rustc_commit is not None: env["BOOTSTRAP_DOWNLOAD_RUSTC"] = '1' run(args, env=env, verbose=build.verbose, is_bootstrap=True) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index fcef784d2d1fa..be6655ddb61d0 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -881,6 +881,10 @@ impl Step for RustcBook { if self.validate { cmd.arg("--validate"); } + if !builder.unstable_features() { + // We need to validate nightly features, even on the stable channel. + cmd.env("RUSTC_BOOTSTRAP", "1"); + } // If the lib directories are in an unusual location (changed in // config.toml), then this needs to explicitly update the dylib search // path. From 751ad4a0e9fc43a9e810cce69d4cef581323e79a Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 22 May 2022 09:44:23 -0500 Subject: [PATCH 2/2] Disable unstable features in bootstrap tools This statically prevents issues like https://github.com/rust-lang/rust/issues/59264, where tools can only be built with the in-tree compiler and not beta. --- src/bootstrap/builder.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 2224bf5f66e90..68d0d685ebb40 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1201,6 +1201,14 @@ impl<'a> Builder<'a> { // this), as well as #63012 which is the tracking issue for this // feature on the rustc side. cargo.arg("-Zbinary-dep-depinfo"); + match mode { + Mode::ToolBootstrap => { + // Restrict the allowed features to those passed by rustbuild, so we don't depend on nightly accidentally. + // HACK: because anyhow does feature detection in build.rs, we need to allow the backtrace feature too. + rustflags.arg("-Zallow-features=binary-dep-depinfo,backtrace"); + } + Mode::Std | Mode::Rustc | Mode::ToolStd | Mode::Codegen | Mode::ToolRustc => {} + } cargo.arg("-j").arg(self.jobs().to_string()); // Remove make-related flags to ensure Cargo can correctly set things up