@@ -537,23 +537,25 @@ impl Builder<'_> {
537
537
}
538
538
}
539
539
540
- let stage = if compiler. stage == 0 && self . local_rebuild {
540
+ let build_compiler_stage = if compiler. stage == 0 && self . local_rebuild {
541
541
// Assume the local-rebuild rustc already has stage1 features.
542
542
1
543
543
} else {
544
544
compiler. stage
545
545
} ;
546
546
547
547
// 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
+ } ;
557
559
let libdir = self . rustc_libdir ( compiler) ;
558
560
559
561
let sysroot_str = sysroot. as_os_str ( ) . to_str ( ) . expect ( "sysroot should be UTF-8" ) ;
@@ -562,7 +564,7 @@ impl Builder<'_> {
562
564
}
563
565
564
566
let mut rustflags = Rustflags :: new ( target) ;
565
- if stage != 0 {
567
+ if build_compiler_stage != 0 {
566
568
if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
567
569
cargo. args ( s. split_whitespace ( ) ) ;
568
570
}
@@ -604,7 +606,7 @@ impl Builder<'_> {
604
606
// sysroot. Passing this cfg enables raw-dylib support instead, which makes the native
605
607
// library unnecessary. This can be removed when windows-rs enables raw-dylib
606
608
// unconditionally.
607
- if let Mode :: Rustc | Mode :: ToolRustc | Mode :: ToolBootstrap = mode {
609
+ if let Mode :: Rustc | Mode :: ToolRustc | Mode :: ToolBootstrap | Mode :: ToolTarget = mode {
608
610
rustflags. arg ( "--cfg=windows_raw_dylib" ) ;
609
611
}
610
612
@@ -657,7 +659,7 @@ impl Builder<'_> {
657
659
// FIXME(rust-lang/cargo#5754) we shouldn't be using special command arguments
658
660
// to the host invocation here, but rather Cargo should know what flags to pass rustc
659
661
// itself.
660
- if stage == 0 {
662
+ if build_compiler_stage == 0 {
661
663
hostflags. arg ( "--cfg=bootstrap" ) ;
662
664
}
663
665
@@ -666,7 +668,7 @@ impl Builder<'_> {
666
668
// #71458.
667
669
let mut rustdocflags = rustflags. clone ( ) ;
668
670
rustdocflags. propagate_cargo_env ( "RUSTDOCFLAGS" ) ;
669
- if stage == 0 {
671
+ if build_compiler_stage == 0 {
670
672
rustdocflags. env ( "RUSTDOCFLAGS_BOOTSTRAP" ) ;
671
673
} else {
672
674
rustdocflags. env ( "RUSTDOCFLAGS_NOT_BOOTSTRAP" ) ;
@@ -677,7 +679,7 @@ impl Builder<'_> {
677
679
}
678
680
679
681
match mode {
680
- Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolStd => { }
682
+ Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolTarget => { }
681
683
Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => {
682
684
// Build proc macros both for the host and the target unless proc-macros are not
683
685
// supported by the target.
@@ -719,7 +721,7 @@ impl Builder<'_> {
719
721
// feature on the rustc side.
720
722
cargo. arg ( "-Zbinary-dep-depinfo" ) ;
721
723
let allow_features = match mode {
722
- Mode :: ToolBootstrap | Mode :: ToolStd => {
724
+ Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolTarget => {
723
725
// Restrict the allowed features so we don't depend on nightly
724
726
// accidentally.
725
727
//
@@ -827,7 +829,7 @@ impl Builder<'_> {
827
829
cargo
828
830
. env ( "RUSTBUILD_NATIVE_DIR" , self . native_dir ( target) )
829
831
. env ( "RUSTC_REAL" , self . rustc ( compiler) )
830
- . env ( "RUSTC_STAGE" , stage . to_string ( ) )
832
+ . env ( "RUSTC_STAGE" , build_compiler_stage . to_string ( ) )
831
833
. env ( "RUSTC_SYSROOT" , sysroot)
832
834
. env ( "RUSTC_LIBDIR" , libdir)
833
835
. env ( "RUSTDOC" , self . bootstrap_out . join ( "rustdoc" ) )
@@ -872,7 +874,7 @@ impl Builder<'_> {
872
874
let debuginfo_level = match mode {
873
875
Mode :: Rustc | Mode :: Codegen => self . config . rust_debuginfo_level_rustc ,
874
876
Mode :: Std => self . config . rust_debuginfo_level_std ,
875
- Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolRustc => {
877
+ Mode :: ToolBootstrap | Mode :: ToolStd | Mode :: ToolRustc | Mode :: ToolTarget => {
876
878
self . config . rust_debuginfo_level_tools
877
879
}
878
880
} ;
@@ -884,11 +886,10 @@ impl Builder<'_> {
884
886
profile_var ( "DEBUG_ASSERTIONS" ) ,
885
887
match mode {
886
888
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
+ }
892
893
}
893
894
. to_string ( ) ,
894
895
) ;
@@ -959,7 +960,11 @@ impl Builder<'_> {
959
960
cargo. env ( "CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR" , map_to) ;
960
961
}
961
962
}
962
- Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolRustc | Mode :: ToolStd => {
963
+ Mode :: Std
964
+ | Mode :: ToolBootstrap
965
+ | Mode :: ToolRustc
966
+ | Mode :: ToolStd
967
+ | Mode :: ToolTarget => {
963
968
if let Some ( ref map_to) =
964
969
self . build . debuginfo_map_to ( GitRepo :: Rustc , RemapScheme :: NonCompiler )
965
970
{
@@ -1274,7 +1279,7 @@ impl Builder<'_> {
1274
1279
} ;
1275
1280
1276
1281
if let Some ( limit) = limit
1277
- && ( stage == 0
1282
+ && ( build_compiler_stage == 0
1278
1283
|| self . config . default_codegen_backend ( target) . unwrap_or_default ( ) == "llvm" )
1279
1284
{
1280
1285
rustflags. arg ( & format ! ( "-Cllvm-args=-import-instr-limit={limit}" ) ) ;
0 commit comments