@@ -231,7 +231,7 @@ impl Step for Std {
231231 . join ( "bin" ) ;
232232 if src_sysroot_bin. exists ( ) {
233233 let target_sysroot_bin =
234- builder. sysroot_libdir ( compiler, target) . parent ( ) . unwrap ( ) . join ( "bin" ) ;
234+ builder. sysroot_target_libdir ( compiler, target) . parent ( ) . unwrap ( ) . join ( "bin" ) ;
235235 t ! ( fs:: create_dir_all( & target_sysroot_bin) ) ;
236236 builder. cp_link_r ( & src_sysroot_bin, & target_sysroot_bin) ;
237237 }
@@ -345,7 +345,7 @@ fn copy_third_party_objects(
345345 && ( target. contains ( "linux" ) || target. contains ( "fuchsia" ) )
346346 {
347347 let libunwind_path =
348- copy_llvm_libunwind ( builder, target, & builder. sysroot_libdir ( * compiler, target) ) ;
348+ copy_llvm_libunwind ( builder, target, & builder. sysroot_target_libdir ( * compiler, target) ) ;
349349 target_deps. push ( ( libunwind_path, DependencyType :: Target ) ) ;
350350 }
351351
@@ -358,7 +358,8 @@ fn copy_self_contained_objects(
358358 compiler : & Compiler ,
359359 target : TargetSelection ,
360360) -> Vec < ( PathBuf , DependencyType ) > {
361- let libdir_self_contained = builder. sysroot_libdir ( * compiler, target) . join ( "self-contained" ) ;
361+ let libdir_self_contained =
362+ builder. sysroot_target_libdir ( * compiler, target) . join ( "self-contained" ) ;
362363 t ! ( fs:: create_dir_all( & libdir_self_contained) ) ;
363364 let mut target_deps = vec ! [ ] ;
364365
@@ -612,8 +613,8 @@ impl Step for StdLink {
612613 let hostdir = sysroot. join ( lib) . join ( "rustlib" ) . join ( compiler. host . triple ) . join ( "lib" ) ;
613614 ( libdir, hostdir)
614615 } else {
615- let libdir = builder. sysroot_libdir ( target_compiler, target) ;
616- let hostdir = builder. sysroot_libdir ( target_compiler, compiler. host ) ;
616+ let libdir = builder. sysroot_target_libdir ( target_compiler, target) ;
617+ let hostdir = builder. sysroot_target_libdir ( target_compiler, compiler. host ) ;
617618 ( libdir, hostdir)
618619 } ;
619620
@@ -680,7 +681,7 @@ fn copy_sanitizers(
680681 }
681682
682683 let mut target_deps = Vec :: new ( ) ;
683- let libdir = builder. sysroot_libdir ( * compiler, target) ;
684+ let libdir = builder. sysroot_target_libdir ( * compiler, target) ;
684685
685686 for runtime in & runtimes {
686687 let dst = libdir. join ( & runtime. name ) ;
@@ -766,7 +767,7 @@ impl Step for StartupObjects {
766767
767768 let src_dir = & builder. src . join ( "library" ) . join ( "rtstartup" ) ;
768769 let dst_dir = & builder. native_dir ( target) . join ( "rtstartup" ) ;
769- let sysroot_dir = & builder. sysroot_libdir ( for_compiler, target) ;
770+ let sysroot_dir = & builder. sysroot_target_libdir ( for_compiler, target) ;
770771 t ! ( fs:: create_dir_all( dst_dir) ) ;
771772
772773 for file in & [ "rsbegin" , "rsend" ] {
@@ -1218,10 +1219,17 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
12181219 }
12191220}
12201221
1222+ /// `RustcLink` copies all of the rlibs from the rustc build into the previous stage's sysroot.
1223+ /// This is necessary for tools using `rustc_private`, where the previous compiler will build
1224+ /// a tool against the next compiler.
1225+ /// To build a tool against a compiler, the rlibs of that compiler that it links against
1226+ /// must be in the sysroot of the compiler that's doing the compiling.
12211227#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
12221228struct RustcLink {
1229+ /// The compiler whose rlibs we are copying around.
12231230 pub compiler : Compiler ,
1224- pub target_compiler : Compiler ,
1231+ /// This is the compiler into whose sysroot we want to copy the rlibs into.
1232+ pub previous_stage_compiler : Compiler ,
12251233 pub target : TargetSelection ,
12261234 /// Not actually used; only present to make sure the cache invalidation is correct.
12271235 crates : Vec < String > ,
@@ -1231,7 +1239,7 @@ impl RustcLink {
12311239 fn from_rustc ( rustc : Rustc , host_compiler : Compiler ) -> Self {
12321240 Self {
12331241 compiler : host_compiler,
1234- target_compiler : rustc. compiler ,
1242+ previous_stage_compiler : rustc. compiler ,
12351243 target : rustc. target ,
12361244 crates : rustc. crates ,
12371245 }
@@ -1248,12 +1256,12 @@ impl Step for RustcLink {
12481256 /// Same as `std_link`, only for librustc
12491257 fn run ( self , builder : & Builder < ' _ > ) {
12501258 let compiler = self . compiler ;
1251- let target_compiler = self . target_compiler ;
1259+ let previous_stage_compiler = self . previous_stage_compiler ;
12521260 let target = self . target ;
12531261 add_to_sysroot (
12541262 builder,
1255- & builder. sysroot_libdir ( target_compiler , target) ,
1256- & builder. sysroot_libdir ( target_compiler , compiler. host ) ,
1263+ & builder. sysroot_target_libdir ( previous_stage_compiler , target) ,
1264+ & builder. sysroot_target_libdir ( previous_stage_compiler , compiler. host ) ,
12571265 & librustc_stamp ( builder, compiler, target) ,
12581266 ) ;
12591267 }
@@ -1797,7 +1805,7 @@ impl Step for Assemble {
17971805 let sysroot = builder. sysroot ( target_compiler) ;
17981806 let rustc_libdir = builder. rustc_libdir ( target_compiler) ;
17991807 t ! ( fs:: create_dir_all( & rustc_libdir) ) ;
1800- let src_libdir = builder. sysroot_libdir ( build_compiler, host) ;
1808+ let src_libdir = builder. sysroot_target_libdir ( build_compiler, host) ;
18011809 for f in builder. read_dir ( & src_libdir) {
18021810 let filename = f. file_name ( ) . into_string ( ) . unwrap ( ) ;
18031811 if ( is_dylib ( & filename) || is_debug_info ( & filename) ) && !proc_macros. contains ( & filename)
@@ -1810,7 +1818,7 @@ impl Step for Assemble {
18101818
18111819 // We prepend this bin directory to the user PATH when linking Rust binaries. To
18121820 // avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
1813- let libdir = builder. sysroot_libdir ( target_compiler, target_compiler. host ) ;
1821+ let libdir = builder. sysroot_target_libdir ( target_compiler, target_compiler. host ) ;
18141822 let libdir_bin = libdir. parent ( ) . unwrap ( ) . join ( "bin" ) ;
18151823 t ! ( fs:: create_dir_all( & libdir_bin) ) ;
18161824 if let Some ( lld_install) = lld_install {
0 commit comments