@@ -35,6 +35,7 @@ use crate::utils::helpers::{
3535} ;
3636use crate :: { CLang , Compiler , DependencyType , FileType , GitRepo , LLVM_TOOLS , Mode , debug, trace} ;
3737
38+ /// Build a standard library for the given `target` using the given `compiler`.
3839#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
3940pub struct Std {
4041 pub target : TargetSelection ,
@@ -960,11 +961,18 @@ fn cp_rustc_component_to_ci_sysroot(builder: &Builder<'_>, sysroot: &Path, conte
960961 }
961962}
962963
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.
963970#[ derive( Debug , PartialOrd , Ord , Clone , PartialEq , Eq , Hash ) ]
964971pub struct Rustc {
972+ /// The target on which rustc will run (its host).
965973 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 ,
968976 /// Whether to build a subset of crates, rather than the whole compiler.
969977 ///
970978 /// This should only be requested by the user, not used within bootstrap itself.
@@ -974,8 +982,8 @@ pub struct Rustc {
974982}
975983
976984impl 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 ( ) }
979987 }
980988}
981989
@@ -1007,7 +1015,7 @@ impl Step for Rustc {
10071015 fn make_run ( run : RunConfig < ' _ > ) {
10081016 let crates = run. cargo_crates_in_set ( ) ;
10091017 run. builder . ensure ( Rustc {
1010- compiler : run
1018+ build_compiler : run
10111019 . builder
10121020 . compiler ( run. builder . top_stage . saturating_sub ( 1 ) , run. build_triple ( ) ) ,
10131021 target : run. target ,
@@ -1018,62 +1026,66 @@ impl Step for Rustc {
10181026 /// Builds the compiler.
10191027 ///
10201028 /// 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
10221030 /// created will also be linked into the sysroot directory.
10231031 #[ cfg_attr(
10241032 feature = "tracing" ,
10251033 instrument(
10261034 level = "debug" ,
10271035 name = "Rustc::run" ,
10281036 skip_all,
1029- fields( previous_compiler = ?self . compiler , target = ?self . target) ,
1037+ fields( previous_compiler = ?self . build_compiler , target = ?self . target) ,
10301038 ) ,
10311039 ) ]
10321040 fn run ( self , builder : & Builder < ' _ > ) -> u32 {
1033- let compiler = self . compiler ;
1041+ let build_compiler = self . build_compiler ;
10341042 let target = self . target ;
10351043
10361044 // NOTE: the ABI of the stage0 compiler is different from the ABI of the downloaded compiler,
10371045 // 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" ) ;
10401048
1041- let sysroot = builder. ensure ( Sysroot { compiler, force_recompile : false } ) ;
1049+ let sysroot =
1050+ builder. ensure ( Sysroot { compiler : build_compiler, force_recompile : false } ) ;
10421051 cp_rustc_component_to_ci_sysroot (
10431052 builder,
10441053 & sysroot,
10451054 builder. config . ci_rustc_dev_contents ( ) ,
10461055 ) ;
1047- return compiler . stage ;
1056+ return build_compiler . stage ;
10481057 }
10491058
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) ) ;
10511062
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" ) ;
10541065
10551066 builder. info ( "WARNING: Using a potentially old librustc. This may not behave well." ) ;
10561067 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 ) ) ;
10581069
1059- return compiler . stage ;
1070+ return build_compiler . stage ;
10601071 }
10611072
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 {
10641076 builder. ensure ( Rustc :: new ( compiler_to_use, target) ) ;
10651077 let msg = if compiler_to_use. host == target {
10661078 format ! (
10671079 "Uplifting rustc (stage{} -> stage{})" ,
10681080 compiler_to_use. stage,
1069- compiler . stage + 1
1081+ build_compiler . stage + 1
10701082 )
10711083 } else {
10721084 format ! (
10731085 "Uplifting rustc (stage{}:{} -> stage{}:{})" ,
10741086 compiler_to_use. stage,
10751087 compiler_to_use. host,
1076- compiler . stage + 1 ,
1088+ build_compiler . stage + 1 ,
10771089 target
10781090 )
10791091 } ;
@@ -1082,22 +1094,26 @@ impl Step for Rustc {
10821094 return compiler_to_use. stage ;
10831095 }
10841096
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.
10861102 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 ) ,
10881104 builder. config . host_target ,
10891105 ) ) ;
10901106
10911107 let mut cargo = builder:: Cargo :: new (
10921108 builder,
1093- compiler ,
1109+ build_compiler ,
10941110 Mode :: Rustc ,
10951111 SourceType :: InTree ,
10961112 target,
10971113 Kind :: Build ,
10981114 ) ;
10991115
1100- rustc_cargo ( builder, & mut cargo, target, & compiler , & self . crates ) ;
1116+ rustc_cargo ( builder, & mut cargo, target, & build_compiler , & self . crates ) ;
11011117
11021118 // NB: all RUSTFLAGS should be added to `rustc_cargo()` so they will be
11031119 // consistently applied by check/doc/test modes too.
@@ -1106,19 +1122,19 @@ impl Step for Rustc {
11061122 cargo. arg ( "-p" ) . arg ( krate) ;
11071123 }
11081124
1109- if builder. build . config . enable_bolt_settings && compiler . stage == 1 {
1125+ if builder. build . config . enable_bolt_settings && build_compiler . stage == 1 {
11101126 // Relocations are required for BOLT to work.
11111127 cargo. env ( "RUSTC_BOLT_LINK_FLAGS" , "1" ) ;
11121128 }
11131129
11141130 let _guard = builder. msg_sysroot_tool (
11151131 Kind :: Build ,
1116- compiler . stage ,
1132+ build_compiler . stage ,
11171133 format_args ! ( "compiler artifacts{}" , crate_description( & self . crates) ) ,
1118- compiler . host ,
1134+ build_compiler . host ,
11191135 target,
11201136 ) ;
1121- let stamp = build_stamp:: librustc_stamp ( builder, compiler , target) ;
1137+ let stamp = build_stamp:: librustc_stamp ( builder, build_compiler , target) ;
11221138 run_cargo (
11231139 builder,
11241140 cargo,
@@ -1150,18 +1166,18 @@ impl Step for Rustc {
11501166
11511167 builder. ensure ( RustcLink :: from_rustc (
11521168 self ,
1153- builder. compiler ( compiler . stage , builder. config . host_target ) ,
1169+ builder. compiler ( build_compiler . stage , builder. config . host_target ) ,
11541170 ) ) ;
11551171
1156- compiler . stage
1172+ build_compiler . stage
11571173 }
11581174}
11591175
11601176pub fn rustc_cargo (
11611177 builder : & Builder < ' _ > ,
11621178 cargo : & mut Cargo ,
11631179 target : TargetSelection ,
1164- compiler : & Compiler ,
1180+ build_compiler : & Compiler ,
11651181 crates : & [ String ] ,
11661182) {
11671183 cargo
@@ -1208,7 +1224,7 @@ pub fn rustc_cargo(
12081224 cargo. rustflag ( "-Zdefault-visibility=protected" ) ;
12091225 }
12101226
1211- if is_lto_stage ( compiler ) {
1227+ if is_lto_stage ( build_compiler ) {
12121228 match builder. config . rust_lto {
12131229 RustcLto :: Thin | RustcLto :: Fat => {
12141230 // Since using LTO for optimizing dylibs is currently experimental,
@@ -1241,15 +1257,15 @@ pub fn rustc_cargo(
12411257 // is already on by default in MSVC optimized builds, which is interpreted as --icf=all:
12421258 // https://github.com/llvm/llvm-project/blob/3329cec2f79185bafd678f310fafadba2a8c76d2/lld/COFF/Driver.cpp#L1746
12431259 // 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 ( ) {
12451261 cargo. rustflag ( "-Clink-args=-Wl,--icf=all" ) ;
12461262 }
12471263
12481264 if builder. config . rust_profile_use . is_some ( ) && builder. config . rust_profile_generate . is_some ( ) {
12491265 panic ! ( "Cannot use and generate PGO profiles at the same time" ) ;
12501266 }
12511267 let is_collecting = if let Some ( path) = & builder. config . rust_profile_generate {
1252- if compiler . stage == 1 {
1268+ if build_compiler . stage == 1 {
12531269 cargo. rustflag ( & format ! ( "-Cprofile-generate={path}" ) ) ;
12541270 // Apparently necessary to avoid overflowing the counters during
12551271 // a Cargo build profile
@@ -1259,7 +1275,7 @@ pub fn rustc_cargo(
12591275 false
12601276 }
12611277 } else if let Some ( path) = & builder. config . rust_profile_use {
1262- if compiler . stage == 1 {
1278+ if build_compiler . stage == 1 {
12631279 cargo. rustflag ( & format ! ( "-Cprofile-use={path}" ) ) ;
12641280 if builder. is_verbose ( ) {
12651281 cargo. rustflag ( "-Cllvm-args=-pgo-warn-missing-function" ) ;
@@ -1284,20 +1300,20 @@ pub fn rustc_cargo(
12841300 // useful.
12851301 // This is only performed for non-incremental builds, as ccache cannot deal with these.
12861302 if let Some ( ref ccache) = builder. config . ccache
1287- && compiler . stage == 0
1303+ && build_compiler . stage == 0
12881304 && !builder. config . incremental
12891305 {
12901306 cargo. env ( "RUSTC_WRAPPER" , ccache) ;
12911307 }
12921308
1293- rustc_cargo_env ( builder, cargo, target, compiler . stage ) ;
1309+ rustc_cargo_env ( builder, cargo, target, build_compiler . stage ) ;
12941310}
12951311
12961312pub fn rustc_cargo_env (
12971313 builder : & Builder < ' _ > ,
12981314 cargo : & mut Cargo ,
12991315 target : TargetSelection ,
1300- stage : u32 ,
1316+ build_stage : u32 ,
13011317) {
13021318 // Set some configuration variables picked up by build scripts and
13031319 // the compiler alike
@@ -1364,7 +1380,7 @@ pub fn rustc_cargo_env(
13641380 crate :: core:: build_steps:: llvm:: prebuilt_llvm_config ( builder, target, false )
13651381 . should_build ( ) ;
13661382 // `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 ;
13681384 let should_skip_build = building_is_expensive && can_skip_build;
13691385 if !should_skip_build {
13701386 rustc_llvm_env ( builder, cargo, target)
@@ -1475,7 +1491,7 @@ impl RustcLink {
14751491 fn from_rustc ( rustc : Rustc , host_compiler : Compiler ) -> Self {
14761492 Self {
14771493 compiler : host_compiler,
1478- previous_stage_compiler : rustc. compiler ,
1494+ previous_stage_compiler : rustc. build_compiler ,
14791495 target : rustc. target ,
14801496 crates : rustc. crates ,
14811497 }
0 commit comments