@@ -933,6 +933,15 @@ fn cp_rustc_component_to_ci_sysroot(builder: &Builder<'_>, sysroot: &Path, conte
933
933
}
934
934
}
935
935
936
+ /// Represents information about a built rustc.
937
+ #[ derive( Clone , Debug ) ]
938
+ pub struct BuiltRustc {
939
+ /// The compiler that actually built this *rustc*.
940
+ /// This can be different from the *build_compiler* passed to the `Rustc` step because of
941
+ /// uplifting.
942
+ pub build_compiler : Compiler ,
943
+ }
944
+
936
945
/// Build rustc using the passed `build_compiler`.
937
946
///
938
947
/// - Makes sure that `build_compiler` has a standard library prepared for its host target,
@@ -960,7 +969,7 @@ impl Rustc {
960
969
}
961
970
962
971
impl Step for Rustc {
963
- type Output = ( ) ;
972
+ type Output = BuiltRustc ;
964
973
965
974
const IS_HOST : bool = true ;
966
975
const DEFAULT : bool = false ;
@@ -1000,7 +1009,7 @@ impl Step for Rustc {
1000
1009
/// This will build the compiler for a particular stage of the build using
1001
1010
/// the `build_compiler` targeting the `target` architecture. The artifacts
1002
1011
/// created will also be linked into the sysroot directory.
1003
- fn run ( self , builder : & Builder < ' _ > ) {
1012
+ fn run ( self , builder : & Builder < ' _ > ) -> Self :: Output {
1004
1013
let build_compiler = self . build_compiler ;
1005
1014
let target = self . target ;
1006
1015
@@ -1016,7 +1025,7 @@ impl Step for Rustc {
1016
1025
& sysroot,
1017
1026
builder. config . ci_rustc_dev_contents ( ) ,
1018
1027
) ;
1019
- return ;
1028
+ return BuiltRustc { build_compiler } ;
1020
1029
}
1021
1030
1022
1031
// Build a standard library for `target` using the `build_compiler`.
@@ -1028,9 +1037,9 @@ impl Step for Rustc {
1028
1037
1029
1038
builder. info ( "WARNING: Using a potentially old librustc. This may not behave well." ) ;
1030
1039
builder. info ( "WARNING: Use `--keep-stage-std` if you want to rebuild the compiler when it changes" ) ;
1031
- builder. ensure ( RustcLink :: from_rustc ( self , build_compiler ) ) ;
1040
+ builder. ensure ( RustcLink :: from_rustc ( self ) ) ;
1032
1041
1033
- return ;
1042
+ return BuiltRustc { build_compiler } ;
1034
1043
}
1035
1044
1036
1045
// The stage of the compiler that we're building
@@ -1042,21 +1051,31 @@ impl Step for Rustc {
1042
1051
&& !builder. config . full_bootstrap
1043
1052
&& ( target == builder. host_target || builder. hosts . contains ( & target) )
1044
1053
{
1045
- // If we're cross-compiling, the earliest rustc that we could have is stage 2.
1046
- // If we're not cross-compiling, then we should have rustc stage 1.
1054
+ // Here we need to determine the **build compiler** that built the stage that we will
1055
+ // be uplifting.
1056
+ // - If we're cross-compiling, the earliest rustc that we could have is stage 2, so its
1057
+ // build compiler is stage 1.
1058
+ // - If we're not cross-compiling, then we should have rustc stage 1, so its build
1059
+ // compiler is stage 0.
1047
1060
let stage_to_uplift = if target == builder. host_target { 1 } else { 2 } ;
1048
- let rustc_to_uplift = builder. compiler ( stage_to_uplift, target ) ;
1049
- let msg = if rustc_to_uplift . host == target {
1050
- format ! ( "Uplifting rustc (stage{} -> stage{stage})" , rustc_to_uplift . stage , )
1061
+ let build_compiler = builder. compiler ( stage_to_uplift - 1 , build_compiler . host ) ;
1062
+ let msg = if build_compiler . host == target {
1063
+ format ! ( "Uplifting rustc (stage{stage_to_uplift } -> stage{stage})" )
1051
1064
} else {
1052
1065
format ! (
1053
- "Uplifting rustc (stage{}:{} -> stage{stage}:{target})" ,
1054
- rustc_to_uplift . stage , rustc_to_uplift . host,
1066
+ "Uplifting rustc (stage{stage_to_uplift }:{} -> stage{stage}:{target})" ,
1067
+ build_compiler . host
1055
1068
)
1056
1069
} ;
1057
1070
builder. info ( & msg) ;
1058
- builder. ensure ( RustcLink :: from_rustc ( self , rustc_to_uplift) ) ;
1059
- return ;
1071
+
1072
+ // Note that we do not invoke `RustcLink` here. Because the uplifted compiled was
1073
+ // already built before using `build_compiler`, and its rlibs thus also had to be copied
1074
+ // into the build compiler's sysroot.
1075
+
1076
+ // Here we have performed an uplift, so we return the actual built compiler that "built"
1077
+ // this rustc.
1078
+ return BuiltRustc { build_compiler } ;
1060
1079
}
1061
1080
1062
1081
// Build a standard library for the current host target using the `build_compiler`.
@@ -1129,10 +1148,8 @@ impl Step for Rustc {
1129
1148
strip_debug ( builder, target, & target_root_dir. join ( "rustc-main" ) ) ;
1130
1149
}
1131
1150
1132
- builder. ensure ( RustcLink :: from_rustc (
1133
- self ,
1134
- builder. compiler ( build_compiler. stage , builder. config . host_target ) ,
1135
- ) ) ;
1151
+ builder. ensure ( RustcLink :: from_rustc ( self ) ) ;
1152
+ BuiltRustc { build_compiler }
1136
1153
}
1137
1154
1138
1155
fn metadata ( & self ) -> Option < StepMetadata > {
@@ -1441,30 +1458,30 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
1441
1458
}
1442
1459
}
1443
1460
1444
- /// `RustcLink` copies all of the rlibs from the rustc build into the previous stage's sysroot.
1461
+ /// `RustcLink` copies compiler rlibs from a rustc build into the sysroot of the compiler that built
1462
+ /// them.
1445
1463
/// This is necessary for tools using `rustc_private`, where the previous compiler will build
1446
1464
/// a tool against the next compiler.
1447
1465
/// To build a tool against a compiler, the rlibs of that compiler that it links against
1448
1466
/// must be in the sysroot of the compiler that's doing the compiling.
1449
1467
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1450
1468
struct RustcLink {
1451
- /// The compiler whose rlibs we are copying around.
1452
- pub compiler : Compiler ,
1453
1469
/// This is the compiler into whose sysroot we want to copy the rlibs into.
1454
- pub previous_stage_compiler : Compiler ,
1455
- pub target : TargetSelection ,
1470
+ /// This compiler **built** some rustc, whose rlibs we will copy into the sysroot.
1471
+ /// Note that we do not explicitly work with the built compiler in this stage at all.
1472
+ /// We just access the build stamp of *some* rustc built by `build_compiler` for the given
1473
+ /// `target`, and copy all the rlibs into the build compiler's sysroot.
1474
+ build_compiler : Compiler ,
1475
+ target : TargetSelection ,
1456
1476
/// Not actually used; only present to make sure the cache invalidation is correct.
1457
1477
crates : Vec < String > ,
1458
1478
}
1459
1479
1460
1480
impl RustcLink {
1461
- fn from_rustc ( rustc : Rustc , host_compiler : Compiler ) -> Self {
1462
- Self {
1463
- compiler : host_compiler,
1464
- previous_stage_compiler : rustc. build_compiler ,
1465
- target : rustc. target ,
1466
- crates : rustc. crates ,
1467
- }
1481
+ /// Copy rlibs from the build compiler that build this `rustc` into the sysroot of that
1482
+ /// build compiler.
1483
+ fn from_rustc ( rustc : Rustc ) -> Self {
1484
+ Self { build_compiler : rustc. build_compiler , target : rustc. target , crates : rustc. crates }
1468
1485
}
1469
1486
}
1470
1487
@@ -1477,14 +1494,13 @@ impl Step for RustcLink {
1477
1494
1478
1495
/// Same as `std_link`, only for librustc
1479
1496
fn run ( self , builder : & Builder < ' _ > ) {
1480
- let compiler = self . compiler ;
1481
- let previous_stage_compiler = self . previous_stage_compiler ;
1497
+ let build_compiler = self . build_compiler ;
1482
1498
let target = self . target ;
1483
1499
add_to_sysroot (
1484
1500
builder,
1485
- & builder. sysroot_target_libdir ( previous_stage_compiler , target) ,
1486
- & builder. sysroot_target_libdir ( previous_stage_compiler , compiler . host ) ,
1487
- & build_stamp:: librustc_stamp ( builder, compiler , target) ,
1501
+ & builder. sysroot_target_libdir ( build_compiler , target) ,
1502
+ & builder. sysroot_target_libdir ( build_compiler , build_compiler . host ) ,
1503
+ & build_stamp:: librustc_stamp ( builder, build_compiler , target) ,
1488
1504
) ;
1489
1505
}
1490
1506
}
@@ -2099,7 +2115,10 @@ impl Step for Assemble {
2099
2115
"target_compiler.host" = ?target_compiler. host,
2100
2116
"building compiler libraries to link to"
2101
2117
) ;
2102
- builder. ensure ( Rustc :: new ( build_compiler, target_compiler. host ) ) ;
2118
+
2119
+ // It is possible that an uplift has happened, so we override build_compiler here.
2120
+ let BuiltRustc { build_compiler } =
2121
+ builder. ensure ( Rustc :: new ( build_compiler, target_compiler. host ) ) ;
2103
2122
2104
2123
let stage = target_compiler. stage ;
2105
2124
let host = target_compiler. host ;
0 commit comments