From 85c286aaa839d61c25398cce5aa3b1889e5861c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 10 Jul 2025 10:12:55 +0200 Subject: [PATCH] Clarify `get_tool_target_compiler` --- src/bootstrap/src/core/build_steps/tool.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index daa47db76b0c..caaaaad845d6 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -381,20 +381,26 @@ pub(crate) fn get_tool_target_compiler( builder: &Builder<'_>, mode: ToolTargetBuildMode, ) -> Compiler { - let (target, min_build_compiler_stage) = match mode { + let (target, build_compiler_stage) = match mode { ToolTargetBuildMode::Build(target) => { assert!(builder.top_stage > 0); + // If we want to build a stage N tool, we need to compile it with stage N-1 rustc (target, builder.top_stage - 1) } ToolTargetBuildMode::Dist(target_compiler) => { assert!(target_compiler.stage > 0); + // If we want to dist a stage N rustc, we want to attach stage N tool to it. + // And to build that tool, we need to compile it with stage N-1 rustc (target_compiler.host, target_compiler.stage - 1) } }; + let compiler = if builder.host_target == target { - builder.compiler(min_build_compiler_stage, builder.host_target) + builder.compiler(build_compiler_stage, builder.host_target) } else { - builder.compiler(min_build_compiler_stage.max(1), builder.host_target) + // If we are cross-compiling a stage 1 tool, we cannot do that with a stage 0 compiler, + // so we auto-bump the tool's stage to 2. + builder.compiler(build_compiler_stage.max(1), builder.host_target) }; builder.std(compiler, target); compiler