@@ -532,23 +532,25 @@ impl Builder<'_> {
532532 }
533533 }
534534
535- let stage = if compiler. stage == 0 && self . local_rebuild {
535+ let build_compiler_stage = if compiler. stage == 0 && self . local_rebuild {
536536 // Assume the local-rebuild rustc already has stage1 features.
537537 1
538538 } else {
539539 compiler. stage
540540 } ;
541541
542542 // We synthetically interpret a stage0 compiler used to build tools as a
543- // "raw" compiler in that it's the exact snapshot we download. Normally
544- // the stage0 build means it uses libraries build by the stage0
545- // compiler, but for tools we just use the precompiled libraries that
546- // we've downloaded
547- let use_snapshot = mode == Mode :: ToolBootstrap ;
548- assert ! ( !use_snapshot || stage == 0 || self . local_rebuild) ;
549-
550- let maybe_sysroot = self . sysroot ( compiler) ;
551- let sysroot = if use_snapshot { self . rustc_snapshot_sysroot ( ) } else { & maybe_sysroot } ;
543+ // "raw" compiler in that it's the exact snapshot we download. For things like
544+ // ToolRustc, we would have to use the artificial stage0-sysroot compiler instead.
545+ let use_snapshot =
546+ mode == Mode :: ToolBootstrap || ( mode == Mode :: ToolTarget && build_compiler_stage == 0 ) ;
547+ assert ! ( !use_snapshot || build_compiler_stage == 0 || self . local_rebuild) ;
548+
549+ let sysroot = if use_snapshot {
550+ self . rustc_snapshot_sysroot ( ) . to_path_buf ( )
551+ } else {
552+ self . sysroot ( compiler)
553+ } ;
552554 let libdir = self . rustc_libdir ( compiler) ;
553555
554556 let sysroot_str = sysroot. as_os_str ( ) . to_str ( ) . expect ( "sysroot should be UTF-8" ) ;
@@ -557,7 +559,7 @@ impl Builder<'_> {
557559 }
558560
559561 let mut rustflags = Rustflags :: new ( target) ;
560- if stage != 0 {
562+ if build_compiler_stage != 0 {
561563 if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
562564 cargo. args ( s. split_whitespace ( ) ) ;
563565 }
@@ -652,7 +654,7 @@ impl Builder<'_> {
652654 // FIXME(rust-lang/cargo#5754) we shouldn't be using special command arguments
653655 // to the host invocation here, but rather Cargo should know what flags to pass rustc
654656 // itself.
655- if stage == 0 {
657+ if build_compiler_stage == 0 {
656658 hostflags. arg ( "--cfg=bootstrap" ) ;
657659 }
658660
@@ -661,7 +663,7 @@ impl Builder<'_> {
661663 // #71458.
662664 let mut rustdocflags = rustflags. clone ( ) ;
663665 rustdocflags. propagate_cargo_env ( "RUSTDOCFLAGS" ) ;
664- if stage == 0 {
666+ if build_compiler_stage == 0 {
665667 rustdocflags. env ( "RUSTDOCFLAGS_BOOTSTRAP" ) ;
666668 } else {
667669 rustdocflags. env ( "RUSTDOCFLAGS_NOT_BOOTSTRAP" ) ;
@@ -822,7 +824,7 @@ impl Builder<'_> {
822824 cargo
823825 . env ( "RUSTBUILD_NATIVE_DIR" , self . native_dir ( target) )
824826 . env ( "RUSTC_REAL" , self . rustc ( compiler) )
825- . env ( "RUSTC_STAGE" , stage . to_string ( ) )
827+ . env ( "RUSTC_STAGE" , build_compiler_stage . to_string ( ) )
826828 . env ( "RUSTC_SYSROOT" , sysroot)
827829 . env ( "RUSTC_LIBDIR" , libdir)
828830 . env ( "RUSTDOC" , self . bootstrap_out . join ( "rustdoc" ) )
@@ -1272,7 +1274,7 @@ impl Builder<'_> {
12721274 } ;
12731275
12741276 if let Some ( limit) = limit
1275- && ( stage == 0
1277+ && ( build_compiler_stage == 0
12761278 || self . config . default_codegen_backend ( target) . unwrap_or_default ( ) == "llvm" )
12771279 {
12781280 rustflags. arg ( & format ! ( "-Cllvm-args=-import-instr-limit={limit}" ) ) ;
0 commit comments