@@ -35,6 +35,7 @@ use crate::utils::helpers::{
35
35
} ;
36
36
use crate :: { CLang , Compiler , DependencyType , FileType , GitRepo , LLVM_TOOLS , Mode , debug, trace} ;
37
37
38
+ /// Build a standard library for the given `target` using the given `compiler`.
38
39
#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
39
40
pub struct Std {
40
41
pub target : TargetSelection ,
@@ -960,11 +961,18 @@ fn cp_rustc_component_to_ci_sysroot(builder: &Builder<'_>, sysroot: &Path, conte
960
961
}
961
962
}
962
963
964
+ /// Build rustc using the passed `build_compiler`.
965
+ ///
966
+ /// - Makes sure that `build_compiler` has a standard library prepared for its host target,
967
+ /// so that it can compile build scripts and proc macros when building this `rustc`.
968
+ /// - Makes sure that `build_compiler` has a standard library prepared for `target`,
969
+ /// so that the built `rustc` can *link to it* and use it at runtime.
963
970
#[ derive( Debug , PartialOrd , Ord , Clone , PartialEq , Eq , Hash ) ]
964
971
pub struct Rustc {
972
+ /// The target on which rustc will run (its host).
965
973
pub target : TargetSelection ,
966
- /// The **previous** compiler used to compile this compiler .
967
- pub compiler : Compiler ,
974
+ /// The **previous** compiler used to compile this rustc .
975
+ pub build_compiler : Compiler ,
968
976
/// Whether to build a subset of crates, rather than the whole compiler.
969
977
///
970
978
/// This should only be requested by the user, not used within bootstrap itself.
@@ -974,8 +982,8 @@ pub struct Rustc {
974
982
}
975
983
976
984
impl Rustc {
977
- pub fn new ( compiler : Compiler , target : TargetSelection ) -> Self {
978
- Self { target, compiler , crates : Default :: default ( ) }
985
+ pub fn new ( build_compiler : Compiler , target : TargetSelection ) -> Self {
986
+ Self { target, build_compiler , crates : Default :: default ( ) }
979
987
}
980
988
}
981
989
@@ -1007,7 +1015,7 @@ impl Step for Rustc {
1007
1015
fn make_run ( run : RunConfig < ' _ > ) {
1008
1016
let crates = run. cargo_crates_in_set ( ) ;
1009
1017
run. builder . ensure ( Rustc {
1010
- compiler : run
1018
+ build_compiler : run
1011
1019
. builder
1012
1020
. compiler ( run. builder . top_stage . saturating_sub ( 1 ) , run. build_triple ( ) ) ,
1013
1021
target : run. target ,
@@ -1018,62 +1026,66 @@ impl Step for Rustc {
1018
1026
/// Builds the compiler.
1019
1027
///
1020
1028
/// This will build the compiler for a particular stage of the build using
1021
- /// the `compiler ` targeting the `target` architecture. The artifacts
1029
+ /// the `build_compiler ` targeting the `target` architecture. The artifacts
1022
1030
/// created will also be linked into the sysroot directory.
1023
1031
#[ cfg_attr(
1024
1032
feature = "tracing" ,
1025
1033
instrument(
1026
1034
level = "debug" ,
1027
1035
name = "Rustc::run" ,
1028
1036
skip_all,
1029
- fields( previous_compiler = ?self . compiler , target = ?self . target) ,
1037
+ fields( previous_compiler = ?self . build_compiler , target = ?self . target) ,
1030
1038
) ,
1031
1039
) ]
1032
1040
fn run ( self , builder : & Builder < ' _ > ) -> u32 {
1033
- let compiler = self . compiler ;
1041
+ let build_compiler = self . build_compiler ;
1034
1042
let target = self . target ;
1035
1043
1036
1044
// NOTE: the ABI of the stage0 compiler is different from the ABI of the downloaded compiler,
1037
1045
// so its artifacts can't be reused.
1038
- if builder. download_rustc ( ) && compiler . stage != 0 {
1039
- trace ! ( stage = compiler . stage, "`download_rustc` requested" ) ;
1046
+ if builder. download_rustc ( ) && build_compiler . stage != 0 {
1047
+ trace ! ( stage = build_compiler . stage, "`download_rustc` requested" ) ;
1040
1048
1041
- let sysroot = builder. ensure ( Sysroot { compiler, force_recompile : false } ) ;
1049
+ let sysroot =
1050
+ builder. ensure ( Sysroot { compiler : build_compiler, force_recompile : false } ) ;
1042
1051
cp_rustc_component_to_ci_sysroot (
1043
1052
builder,
1044
1053
& sysroot,
1045
1054
builder. config . ci_rustc_dev_contents ( ) ,
1046
1055
) ;
1047
- return compiler . stage ;
1056
+ return build_compiler . stage ;
1048
1057
}
1049
1058
1050
- builder. ensure ( Std :: new ( compiler, target) ) ;
1059
+ // Build a standard library for `target` using the `build_compiler`.
1060
+ // This will be the standard library that the rustc which we build *links to*.
1061
+ builder. ensure ( Std :: new ( build_compiler, target) ) ;
1051
1062
1052
- if builder. config . keep_stage . contains ( & compiler . stage ) {
1053
- trace ! ( stage = compiler . stage, "`keep-stage` requested" ) ;
1063
+ if builder. config . keep_stage . contains ( & build_compiler . stage ) {
1064
+ trace ! ( stage = build_compiler . stage, "`keep-stage` requested" ) ;
1054
1065
1055
1066
builder. info ( "WARNING: Using a potentially old librustc. This may not behave well." ) ;
1056
1067
builder. info ( "WARNING: Use `--keep-stage-std` if you want to rebuild the compiler when it changes" ) ;
1057
- builder. ensure ( RustcLink :: from_rustc ( self , compiler ) ) ;
1068
+ builder. ensure ( RustcLink :: from_rustc ( self , build_compiler ) ) ;
1058
1069
1059
- return compiler . stage ;
1070
+ return build_compiler . stage ;
1060
1071
}
1061
1072
1062
- let compiler_to_use = builder. compiler_for ( compiler. stage , compiler. host , target) ;
1063
- if compiler_to_use != compiler {
1073
+ let compiler_to_use =
1074
+ builder. compiler_for ( build_compiler. stage , build_compiler. host , target) ;
1075
+ if compiler_to_use != build_compiler {
1064
1076
builder. ensure ( Rustc :: new ( compiler_to_use, target) ) ;
1065
1077
let msg = if compiler_to_use. host == target {
1066
1078
format ! (
1067
1079
"Uplifting rustc (stage{} -> stage{})" ,
1068
1080
compiler_to_use. stage,
1069
- compiler . stage + 1
1081
+ build_compiler . stage + 1
1070
1082
)
1071
1083
} else {
1072
1084
format ! (
1073
1085
"Uplifting rustc (stage{}:{} -> stage{}:{})" ,
1074
1086
compiler_to_use. stage,
1075
1087
compiler_to_use. host,
1076
- compiler . stage + 1 ,
1088
+ build_compiler . stage + 1 ,
1077
1089
target
1078
1090
)
1079
1091
} ;
@@ -1082,22 +1094,26 @@ impl Step for Rustc {
1082
1094
return compiler_to_use. stage ;
1083
1095
}
1084
1096
1085
- // Ensure that build scripts and proc macros have a std / libproc_macro to link against.
1097
+ // Build a standard library for the current host target using the `build_compiler`.
1098
+ // This standard library will be used when building `rustc` for compiling
1099
+ // build scripts and proc macros.
1100
+ // If we are not cross-compiling, the Std build above will be the same one as the one we
1101
+ // prepare here.
1086
1102
builder. ensure ( Std :: new (
1087
- builder. compiler ( self . compiler . stage , builder. config . host_target ) ,
1103
+ builder. compiler ( self . build_compiler . stage , builder. config . host_target ) ,
1088
1104
builder. config . host_target ,
1089
1105
) ) ;
1090
1106
1091
1107
let mut cargo = builder:: Cargo :: new (
1092
1108
builder,
1093
- compiler ,
1109
+ build_compiler ,
1094
1110
Mode :: Rustc ,
1095
1111
SourceType :: InTree ,
1096
1112
target,
1097
1113
Kind :: Build ,
1098
1114
) ;
1099
1115
1100
- rustc_cargo ( builder, & mut cargo, target, & compiler , & self . crates ) ;
1116
+ rustc_cargo ( builder, & mut cargo, target, & build_compiler , & self . crates ) ;
1101
1117
1102
1118
// NB: all RUSTFLAGS should be added to `rustc_cargo()` so they will be
1103
1119
// consistently applied by check/doc/test modes too.
@@ -1106,19 +1122,19 @@ impl Step for Rustc {
1106
1122
cargo. arg ( "-p" ) . arg ( krate) ;
1107
1123
}
1108
1124
1109
- if builder. build . config . enable_bolt_settings && compiler . stage == 1 {
1125
+ if builder. build . config . enable_bolt_settings && build_compiler . stage == 1 {
1110
1126
// Relocations are required for BOLT to work.
1111
1127
cargo. env ( "RUSTC_BOLT_LINK_FLAGS" , "1" ) ;
1112
1128
}
1113
1129
1114
1130
let _guard = builder. msg_sysroot_tool (
1115
1131
Kind :: Build ,
1116
- compiler . stage ,
1132
+ build_compiler . stage ,
1117
1133
format_args ! ( "compiler artifacts{}" , crate_description( & self . crates) ) ,
1118
- compiler . host ,
1134
+ build_compiler . host ,
1119
1135
target,
1120
1136
) ;
1121
- let stamp = build_stamp:: librustc_stamp ( builder, compiler , target) ;
1137
+ let stamp = build_stamp:: librustc_stamp ( builder, build_compiler , target) ;
1122
1138
run_cargo (
1123
1139
builder,
1124
1140
cargo,
@@ -1150,18 +1166,18 @@ impl Step for Rustc {
1150
1166
1151
1167
builder. ensure ( RustcLink :: from_rustc (
1152
1168
self ,
1153
- builder. compiler ( compiler . stage , builder. config . host_target ) ,
1169
+ builder. compiler ( build_compiler . stage , builder. config . host_target ) ,
1154
1170
) ) ;
1155
1171
1156
- compiler . stage
1172
+ build_compiler . stage
1157
1173
}
1158
1174
}
1159
1175
1160
1176
pub fn rustc_cargo (
1161
1177
builder : & Builder < ' _ > ,
1162
1178
cargo : & mut Cargo ,
1163
1179
target : TargetSelection ,
1164
- compiler : & Compiler ,
1180
+ build_compiler : & Compiler ,
1165
1181
crates : & [ String ] ,
1166
1182
) {
1167
1183
cargo
@@ -1208,7 +1224,7 @@ pub fn rustc_cargo(
1208
1224
cargo. rustflag ( "-Zdefault-visibility=protected" ) ;
1209
1225
}
1210
1226
1211
- if is_lto_stage ( compiler ) {
1227
+ if is_lto_stage ( build_compiler ) {
1212
1228
match builder. config . rust_lto {
1213
1229
RustcLto :: Thin | RustcLto :: Fat => {
1214
1230
// Since using LTO for optimizing dylibs is currently experimental,
@@ -1241,15 +1257,15 @@ pub fn rustc_cargo(
1241
1257
// is already on by default in MSVC optimized builds, which is interpreted as --icf=all:
1242
1258
// https://github.com/llvm/llvm-project/blob/3329cec2f79185bafd678f310fafadba2a8c76d2/lld/COFF/Driver.cpp#L1746
1243
1259
// https://github.com/rust-lang/rust/blob/f22819bcce4abaff7d1246a56eec493418f9f4ee/compiler/rustc_codegen_ssa/src/back/linker.rs#L827
1244
- if builder. config . lld_mode . is_used ( ) && !compiler . host . is_msvc ( ) {
1260
+ if builder. config . lld_mode . is_used ( ) && !build_compiler . host . is_msvc ( ) {
1245
1261
cargo. rustflag ( "-Clink-args=-Wl,--icf=all" ) ;
1246
1262
}
1247
1263
1248
1264
if builder. config . rust_profile_use . is_some ( ) && builder. config . rust_profile_generate . is_some ( ) {
1249
1265
panic ! ( "Cannot use and generate PGO profiles at the same time" ) ;
1250
1266
}
1251
1267
let is_collecting = if let Some ( path) = & builder. config . rust_profile_generate {
1252
- if compiler . stage == 1 {
1268
+ if build_compiler . stage == 1 {
1253
1269
cargo. rustflag ( & format ! ( "-Cprofile-generate={path}" ) ) ;
1254
1270
// Apparently necessary to avoid overflowing the counters during
1255
1271
// a Cargo build profile
@@ -1259,7 +1275,7 @@ pub fn rustc_cargo(
1259
1275
false
1260
1276
}
1261
1277
} else if let Some ( path) = & builder. config . rust_profile_use {
1262
- if compiler . stage == 1 {
1278
+ if build_compiler . stage == 1 {
1263
1279
cargo. rustflag ( & format ! ( "-Cprofile-use={path}" ) ) ;
1264
1280
if builder. is_verbose ( ) {
1265
1281
cargo. rustflag ( "-Cllvm-args=-pgo-warn-missing-function" ) ;
@@ -1284,20 +1300,20 @@ pub fn rustc_cargo(
1284
1300
// useful.
1285
1301
// This is only performed for non-incremental builds, as ccache cannot deal with these.
1286
1302
if let Some ( ref ccache) = builder. config . ccache
1287
- && compiler . stage == 0
1303
+ && build_compiler . stage == 0
1288
1304
&& !builder. config . incremental
1289
1305
{
1290
1306
cargo. env ( "RUSTC_WRAPPER" , ccache) ;
1291
1307
}
1292
1308
1293
- rustc_cargo_env ( builder, cargo, target, compiler . stage ) ;
1309
+ rustc_cargo_env ( builder, cargo, target, build_compiler . stage ) ;
1294
1310
}
1295
1311
1296
1312
pub fn rustc_cargo_env (
1297
1313
builder : & Builder < ' _ > ,
1298
1314
cargo : & mut Cargo ,
1299
1315
target : TargetSelection ,
1300
- stage : u32 ,
1316
+ build_stage : u32 ,
1301
1317
) {
1302
1318
// Set some configuration variables picked up by build scripts and
1303
1319
// the compiler alike
@@ -1364,7 +1380,7 @@ pub fn rustc_cargo_env(
1364
1380
crate :: core:: build_steps:: llvm:: prebuilt_llvm_config ( builder, target, false )
1365
1381
. should_build ( ) ;
1366
1382
// `top_stage == stage` might be false for `check --stage 1`, if we are building the stage 1 compiler
1367
- let can_skip_build = builder. kind == Kind :: Check && builder. top_stage == stage ;
1383
+ let can_skip_build = builder. kind == Kind :: Check && builder. top_stage == build_stage ;
1368
1384
let should_skip_build = building_is_expensive && can_skip_build;
1369
1385
if !should_skip_build {
1370
1386
rustc_llvm_env ( builder, cargo, target)
@@ -1475,7 +1491,7 @@ impl RustcLink {
1475
1491
fn from_rustc ( rustc : Rustc , host_compiler : Compiler ) -> Self {
1476
1492
Self {
1477
1493
compiler : host_compiler,
1478
- previous_stage_compiler : rustc. compiler ,
1494
+ previous_stage_compiler : rustc. build_compiler ,
1479
1495
target : rustc. target ,
1480
1496
crates : rustc. crates ,
1481
1497
}
0 commit comments