@@ -224,7 +224,8 @@ impl Step for StdLink {
224224 target_compiler. host,
225225 target) ) ;
226226 let libdir = builder. sysroot_libdir ( target_compiler, target) ;
227- add_to_sysroot ( builder, & libdir, & libstd_stamp ( builder, compiler, target) ) ;
227+ let hostdir = builder. sysroot_libdir ( target_compiler, compiler. host ) ;
228+ add_to_sysroot ( builder, & libdir, & hostdir, & libstd_stamp ( builder, compiler, target) ) ;
228229
229230 if builder. config . sanitizers && compiler. stage != 0 && target == "x86_64-apple-darwin" {
230231 // The sanitizers are only built in stage1 or above, so the dylibs will
@@ -431,8 +432,12 @@ impl Step for TestLink {
431432 & compiler. host,
432433 target_compiler. host,
433434 target) ) ;
434- add_to_sysroot ( builder, & builder. sysroot_libdir ( target_compiler, target) ,
435- & libtest_stamp ( builder, compiler, target) ) ;
435+ add_to_sysroot (
436+ builder,
437+ & builder. sysroot_libdir ( target_compiler, target) ,
438+ & builder. sysroot_libdir ( target_compiler, compiler. host ) ,
439+ & libtest_stamp ( builder, compiler, target)
440+ ) ;
436441
437442 builder. cargo ( target_compiler, Mode :: ToolTest , target, "clean" ) ;
438443 }
@@ -496,8 +501,8 @@ impl Step for Rustc {
496501 return ;
497502 }
498503
499- // Ensure that build scripts have a std to link against.
500- builder. ensure ( Std {
504+ // Ensure that build scripts and proc macros have a std / libproc_macro to link against.
505+ builder. ensure ( Test {
501506 compiler : builder. compiler ( self . compiler . stage , builder. config . build ) ,
502507 target : builder. config . build ,
503508 } ) ;
@@ -592,8 +597,12 @@ impl Step for RustcLink {
592597 & compiler. host,
593598 target_compiler. host,
594599 target) ) ;
595- add_to_sysroot ( builder, & builder. sysroot_libdir ( target_compiler, target) ,
596- & librustc_stamp ( builder, compiler, target) ) ;
600+ add_to_sysroot (
601+ builder,
602+ & builder. sysroot_libdir ( target_compiler, target) ,
603+ & builder. sysroot_libdir ( target_compiler, compiler. host ) ,
604+ & librustc_stamp ( builder, compiler, target)
605+ ) ;
597606 builder. cargo ( target_compiler, Mode :: ToolRustc , target, "clean" ) ;
598607 }
599608}
@@ -1015,10 +1024,20 @@ impl Step for Assemble {
10151024///
10161025/// For a particular stage this will link the file listed in `stamp` into the
10171026/// `sysroot_dst` provided.
1018- pub fn add_to_sysroot ( builder : & Builder < ' _ > , sysroot_dst : & Path , stamp : & Path ) {
1027+ pub fn add_to_sysroot (
1028+ builder : & Builder < ' _ > ,
1029+ sysroot_dst : & Path ,
1030+ sysroot_host_dst : & Path ,
1031+ stamp : & Path
1032+ ) {
10191033 t ! ( fs:: create_dir_all( & sysroot_dst) ) ;
1020- for path in builder. read_stamp_file ( stamp) {
1021- builder. copy ( & path, & sysroot_dst. join ( path. file_name ( ) . unwrap ( ) ) ) ;
1034+ t ! ( fs:: create_dir_all( & sysroot_host_dst) ) ;
1035+ for ( path, host) in builder. read_stamp_file ( stamp) {
1036+ if host {
1037+ builder. copy ( & path, & sysroot_host_dst. join ( path. file_name ( ) . unwrap ( ) ) ) ;
1038+ } else {
1039+ builder. copy ( & path, & sysroot_dst. join ( path. file_name ( ) . unwrap ( ) ) ) ;
1040+ }
10221041 }
10231042}
10241043
@@ -1047,8 +1066,14 @@ pub fn run_cargo(builder: &Builder<'_>,
10471066 let mut deps = Vec :: new ( ) ;
10481067 let mut toplevel = Vec :: new ( ) ;
10491068 let ok = stream_cargo ( builder, cargo, & mut |msg| {
1050- let filenames = match msg {
1051- CargoMessage :: CompilerArtifact { filenames, .. } => filenames,
1069+ let ( filenames, crate_types) = match msg {
1070+ CargoMessage :: CompilerArtifact {
1071+ filenames,
1072+ target : CargoTarget {
1073+ crate_types,
1074+ } ,
1075+ ..
1076+ } => ( filenames, crate_types) ,
10521077 _ => return ,
10531078 } ;
10541079 for filename in filenames {
@@ -1063,15 +1088,19 @@ pub fn run_cargo(builder: &Builder<'_>,
10631088 let filename = Path :: new ( & * filename) ;
10641089
10651090 // If this was an output file in the "host dir" we don't actually
1066- // worry about it, it's not relevant for us.
1091+ // worry about it, it's not relevant for us
10671092 if filename. starts_with ( & host_root_dir) {
1093+ // Unless it's a proc macro used in the compiler
1094+ if crate_types. iter ( ) . any ( |t| t == "proc-macro" ) {
1095+ deps. push ( ( filename. to_path_buf ( ) , true ) ) ;
1096+ }
10681097 continue ;
10691098 }
10701099
10711100 // If this was output in the `deps` dir then this is a precise file
10721101 // name (hash included) so we start tracking it.
10731102 if filename. starts_with ( & target_deps_dir) {
1074- deps. push ( filename. to_path_buf ( ) ) ;
1103+ deps. push ( ( filename. to_path_buf ( ) , false ) ) ;
10751104 continue ;
10761105 }
10771106
@@ -1124,10 +1153,10 @@ pub fn run_cargo(builder: &Builder<'_>,
11241153 let candidate = format ! ( "{}.lib" , path_to_add) ;
11251154 let candidate = PathBuf :: from ( candidate) ;
11261155 if candidate. exists ( ) {
1127- deps. push ( candidate) ;
1156+ deps. push ( ( candidate, false ) ) ;
11281157 }
11291158 }
1130- deps. push ( path_to_add. into ( ) ) ;
1159+ deps. push ( ( path_to_add. into ( ) , false ) ) ;
11311160 }
11321161
11331162 // Now we want to update the contents of the stamp file, if necessary. First
@@ -1140,12 +1169,13 @@ pub fn run_cargo(builder: &Builder<'_>,
11401169 let mut new_contents = Vec :: new ( ) ;
11411170 let mut max = None ;
11421171 let mut max_path = None ;
1143- for dep in deps. iter ( ) {
1172+ for ( dep, proc_macro ) in deps. iter ( ) {
11441173 let mtime = mtime ( dep) ;
11451174 if Some ( mtime) > max {
11461175 max = Some ( mtime) ;
11471176 max_path = Some ( dep. clone ( ) ) ;
11481177 }
1178+ new_contents. extend ( if * proc_macro { b"h" } else { b"t" } ) ;
11491179 new_contents. extend ( dep. to_str ( ) . unwrap ( ) . as_bytes ( ) ) ;
11501180 new_contents. extend ( b"\0 " ) ;
11511181 }
@@ -1157,15 +1187,15 @@ pub fn run_cargo(builder: &Builder<'_>,
11571187 if contents_equal && max <= stamp_mtime {
11581188 builder. verbose ( & format ! ( "not updating {:?}; contents equal and {:?} <= {:?}" ,
11591189 stamp, max, stamp_mtime) ) ;
1160- return deps
1190+ return deps. into_iter ( ) . map ( | ( d , _ ) | d ) . collect ( )
11611191 }
11621192 if max > stamp_mtime {
11631193 builder. verbose ( & format ! ( "updating {:?} as {:?} changed" , stamp, max_path) ) ;
11641194 } else {
11651195 builder. verbose ( & format ! ( "updating {:?} as deps changed" , stamp) ) ;
11661196 }
11671197 t ! ( fs:: write( & stamp, & new_contents) ) ;
1168- deps
1198+ deps. into_iter ( ) . map ( | ( d , _ ) | d ) . collect ( )
11691199}
11701200
11711201pub fn stream_cargo (
@@ -1211,13 +1241,19 @@ pub fn stream_cargo(
12111241 status. success ( )
12121242}
12131243
1244+ #[ derive( Deserialize ) ]
1245+ pub struct CargoTarget < ' a > {
1246+ crate_types : Vec < Cow < ' a , str > > ,
1247+ }
1248+
12141249#[ derive( Deserialize ) ]
12151250#[ serde( tag = "reason" , rename_all = "kebab-case" ) ]
12161251pub enum CargoMessage < ' a > {
12171252 CompilerArtifact {
12181253 package_id : Cow < ' a , str > ,
12191254 features : Vec < Cow < ' a , str > > ,
12201255 filenames : Vec < Cow < ' a , str > > ,
1256+ target : CargoTarget < ' a > ,
12211257 } ,
12221258 BuildScriptExecuted {
12231259 package_id : Cow < ' a , str > ,
0 commit comments