@@ -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 }
@@ -599,7 +601,7 @@ impl Builder<'_> {
599601 // sysroot. Passing this cfg enables raw-dylib support instead, which makes the native
600602 // library unnecessary. This can be removed when windows-rs enables raw-dylib
601603 // unconditionally.
602- if let Mode :: Rustc | Mode :: ToolRustc | Mode :: ToolBootstrap = mode {
604+ if let Mode :: Rustc | Mode :: ToolRustc | Mode :: ToolBootstrap | Mode :: ToolTarget = mode {
603605 rustflags. arg ( "--cfg=windows_raw_dylib" ) ;
604606 }
605607
@@ -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" ) ;
@@ -672,7 +674,7 @@ impl Builder<'_> {
672674 }
673675
674676 match mode {
675- Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolStd => { }
677+ Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolTarget => { }
676678 Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => {
677679 // Build proc macros both for the host and the target unless proc-macros are not
678680 // supported by the target.
@@ -714,7 +716,7 @@ impl Builder<'_> {
714716 // feature on the rustc side.
715717 cargo. arg ( "-Zbinary-dep-depinfo" ) ;
716718 let allow_features = match mode {
717- Mode :: ToolBootstrap | Mode :: ToolStd => {
719+ Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolTarget => {
718720 // Restrict the allowed features so we don't depend on nightly
719721 // accidentally.
720722 //
@@ -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" ) )
@@ -867,7 +869,7 @@ impl Builder<'_> {
867869 let debuginfo_level = match mode {
868870 Mode :: Rustc | Mode :: Codegen => self . config . rust_debuginfo_level_rustc ,
869871 Mode :: Std => self . config . rust_debuginfo_level_std ,
870- Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolRustc => {
872+ Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolRustc | Mode :: ToolTarget => {
871873 self . config . rust_debuginfo_level_tools
872874 }
873875 } ;
@@ -879,11 +881,10 @@ impl Builder<'_> {
879881 profile_var ( "DEBUG_ASSERTIONS" ) ,
880882 match mode {
881883 Mode :: Std => self . config . std_debug_assertions ,
882- Mode :: Rustc => self . config . rustc_debug_assertions ,
883- Mode :: Codegen => self . config . rustc_debug_assertions ,
884- Mode :: ToolBootstrap => self . config . tools_debug_assertions ,
885- Mode :: ToolStd => self . config . tools_debug_assertions ,
886- Mode :: ToolRustc => self . config . tools_debug_assertions ,
884+ Mode :: Rustc | Mode :: Codegen => self . config . rustc_debug_assertions ,
885+ Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolRustc | Mode :: ToolTarget => {
886+ self . config . tools_debug_assertions
887+ }
887888 }
888889 . to_string ( ) ,
889890 ) ;
@@ -954,7 +955,11 @@ impl Builder<'_> {
954955 cargo. env ( "CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR" , map_to) ;
955956 }
956957 }
957- Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolRustc | Mode :: ToolStd => {
958+ Mode :: Std
959+ | Mode :: ToolBootstrap
960+ | Mode :: ToolRustc
961+ | Mode :: ToolStd
962+ | Mode :: ToolTarget => {
958963 if let Some ( ref map_to) =
959964 self . build . debuginfo_map_to ( GitRepo :: Rustc , RemapScheme :: NonCompiler )
960965 {
@@ -1269,7 +1274,7 @@ impl Builder<'_> {
12691274 } ;
12701275
12711276 if let Some ( limit) = limit
1272- && ( stage == 0
1277+ && ( build_compiler_stage == 0
12731278 || self . config . default_codegen_backend ( target) . unwrap_or_default ( ) == "llvm" )
12741279 {
12751280 rustflags. arg ( & format ! ( "-Cllvm-args=-import-instr-limit={limit}" ) ) ;
0 commit comments