@@ -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,
@@ -94,9 +94,13 @@ impl Step for Std {
9494 true ,
9595 ) ;
9696
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) ) ;
97+ // We skip populating the sysroot in non-zero stage because that'll lead
98+ // to rlib/rmeta conflicts if std gets built during this session.
99+ if compiler. stage == 0 {
100+ let libdir = builder. sysroot_libdir ( compiler, target) ;
101+ let hostdir = builder. sysroot_libdir ( compiler, compiler. host ) ;
102+ add_to_sysroot ( & builder, & libdir, & hostdir, & libstd_stamp ( builder, compiler, target) ) ;
103+ }
100104
101105 // Then run cargo again, once we've put the rmeta files for the library
102106 // crates into the sysroot. This is needed because e.g., core's tests
@@ -163,10 +167,20 @@ impl Step for Rustc {
163167 /// the `compiler` targeting the `target` architecture. The artifacts
164168 /// created will also be linked into the sysroot directory.
165169 fn run ( self , builder : & Builder < ' _ > ) {
166- let compiler = builder. compiler ( 0 , builder. config . build ) ;
170+ let compiler = builder. compiler ( builder . top_stage , builder. config . build ) ;
167171 let target = self . target ;
168172
169- builder. ensure ( Std { target } ) ;
173+ if compiler. stage != 0 {
174+ // If we're not in stage 0, then we won't have a std from the beta
175+ // compiler around. That means we need to make sure there's one in
176+ // the sysroot for the compiler to find. Otherwise, we're going to
177+ // fail when building crates that need to generate code (e.g., build
178+ // scripts and their dependencies).
179+ builder. ensure ( crate :: compile:: Std { target : compiler. host , compiler } ) ;
180+ builder. ensure ( crate :: compile:: Std { target, compiler } ) ;
181+ } else {
182+ builder. ensure ( Std { target } ) ;
183+ }
170184
171185 let mut cargo = builder. cargo (
172186 compiler,
@@ -225,7 +239,7 @@ impl Step for CodegenBackend {
225239 }
226240
227241 fn run ( self , builder : & Builder < ' _ > ) {
228- let compiler = builder. compiler ( 0 , builder. config . build ) ;
242+ let compiler = builder. compiler ( builder . top_stage , builder. config . build ) ;
229243 let target = self . target ;
230244 let backend = self . backend ;
231245
@@ -280,7 +294,7 @@ macro_rules! tool_check_step {
280294 }
281295
282296 fn run( self , builder: & Builder <' _>) {
283- let compiler = builder. compiler( 0 , builder. config. build) ;
297+ let compiler = builder. compiler( builder . top_stage , builder. config. build) ;
284298 let target = self . target;
285299
286300 builder. ensure( Rustc { target } ) ;
0 commit comments