about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJieyou Xu <jieyouxu@outlook.com>2025-07-30 19:54:47 +0800
committerJieyou Xu <jieyouxu@outlook.com>2025-07-30 19:55:08 +0800
commit2033a06d7fb1970794998331dd8747e19caaa6e7 (patch)
treea25d26b2698ff43523a9795a9f1aebfe944ae57c
parenta7fcc738c98d04ea5b504719555478becbba3dce (diff)
downloadrust-2033a06d7fb1970794998331dd8747e19caaa6e7.tar.gz
rust-2033a06d7fb1970794998331dd8747e19caaa6e7.zip
Deny `compiletest` self-tests being run against stage 0 rustc unless explicitly allowed
Otherwise, `compiletest` would have to know e.g. how to parse two
different target spec, if target spec format was changed between beta
`rustc` and in-tree `rustc`.
-rw-r--r--src/bootstrap/src/core/build_steps/test.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs
index 3f62f8b2013..951ca73fcc4 100644
--- a/src/bootstrap/src/core/build_steps/test.rs
+++ b/src/bootstrap/src/core/build_steps/test.rs
@@ -8,6 +8,9 @@ use std::ffi::{OsStr, OsString};
 use std::path::{Path, PathBuf};
 use std::{env, fs, iter};
 
+#[cfg(feature = "tracing")]
+use tracing::instrument;
+
 use crate::core::build_steps::compile::{Std, run_cargo};
 use crate::core::build_steps::doc::DocumentationFormat;
 use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
@@ -30,7 +33,7 @@ use crate::utils::helpers::{
     linker_flags, t, target_supports_cranelift_backend, up_to_date,
 };
 use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
-use crate::{CLang, DocTests, GitRepo, Mode, PathSet, envify};
+use crate::{CLang, DocTests, GitRepo, Mode, PathSet, debug, envify};
 
 const ADB_TEST_DIR: &str = "/data/local/tmp/work";
 
@@ -713,9 +716,23 @@ impl Step for CompiletestTest {
     }
 
     /// Runs `cargo test` for compiletest.
+    #[cfg_attr(
+        feature = "tracing",
+        instrument(level = "debug", name = "CompiletestTest::run", skip_all)
+    )]
     fn run(self, builder: &Builder<'_>) {
         let host = self.host;
+
+        if builder.top_stage == 0 && !builder.config.compiletest_allow_stage0 {
+            eprintln!("\
+ERROR: `--stage 0` runs compiletest self-tests against the stage0 (precompiled) compiler, not the in-tree compiler, and will almost always cause tests to fail
+NOTE: if you're sure you want to do this, please open an issue as to why. In the meantime, you can override this with `--set build.compiletest-allow-stage0=true`."
+            );
+            crate::exit!(1);
+        }
+
         let compiler = builder.compiler(builder.top_stage, host);
+        debug!(?compiler);
 
         // We need `ToolStd` for the locally-built sysroot because
         // compiletest uses unstable features of the `test` crate.