@@ -161,12 +161,8 @@ pub struct Rustc {
161161}
162162
163163impl Rustc {
164- pub fn new ( builder : & Builder < ' _ > , build_compiler : Compiler , target : TargetSelection ) -> Self {
165- let crates = builder
166- . in_tree_crates ( "rustc-main" , Some ( target) )
167- . into_iter ( )
168- . map ( |krate| krate. name . to_string ( ) )
169- . collect ( ) ;
164+ pub fn new ( builder : & Builder < ' _ > , target : TargetSelection , crates : Vec < String > ) -> Self {
165+ let build_compiler = prepare_compiler_for_check ( builder, target, Mode :: Rustc ) ;
170166 Self { build_compiler, target, crates }
171167 }
172168}
@@ -182,11 +178,7 @@ impl Step for Rustc {
182178
183179 fn make_run ( run : RunConfig < ' _ > ) {
184180 let crates = run. make_run_crates ( Alias :: Compiler ) ;
185- run. builder . ensure ( Rustc {
186- target : run. target ,
187- build_compiler : prepare_compiler_for_check ( run. builder , run. target , Mode :: Rustc ) ,
188- crates,
189- } ) ;
181+ run. builder . ensure ( Rustc :: new ( run. builder , run. target , crates) ) ;
190182 }
191183
192184 /// Check the compiler.
@@ -200,15 +192,6 @@ impl Step for Rustc {
200192 let build_compiler = self . build_compiler ;
201193 let target = self . target ;
202194
203- // Build host std for compiling build scripts
204- builder. std ( build_compiler, build_compiler. host ) ;
205-
206- // Build target std so that the checked rustc can link to it during the check
207- // FIXME: maybe we can a way to only do a check of std here?
208- // But for that we would have to copy the stdlib rmetas to the sysroot of the build
209- // compiler, which conflicts with std rlibs, if we also build std.
210- builder. std ( build_compiler, target) ;
211-
212195 let mut cargo = builder:: Cargo :: new (
213196 builder,
214197 build_compiler,
@@ -280,11 +263,13 @@ fn prepare_compiler_for_check(
280263 build_compiler
281264 }
282265 Mode :: ToolRustc | Mode :: Codegen => {
283- // FIXME: this is a hack, see description of Mode::Rustc below
284- let stage = if host == target { builder. top_stage - 1 } else { builder. top_stage } ;
285- // When checking tool stage N, we check it with compiler stage N-1
286- let build_compiler = builder. compiler ( stage, host) ;
287- builder. ensure ( Rustc :: new ( builder, build_compiler, target) ) ;
266+ // Check Rustc to produce the required rmeta artifacts for rustc_private, and then
267+ // return the build compiler that was used to check rustc.
268+ // We do not need to check examples/tests/etc. of Rustc for rustc_private, so we pass
269+ // an empty set of crates, which will avoid using `cargo -p`.
270+ let check = Rustc :: new ( builder, target, vec ! [ ] ) ;
271+ let build_compiler = check. build_compiler ;
272+ builder. ensure ( check) ;
288273 build_compiler
289274 }
290275 Mode :: Rustc => {
@@ -296,7 +281,18 @@ fn prepare_compiler_for_check(
296281 // FIXME: remove this and either fix cross-compilation check on stage 2 (which has a
297282 // myriad of other problems) or disable cross-checking on stage 1.
298283 let stage = if host == target { builder. top_stage - 1 } else { builder. top_stage } ;
299- builder. compiler ( stage, host)
284+ let build_compiler = builder. compiler ( stage, host) ;
285+
286+ // Build host std for compiling build scripts
287+ builder. std ( build_compiler, build_compiler. host ) ;
288+
289+ // Build target std so that the checked rustc can link to it during the check
290+ // FIXME: maybe we can a way to only do a check of std here?
291+ // But for that we would have to copy the stdlib rmetas to the sysroot of the build
292+ // compiler, which conflicts with std rlibs, if we also build std.
293+ builder. std ( build_compiler, target) ;
294+
295+ build_compiler
300296 }
301297 Mode :: Std => {
302298 // When checking std stage N, we want to do it with the stage N compiler
0 commit comments