@@ -30,10 +30,6 @@ pub struct Std {
3030
3131impl Std {
3232 const CRATE_OR_DEPS : & [ & str ] = & [ "sysroot" , "coretests" , "alloctests" ] ;
33-
34- pub fn new ( build_compiler : Compiler , target : TargetSelection ) -> Self {
35- Self { build_compiler, target, crates : vec ! [ ] }
36- }
3733}
3834
3935impl Step for Std {
@@ -168,12 +164,8 @@ pub struct Rustc {
168164}
169165
170166impl Rustc {
171- pub fn new ( builder : & Builder < ' _ > , build_compiler : Compiler , target : TargetSelection ) -> Self {
172- let crates = builder
173- . in_tree_crates ( "rustc-main" , Some ( target) )
174- . into_iter ( )
175- . map ( |krate| krate. name . to_string ( ) )
176- . collect ( ) ;
167+ pub fn new ( builder : & Builder < ' _ > , target : TargetSelection , crates : Vec < String > ) -> Self {
168+ let build_compiler = prepare_compiler_for_check ( builder, target, Mode :: Rustc ) ;
177169 Self { build_compiler, target, crates }
178170 }
179171}
@@ -189,11 +181,7 @@ impl Step for Rustc {
189181
190182 fn make_run ( run : RunConfig < ' _ > ) {
191183 let crates = run. make_run_crates ( Alias :: Compiler ) ;
192- run. builder . ensure ( Rustc {
193- target : run. target ,
194- build_compiler : prepare_compiler_for_check ( run. builder , run. target , Mode :: Rustc ) ,
195- crates,
196- } ) ;
184+ run. builder . ensure ( Rustc :: new ( run. builder , run. target , crates) ) ;
197185 }
198186
199187 /// Check the compiler.
@@ -207,15 +195,6 @@ impl Step for Rustc {
207195 let build_compiler = self . build_compiler ;
208196 let target = self . target ;
209197
210- // Build host std for compiling build scripts
211- builder. std ( build_compiler, build_compiler. host ) ;
212-
213- // Build target std so that the checked rustc can link to it during the check
214- // FIXME: maybe we can a way to only do a check of std here?
215- // But for that we would have to copy the stdlib rmetas to the sysroot of the build
216- // compiler, which conflicts with std rlibs, if we also build std.
217- builder. std ( build_compiler, target) ;
218-
219198 let mut cargo = builder:: Cargo :: new (
220199 builder,
221200 build_compiler,
@@ -253,12 +232,18 @@ impl Step for Rustc {
253232 }
254233
255234 fn metadata ( & self ) -> Option < StepMetadata > {
256- Some ( StepMetadata :: check ( "rustc" , self . target ) . built_by ( self . build_compiler ) )
235+ let metadata = StepMetadata :: check ( "rustc" , self . target ) . built_by ( self . build_compiler ) ;
236+ let metadata = if self . crates . is_empty ( ) {
237+ metadata
238+ } else {
239+ metadata. with_metadata ( format ! ( "({} crates)" , self . crates. len( ) ) )
240+ } ;
241+ Some ( metadata)
257242 }
258243}
259244
260245/// Prepares a compiler that will check something with the given `mode`.
261- fn prepare_compiler_for_check (
246+ pub fn prepare_compiler_for_check (
262247 builder : & Builder < ' _ > ,
263248 target : TargetSelection ,
264249 mode : Mode ,
@@ -289,11 +274,13 @@ fn prepare_compiler_for_check(
289274 build_compiler
290275 }
291276 Mode :: ToolRustc | Mode :: Codegen => {
292- // FIXME: this is a hack, see description of Mode::Rustc below
293- let stage = if host == target { builder. top_stage - 1 } else { builder. top_stage } ;
294- // When checking tool stage N, we check it with compiler stage N-1
295- let build_compiler = builder. compiler ( stage, host) ;
296- builder. ensure ( Rustc :: new ( builder, build_compiler, target) ) ;
277+ // Check Rustc to produce the required rmeta artifacts for rustc_private, and then
278+ // return the build compiler that was used to check rustc.
279+ // We do not need to check examples/tests/etc. of Rustc for rustc_private, so we pass
280+ // an empty set of crates, which will avoid using `cargo -p`.
281+ let check = Rustc :: new ( builder, target, vec ! [ ] ) ;
282+ let build_compiler = check. build_compiler ;
283+ builder. ensure ( check) ;
297284 build_compiler
298285 }
299286 Mode :: Rustc => {
@@ -305,7 +292,18 @@ fn prepare_compiler_for_check(
305292 // FIXME: remove this and either fix cross-compilation check on stage 2 (which has a
306293 // myriad of other problems) or disable cross-checking on stage 1.
307294 let stage = if host == target { builder. top_stage - 1 } else { builder. top_stage } ;
308- builder. compiler ( stage, host)
295+ let build_compiler = builder. compiler ( stage, host) ;
296+
297+ // Build host std for compiling build scripts
298+ builder. std ( build_compiler, build_compiler. host ) ;
299+
300+ // Build target std so that the checked rustc can link to it during the check
301+ // FIXME: maybe we can a way to only do a check of std here?
302+ // But for that we would have to copy the stdlib rmetas to the sysroot of the build
303+ // compiler, which conflicts with std rlibs, if we also build std.
304+ builder. std ( build_compiler, target) ;
305+
306+ build_compiler
309307 }
310308 Mode :: Std => {
311309 // When checking std stage N, we want to do it with the stage N compiler
0 commit comments