@@ -537,23 +537,25 @@ impl Builder<'_> {
537537 }
538538 }
539539
540- let stage = if compiler. stage == 0 && self . local_rebuild {
540+ let build_compiler_stage = if compiler. stage == 0 && self . local_rebuild {
541541 // Assume the local-rebuild rustc already has stage1 features.
542542 1
543543 } else {
544544 compiler. stage
545545 } ;
546546
547547 // We synthetically interpret a stage0 compiler used to build tools as a
548- // "raw" compiler in that it's the exact snapshot we download. Normally
549- // the stage0 build means it uses libraries build by the stage0
550- // compiler, but for tools we just use the precompiled libraries that
551- // we've downloaded
552- let use_snapshot = mode == Mode :: ToolBootstrap ;
553- assert ! ( !use_snapshot || stage == 0 || self . local_rebuild) ;
554-
555- let maybe_sysroot = self . sysroot ( compiler) ;
556- let sysroot = if use_snapshot { self . rustc_snapshot_sysroot ( ) } else { & maybe_sysroot } ;
548+ // "raw" compiler in that it's the exact snapshot we download. For things like
549+ // ToolRustc, we would have to use the artificial stage0-sysroot compiler instead.
550+ let use_snapshot =
551+ mode == Mode :: ToolBootstrap || ( mode == Mode :: ToolTarget && build_compiler_stage == 0 ) ;
552+ assert ! ( !use_snapshot || build_compiler_stage == 0 || self . local_rebuild) ;
553+
554+ let sysroot = if use_snapshot {
555+ self . rustc_snapshot_sysroot ( ) . to_path_buf ( )
556+ } else {
557+ self . sysroot ( compiler)
558+ } ;
557559 let libdir = self . rustc_libdir ( compiler) ;
558560
559561 let sysroot_str = sysroot. as_os_str ( ) . to_str ( ) . expect ( "sysroot should be UTF-8" ) ;
@@ -562,7 +564,7 @@ impl Builder<'_> {
562564 }
563565
564566 let mut rustflags = Rustflags :: new ( target) ;
565- if stage != 0 {
567+ if build_compiler_stage != 0 {
566568 if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
567569 cargo. args ( s. split_whitespace ( ) ) ;
568570 }
@@ -604,7 +606,7 @@ impl Builder<'_> {
604606 // sysroot. Passing this cfg enables raw-dylib support instead, which makes the native
605607 // library unnecessary. This can be removed when windows-rs enables raw-dylib
606608 // unconditionally.
607- if let Mode :: Rustc | Mode :: ToolRustc | Mode :: ToolBootstrap = mode {
609+ if let Mode :: Rustc | Mode :: ToolRustc | Mode :: ToolBootstrap | Mode :: ToolTarget = mode {
608610 rustflags. arg ( "--cfg=windows_raw_dylib" ) ;
609611 }
610612
@@ -657,7 +659,7 @@ impl Builder<'_> {
657659 // FIXME(rust-lang/cargo#5754) we shouldn't be using special command arguments
658660 // to the host invocation here, but rather Cargo should know what flags to pass rustc
659661 // itself.
660- if stage == 0 {
662+ if build_compiler_stage == 0 {
661663 hostflags. arg ( "--cfg=bootstrap" ) ;
662664 }
663665
@@ -666,7 +668,7 @@ impl Builder<'_> {
666668 // #71458.
667669 let mut rustdocflags = rustflags. clone ( ) ;
668670 rustdocflags. propagate_cargo_env ( "RUSTDOCFLAGS" ) ;
669- if stage == 0 {
671+ if build_compiler_stage == 0 {
670672 rustdocflags. env ( "RUSTDOCFLAGS_BOOTSTRAP" ) ;
671673 } else {
672674 rustdocflags. env ( "RUSTDOCFLAGS_NOT_BOOTSTRAP" ) ;
@@ -677,7 +679,7 @@ impl Builder<'_> {
677679 }
678680
679681 match mode {
680- Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolStd => { }
682+ Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolTarget => { }
681683 Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => {
682684 // Build proc macros both for the host and the target unless proc-macros are not
683685 // supported by the target.
@@ -719,7 +721,7 @@ impl Builder<'_> {
719721 // feature on the rustc side.
720722 cargo. arg ( "-Zbinary-dep-depinfo" ) ;
721723 let allow_features = match mode {
722- Mode :: ToolBootstrap | Mode :: ToolStd => {
724+ Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolTarget => {
723725 // Restrict the allowed features so we don't depend on nightly
724726 // accidentally.
725727 //
@@ -827,7 +829,7 @@ impl Builder<'_> {
827829 cargo
828830 . env ( "RUSTBUILD_NATIVE_DIR" , self . native_dir ( target) )
829831 . env ( "RUSTC_REAL" , self . rustc ( compiler) )
830- . env ( "RUSTC_STAGE" , stage . to_string ( ) )
832+ . env ( "RUSTC_STAGE" , build_compiler_stage . to_string ( ) )
831833 . env ( "RUSTC_SYSROOT" , sysroot)
832834 . env ( "RUSTC_LIBDIR" , libdir)
833835 . env ( "RUSTDOC" , self . bootstrap_out . join ( "rustdoc" ) )
@@ -872,7 +874,7 @@ impl Builder<'_> {
872874 let debuginfo_level = match mode {
873875 Mode :: Rustc | Mode :: Codegen => self . config . rust_debuginfo_level_rustc ,
874876 Mode :: Std => self . config . rust_debuginfo_level_std ,
875- Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolRustc => {
877+ Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolRustc | Mode :: ToolTarget => {
876878 self . config . rust_debuginfo_level_tools
877879 }
878880 } ;
@@ -884,11 +886,10 @@ impl Builder<'_> {
884886 profile_var ( "DEBUG_ASSERTIONS" ) ,
885887 match mode {
886888 Mode :: Std => self . config . std_debug_assertions ,
887- Mode :: Rustc => self . config . rustc_debug_assertions ,
888- Mode :: Codegen => self . config . rustc_debug_assertions ,
889- Mode :: ToolBootstrap => self . config . tools_debug_assertions ,
890- Mode :: ToolStd => self . config . tools_debug_assertions ,
891- Mode :: ToolRustc => self . config . tools_debug_assertions ,
889+ Mode :: Rustc | Mode :: Codegen => self . config . rustc_debug_assertions ,
890+ Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolRustc | Mode :: ToolTarget => {
891+ self . config . tools_debug_assertions
892+ }
892893 }
893894 . to_string ( ) ,
894895 ) ;
@@ -959,7 +960,11 @@ impl Builder<'_> {
959960 cargo. env ( "CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR" , map_to) ;
960961 }
961962 }
962- Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolRustc | Mode :: ToolStd => {
963+ Mode :: Std
964+ | Mode :: ToolBootstrap
965+ | Mode :: ToolRustc
966+ | Mode :: ToolStd
967+ | Mode :: ToolTarget => {
963968 if let Some ( ref map_to) =
964969 self . build . debuginfo_map_to ( GitRepo :: Rustc , RemapScheme :: NonCompiler )
965970 {
@@ -1274,7 +1279,7 @@ impl Builder<'_> {
12741279 } ;
12751280
12761281 if let Some ( limit) = limit
1277- && ( stage == 0
1282+ && ( build_compiler_stage == 0
12781283 || self . config . default_codegen_backend ( target) . unwrap_or_default ( ) == "llvm" )
12791284 {
12801285 rustflags. arg ( & format ! ( "-Cllvm-args=-import-instr-limit={limit}" ) ) ;
0 commit comments