@@ -532,23 +532,25 @@ impl Builder<'_> {
532
532
}
533
533
}
534
534
535
- let stage = if compiler. stage == 0 && self . local_rebuild {
535
+ let build_compiler_stage = if compiler. stage == 0 && self . local_rebuild {
536
536
// Assume the local-rebuild rustc already has stage1 features.
537
537
1
538
538
} else {
539
539
compiler. stage
540
540
} ;
541
541
542
542
// 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
+ } ;
552
554
let libdir = self . rustc_libdir ( compiler) ;
553
555
554
556
let sysroot_str = sysroot. as_os_str ( ) . to_str ( ) . expect ( "sysroot should be UTF-8" ) ;
@@ -557,7 +559,7 @@ impl Builder<'_> {
557
559
}
558
560
559
561
let mut rustflags = Rustflags :: new ( target) ;
560
- if stage != 0 {
562
+ if build_compiler_stage != 0 {
561
563
if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
562
564
cargo. args ( s. split_whitespace ( ) ) ;
563
565
}
@@ -599,7 +601,7 @@ impl Builder<'_> {
599
601
// sysroot. Passing this cfg enables raw-dylib support instead, which makes the native
600
602
// library unnecessary. This can be removed when windows-rs enables raw-dylib
601
603
// unconditionally.
602
- if let Mode :: Rustc | Mode :: ToolRustc | Mode :: ToolBootstrap = mode {
604
+ if let Mode :: Rustc | Mode :: ToolRustc | Mode :: ToolBootstrap | Mode :: ToolTarget = mode {
603
605
rustflags. arg ( "--cfg=windows_raw_dylib" ) ;
604
606
}
605
607
@@ -652,7 +654,7 @@ impl Builder<'_> {
652
654
// FIXME(rust-lang/cargo#5754) we shouldn't be using special command arguments
653
655
// to the host invocation here, but rather Cargo should know what flags to pass rustc
654
656
// itself.
655
- if stage == 0 {
657
+ if build_compiler_stage == 0 {
656
658
hostflags. arg ( "--cfg=bootstrap" ) ;
657
659
}
658
660
@@ -661,7 +663,7 @@ impl Builder<'_> {
661
663
// #71458.
662
664
let mut rustdocflags = rustflags. clone ( ) ;
663
665
rustdocflags. propagate_cargo_env ( "RUSTDOCFLAGS" ) ;
664
- if stage == 0 {
666
+ if build_compiler_stage == 0 {
665
667
rustdocflags. env ( "RUSTDOCFLAGS_BOOTSTRAP" ) ;
666
668
} else {
667
669
rustdocflags. env ( "RUSTDOCFLAGS_NOT_BOOTSTRAP" ) ;
@@ -672,7 +674,7 @@ impl Builder<'_> {
672
674
}
673
675
674
676
match mode {
675
- Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolStd => { }
677
+ Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolTarget => { }
676
678
Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => {
677
679
// Build proc macros both for the host and the target unless proc-macros are not
678
680
// supported by the target.
@@ -714,7 +716,7 @@ impl Builder<'_> {
714
716
// feature on the rustc side.
715
717
cargo. arg ( "-Zbinary-dep-depinfo" ) ;
716
718
let allow_features = match mode {
717
- Mode :: ToolBootstrap | Mode :: ToolStd => {
719
+ Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolTarget => {
718
720
// Restrict the allowed features so we don't depend on nightly
719
721
// accidentally.
720
722
//
@@ -822,7 +824,7 @@ impl Builder<'_> {
822
824
cargo
823
825
. env ( "RUSTBUILD_NATIVE_DIR" , self . native_dir ( target) )
824
826
. env ( "RUSTC_REAL" , self . rustc ( compiler) )
825
- . env ( "RUSTC_STAGE" , stage . to_string ( ) )
827
+ . env ( "RUSTC_STAGE" , build_compiler_stage . to_string ( ) )
826
828
. env ( "RUSTC_SYSROOT" , sysroot)
827
829
. env ( "RUSTC_LIBDIR" , libdir)
828
830
. env ( "RUSTDOC" , self . bootstrap_out . join ( "rustdoc" ) )
@@ -867,7 +869,7 @@ impl Builder<'_> {
867
869
let debuginfo_level = match mode {
868
870
Mode :: Rustc | Mode :: Codegen => self . config . rust_debuginfo_level_rustc ,
869
871
Mode :: Std => self . config . rust_debuginfo_level_std ,
870
- Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolRustc => {
872
+ Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolRustc | Mode :: ToolTarget => {
871
873
self . config . rust_debuginfo_level_tools
872
874
}
873
875
} ;
@@ -879,11 +881,10 @@ impl Builder<'_> {
879
881
profile_var ( "DEBUG_ASSERTIONS" ) ,
880
882
match mode {
881
883
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
+ }
887
888
}
888
889
. to_string ( ) ,
889
890
) ;
@@ -954,7 +955,11 @@ impl Builder<'_> {
954
955
cargo. env ( "CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR" , map_to) ;
955
956
}
956
957
}
957
- Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolRustc | Mode :: ToolStd => {
958
+ Mode :: Std
959
+ | Mode :: ToolBootstrap
960
+ | Mode :: ToolRustc
961
+ | Mode :: ToolStd
962
+ | Mode :: ToolTarget => {
958
963
if let Some ( ref map_to) =
959
964
self . build . debuginfo_map_to ( GitRepo :: Rustc , RemapScheme :: NonCompiler )
960
965
{
@@ -1269,7 +1274,7 @@ impl Builder<'_> {
1269
1274
} ;
1270
1275
1271
1276
if let Some ( limit) = limit
1272
- && ( stage == 0
1277
+ && ( build_compiler_stage == 0
1273
1278
|| self . config . default_codegen_backend ( target) . unwrap_or_default ( ) == "llvm" )
1274
1279
{
1275
1280
rustflags. arg ( & format ! ( "-Cllvm-args=-import-instr-limit={limit}" ) ) ;
0 commit comments