@@ -73,7 +73,7 @@ impl Step for Std {
7373
7474 fn run ( self , builder : & Builder < ' _ > ) {
7575 let target = self . target ;
76- let compiler = builder. compiler ( 0 , builder. config . build ) ;
76+ let compiler = builder. compiler ( builder . top_stage , builder. config . build ) ;
7777
7878 let mut cargo = builder. cargo (
7979 compiler,
@@ -84,7 +84,10 @@ impl Step for Std {
8484 ) ;
8585 std_cargo ( builder, target, compiler. stage , & mut cargo) ;
8686
87- builder. info ( & format ! ( "Checking std artifacts ({} -> {})" , & compiler. host, target) ) ;
87+ builder. info ( & format ! (
88+ "Checking stage{} std artifacts ({} -> {})" ,
89+ builder. top_stage, & compiler. host, target
90+ ) ) ;
8891 run_cargo (
8992 builder,
9093 cargo,
@@ -94,9 +97,13 @@ impl Step for Std {
9497 true ,
9598 ) ;
9699
97- let libdir = builder. sysroot_libdir ( compiler, target) ;
98- let hostdir = builder. sysroot_libdir ( compiler, compiler. host ) ;
99- add_to_sysroot ( & builder, & libdir, & hostdir, & libstd_stamp ( builder, compiler, target) ) ;
100+ // We skip populating the sysroot in non-zero stage because that'll lead
101+ // to rlib/rmeta conflicts if std gets built during this session.
102+ if compiler. stage == 0 {
103+ let libdir = builder. sysroot_libdir ( compiler, target) ;
104+ let hostdir = builder. sysroot_libdir ( compiler, compiler. host ) ;
105+ add_to_sysroot ( & builder, & libdir, & hostdir, & libstd_stamp ( builder, compiler, target) ) ;
106+ }
100107
101108 // Then run cargo again, once we've put the rmeta files for the library
102109 // crates into the sysroot. This is needed because e.g., core's tests
@@ -124,8 +131,8 @@ impl Step for Std {
124131 }
125132
126133 builder. info ( & format ! (
127- "Checking std test/bench/example targets ({} -> {})" ,
128- & compiler. host, target
134+ "Checking stage{} std test/bench/example targets ({} -> {})" ,
135+ builder . top_stage , & compiler. host, target
129136 ) ) ;
130137 run_cargo (
131138 builder,
@@ -163,10 +170,20 @@ impl Step for Rustc {
163170 /// the `compiler` targeting the `target` architecture. The artifacts
164171 /// created will also be linked into the sysroot directory.
165172 fn run ( self , builder : & Builder < ' _ > ) {
166- let compiler = builder. compiler ( 0 , builder. config . build ) ;
173+ let compiler = builder. compiler ( builder . top_stage , builder. config . build ) ;
167174 let target = self . target ;
168175
169- builder. ensure ( Std { target } ) ;
176+ if compiler. stage != 0 {
177+ // If we're not in stage 0, then we won't have a std from the beta
178+ // compiler around. That means we need to make sure there's one in
179+ // the sysroot for the compiler to find. Otherwise, we're going to
180+ // fail when building crates that need to generate code (e.g., build
181+ // scripts and their dependencies).
182+ builder. ensure ( crate :: compile:: Std { target : compiler. host , compiler } ) ;
183+ builder. ensure ( crate :: compile:: Std { target, compiler } ) ;
184+ } else {
185+ builder. ensure ( Std { target } ) ;
186+ }
170187
171188 let mut cargo = builder. cargo (
172189 compiler,
@@ -187,7 +204,10 @@ impl Step for Rustc {
187204 cargo. arg ( "-p" ) . arg ( krate. name ) ;
188205 }
189206
190- builder. info ( & format ! ( "Checking compiler artifacts ({} -> {})" , & compiler. host, target) ) ;
207+ builder. info ( & format ! (
208+ "Checking stage{} compiler artifacts ({} -> {})" ,
209+ builder. top_stage, & compiler. host, target
210+ ) ) ;
191211 run_cargo (
192212 builder,
193213 cargo,
@@ -225,7 +245,7 @@ impl Step for CodegenBackend {
225245 }
226246
227247 fn run ( self , builder : & Builder < ' _ > ) {
228- let compiler = builder. compiler ( 0 , builder. config . build ) ;
248+ let compiler = builder. compiler ( builder . top_stage , builder. config . build ) ;
229249 let target = self . target ;
230250 let backend = self . backend ;
231251
@@ -244,8 +264,8 @@ impl Step for CodegenBackend {
244264 rustc_cargo_env ( builder, & mut cargo, target) ;
245265
246266 builder. info ( & format ! (
247- "Checking {} artifacts ({} -> {})" ,
248- backend, & compiler. host. triple, target. triple
267+ "Checking stage{} {} artifacts ({} -> {})" ,
268+ builder . top_stage , backend, & compiler. host. triple, target. triple
249269 ) ) ;
250270
251271 run_cargo (
@@ -280,7 +300,7 @@ macro_rules! tool_check_step {
280300 }
281301
282302 fn run( self , builder: & Builder <' _>) {
283- let compiler = builder. compiler( 0 , builder. config. build) ;
303+ let compiler = builder. compiler( builder . top_stage , builder. config. build) ;
284304 let target = self . target;
285305
286306 builder. ensure( Rustc { target } ) ;
@@ -301,7 +321,8 @@ macro_rules! tool_check_step {
301321 }
302322
303323 builder. info( & format!(
304- "Checking {} artifacts ({} -> {})" ,
324+ "Checking stage{} {} artifacts ({} -> {})" ,
325+ builder. top_stage,
305326 stringify!( $name) . to_lowercase( ) ,
306327 & compiler. host. triple,
307328 target. triple
0 commit comments