From 55298ea6ea61f337ac563381582b66d3aa9c0b7f Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sat, 10 May 2025 19:25:46 +0300 Subject: [PATCH 1/2] if stage isn't set explicitly, default to 1 when running miri Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/run.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/src/core/build_steps/run.rs b/src/bootstrap/src/core/build_steps/run.rs index 0bba441c3fa26..f6eb1f6fd9055 100644 --- a/src/bootstrap/src/core/build_steps/run.rs +++ b/src/bootstrap/src/core/build_steps/run.rs @@ -118,7 +118,15 @@ impl Step for Miri { fn run(self, builder: &Builder<'_>) { let host = builder.build.build; let target = self.target; - let stage = builder.top_stage; + + // `x run` uses stage 0 by default but miri does not work well with stage 0. + // Change the stage to 1 if it's not set explicitly. + let stage = if builder.config.is_explicit_stage() || builder.top_stage >= 1 { + builder.top_stage + } else { + 1 + }; + if stage == 0 { eprintln!("miri cannot be run at stage 0"); std::process::exit(1); From 17d27c993e67f5a466a0911cf1f54df93514d8db Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sat, 10 May 2025 19:23:36 +0300 Subject: [PATCH 2/2] let `tool::Miri` implementation to handle compilers Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/run.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/run.rs b/src/bootstrap/src/core/build_steps/run.rs index f6eb1f6fd9055..eeba7780c65b3 100644 --- a/src/bootstrap/src/core/build_steps/run.rs +++ b/src/bootstrap/src/core/build_steps/run.rs @@ -133,8 +133,10 @@ impl Step for Miri { } // This compiler runs on the host, we'll just use it for the target. - let target_compiler = builder.compiler(stage, host); - let host_compiler = tool::get_tool_rustc_compiler(builder, target_compiler); + let target_compiler = builder.compiler(stage, target); + let miri_build = builder.ensure(tool::Miri { compiler: target_compiler, target }); + // Rustc tools are off by one stage, so use the build compiler to run miri. + let host_compiler = miri_build.build_compiler; // Get a target sysroot for Miri. let miri_sysroot = test::Miri::build_miri_sysroot(builder, target_compiler, target);