@@ -381,20 +381,26 @@ pub(crate) fn get_tool_target_compiler(
381
381
builder : & Builder < ' _ > ,
382
382
mode : ToolTargetBuildMode ,
383
383
) -> Compiler {
384
- let ( target, min_build_compiler_stage ) = match mode {
384
+ let ( target, build_compiler_stage ) = match mode {
385
385
ToolTargetBuildMode :: Build ( target) => {
386
386
assert ! ( builder. top_stage > 0 ) ;
387
+ // If we want to build a stage N tool, we need to compile it with stage N-1 rustc
387
388
( target, builder. top_stage - 1 )
388
389
}
389
390
ToolTargetBuildMode :: Dist ( target_compiler) => {
390
391
assert ! ( target_compiler. stage > 0 ) ;
392
+ // If we want to dist a stage N rustc, we want to attach stage N tool to it.
393
+ // And to build that tool, we need to compile it with stage N-1 rustc
391
394
( target_compiler. host , target_compiler. stage - 1 )
392
395
}
393
396
} ;
397
+
394
398
let compiler = if builder. host_target == target {
395
- builder. compiler ( min_build_compiler_stage , builder. host_target )
399
+ builder. compiler ( build_compiler_stage , builder. host_target )
396
400
} else {
397
- builder. compiler ( min_build_compiler_stage. max ( 1 ) , builder. host_target )
401
+ // If we are cross-compiling a stage 1 tool, we cannot do that with a stage 0 compiler,
402
+ // so we auto-bump the tool's stage to 2.
403
+ builder. compiler ( build_compiler_stage. max ( 1 ) , builder. host_target )
398
404
} ;
399
405
builder. std ( compiler, target) ;
400
406
compiler
0 commit comments