@@ -211,7 +211,7 @@ impl Step for StdLink {
211211 target_compiler. host,
212212 target) ) ;
213213 let libdir = builder. sysroot_libdir ( target_compiler, target) ;
214- add_to_sysroot ( builder, & libdir, & libstd_stamp ( builder, compiler, target) ) ;
214+ add_to_sysroot ( builder, & libdir, & libstd_stamp ( builder, compiler, target) , None ) ;
215215
216216 if builder. config . sanitizers && compiler. stage != 0 && target == "x86_64-apple-darwin" {
217217 // The sanitizers are only built in stage1 or above, so the dylibs will
@@ -414,7 +414,7 @@ impl Step for TestLink {
414414 target_compiler. host,
415415 target) ) ;
416416 add_to_sysroot ( builder, & builder. sysroot_libdir ( target_compiler, target) ,
417- & libtest_stamp ( builder, compiler, target) ) ;
417+ & libtest_stamp ( builder, compiler, target) , None ) ;
418418
419419 builder. cargo ( target_compiler, Mode :: ToolTest , target, "clean" ) ;
420420 }
@@ -574,8 +574,13 @@ impl Step for RustcLink {
574574 & compiler. host,
575575 target_compiler. host,
576576 target) ) ;
577- add_to_sysroot ( builder, & builder. sysroot_libdir ( target_compiler, target) ,
578- & librustc_stamp ( builder, compiler, target) ) ;
577+ let stage_out = builder. build . stage_out ( target_compiler, Mode :: Rustc ) ;
578+ add_to_sysroot (
579+ builder,
580+ & builder. sysroot_libdir ( target_compiler, target) ,
581+ & librustc_stamp ( builder, compiler, target) ,
582+ if compiler. stage == 0 { Some ( & stage_out) } else { None } ,
583+ ) ;
579584 builder. cargo ( target_compiler, Mode :: ToolRustc , target, "clean" ) ;
580585 }
581586}
@@ -982,10 +987,26 @@ impl Step for Assemble {
982987///
983988/// For a particular stage this will link the file listed in `stamp` into the
984989/// `sysroot_dst` provided.
985- pub fn add_to_sysroot ( builder : & Builder , sysroot_dst : & Path , stamp : & Path ) {
990+ pub fn add_to_sysroot (
991+ builder : & Builder ,
992+ sysroot_dst : & Path ,
993+ stamp : & Path ,
994+ stage_out : Option < & Path > ) {
986995 t ! ( fs:: create_dir_all( & sysroot_dst) ) ;
987996 for path in builder. read_stamp_file ( stamp) {
988- builder. copy ( & path, & sysroot_dst. join ( path. file_name ( ) . unwrap ( ) ) ) ;
997+ let file_dir = path. parent ( ) . unwrap ( ) // chop off base name
998+ . parent ( ) . unwrap ( ) // chop off `release`
999+ . parent ( ) . unwrap ( ) ; // chop off `release`
1000+ if stage_out == Some ( file_dir) {
1001+ // We are copying a build file. We need to add the build triple to it
1002+ let rustlib_dir = sysroot_dst. parent ( ) . unwrap ( ) // chop off `lib`
1003+ . parent ( ) . unwrap ( ) ; // chop off `$target`
1004+ let build_dir = rustlib_dir. join ( builder. build . build ) . join ( "lib" ) ;
1005+ t ! ( fs:: create_dir_all( & build_dir) ) ;
1006+ builder. copy ( & path, & build_dir. join ( path. file_name ( ) . unwrap ( ) ) ) ;
1007+ } else {
1008+ builder. copy ( & path, & sysroot_dst. join ( path. file_name ( ) . unwrap ( ) ) ) ;
1009+ }
9891010 }
9901011}
9911012
@@ -1014,8 +1035,12 @@ pub fn run_cargo(builder: &Builder,
10141035 let mut deps = Vec :: new ( ) ;
10151036 let mut toplevel = Vec :: new ( ) ;
10161037 let ok = stream_cargo ( builder, cargo, & mut |msg| {
1017- let filenames = match msg {
1018- CargoMessage :: CompilerArtifact { filenames, .. } => filenames,
1038+ let ( filenames, package_id) = match msg {
1039+ CargoMessage :: CompilerArtifact {
1040+ filenames,
1041+ package_id,
1042+ ..
1043+ } => ( filenames, package_id) ,
10191044 _ => return ,
10201045 } ;
10211046 for filename in filenames {
@@ -1030,8 +1055,12 @@ pub fn run_cargo(builder: &Builder,
10301055 let filename = Path :: new ( & * filename) ;
10311056
10321057 // If this was an output file in the "host dir" we don't actually
1033- // worry about it, it's not relevant for us.
1058+ // worry about it, it's not relevant for us
10341059 if filename. starts_with ( & host_root_dir) {
1060+ // Unless it's a proc macro used in the compiler
1061+ if package_id. starts_with ( "rustc_macros " ) {
1062+ deps. push ( filename. to_path_buf ( ) ) ;
1063+ }
10351064 continue ;
10361065 }
10371066
0 commit comments