@@ -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
@@ -426,8 +427,12 @@ impl Step for TestLink {
426427 & compiler. host,
427428 target_compiler. host,
428429 target) ) ;
429- add_to_sysroot ( builder, & builder. sysroot_libdir ( target_compiler, target) ,
430- & libtest_stamp ( builder, compiler, target) ) ;
430+ add_to_sysroot (
431+ builder,
432+ & builder. sysroot_libdir ( target_compiler, target) ,
433+ & builder. sysroot_libdir ( target_compiler, compiler. host ) ,
434+ & libtest_stamp ( builder, compiler, target)
435+ ) ;
431436
432437 builder. cargo ( target_compiler, Mode :: ToolTest , target, "clean" ) ;
433438 }
@@ -491,8 +496,8 @@ impl Step for Rustc {
491496 return ;
492497 }
493498
494- // Ensure that build scripts have a std to link against.
495- builder. ensure ( Std {
499+ // Ensure that build scripts and proc macros have a std / libproc_macro to link against.
500+ builder. ensure ( Test {
496501 compiler : builder. compiler ( self . compiler . stage , builder. config . build ) ,
497502 target : builder. config . build ,
498503 } ) ;
@@ -587,8 +592,12 @@ impl Step for RustcLink {
587592 & compiler. host,
588593 target_compiler. host,
589594 target) ) ;
590- add_to_sysroot ( builder, & builder. sysroot_libdir ( target_compiler, target) ,
591- & librustc_stamp ( builder, compiler, target) ) ;
595+ add_to_sysroot (
596+ builder,
597+ & builder. sysroot_libdir ( target_compiler, target) ,
598+ & builder. sysroot_libdir ( target_compiler, compiler. host ) ,
599+ & librustc_stamp ( builder, compiler, target)
600+ ) ;
592601 builder. cargo ( target_compiler, Mode :: ToolRustc , target, "clean" ) ;
593602 }
594603}
@@ -996,10 +1005,22 @@ impl Step for Assemble {
9961005///
9971006/// For a particular stage this will link the file listed in `stamp` into the
9981007/// `sysroot_dst` provided.
999- pub fn add_to_sysroot ( builder : & Builder , sysroot_dst : & Path , stamp : & Path ) {
1008+ pub fn add_to_sysroot (
1009+ builder : & Builder ,
1010+ sysroot_dst : & Path ,
1011+ sysroot_host_dst : & Path ,
1012+ stamp : & Path
1013+ ) {
1014+ //eprintln!("add_to_sysroot - host dir {:?} - stamp {:?}", sysroot_host_dst, stamp);
10001015 t ! ( fs:: create_dir_all( & sysroot_dst) ) ;
1001- for path in builder. read_stamp_file ( stamp) {
1002- builder. copy ( & path, & sysroot_dst. join ( path. file_name ( ) . unwrap ( ) ) ) ;
1016+ t ! ( fs:: create_dir_all( & sysroot_host_dst) ) ;
1017+ for ( path, host) in builder. read_stamp_file ( stamp) {
1018+ if host {
1019+ eprintln ! ( "add_to_sysroot host - copying {:?} to {:?}" , path, sysroot_host_dst) ;
1020+ builder. copy ( & path, & sysroot_host_dst. join ( path. file_name ( ) . unwrap ( ) ) ) ;
1021+ } else {
1022+ builder. copy ( & path, & sysroot_dst. join ( path. file_name ( ) . unwrap ( ) ) ) ;
1023+ }
10031024 }
10041025}
10051026
@@ -1028,8 +1049,14 @@ pub fn run_cargo(builder: &Builder,
10281049 let mut deps = Vec :: new ( ) ;
10291050 let mut toplevel = Vec :: new ( ) ;
10301051 let ok = stream_cargo ( builder, cargo, & mut |msg| {
1031- let filenames = match msg {
1032- CargoMessage :: CompilerArtifact { filenames, .. } => filenames,
1052+ let ( filenames, crate_types) = match msg {
1053+ CargoMessage :: CompilerArtifact {
1054+ filenames,
1055+ target : CargoTarget {
1056+ crate_types,
1057+ } ,
1058+ ..
1059+ } => ( filenames, crate_types) ,
10331060 _ => return ,
10341061 } ;
10351062 for filename in filenames {
@@ -1044,15 +1071,19 @@ pub fn run_cargo(builder: &Builder,
10441071 let filename = Path :: new ( & * filename) ;
10451072
10461073 // If this was an output file in the "host dir" we don't actually
1047- // worry about it, it's not relevant for us.
1074+ // worry about it, it's not relevant for us
10481075 if filename. starts_with ( & host_root_dir) {
1076+ // Unless it's a proc macro used in the compiler
1077+ if crate_types. iter ( ) . any ( |t| t == "proc-macro" ) {
1078+ deps. push ( ( filename. to_path_buf ( ) , true ) ) ;
1079+ }
10491080 continue ;
10501081 }
10511082
10521083 // If this was output in the `deps` dir then this is a precise file
10531084 // name (hash included) so we start tracking it.
10541085 if filename. starts_with ( & target_deps_dir) {
1055- deps. push ( filename. to_path_buf ( ) ) ;
1086+ deps. push ( ( filename. to_path_buf ( ) , false ) ) ;
10561087 continue ;
10571088 }
10581089
@@ -1105,10 +1136,10 @@ pub fn run_cargo(builder: &Builder,
11051136 let candidate = format ! ( "{}.lib" , path_to_add) ;
11061137 let candidate = PathBuf :: from ( candidate) ;
11071138 if candidate. exists ( ) {
1108- deps. push ( candidate) ;
1139+ deps. push ( ( candidate, false ) ) ;
11091140 }
11101141 }
1111- deps. push ( path_to_add. into ( ) ) ;
1142+ deps. push ( ( path_to_add. into ( ) , false ) ) ;
11121143 }
11131144
11141145 // Now we want to update the contents of the stamp file, if necessary. First
@@ -1121,12 +1152,13 @@ pub fn run_cargo(builder: &Builder,
11211152 let mut new_contents = Vec :: new ( ) ;
11221153 let mut max = None ;
11231154 let mut max_path = None ;
1124- for dep in deps. iter ( ) {
1155+ for ( dep, proc_macro ) in deps. iter ( ) {
11251156 let mtime = mtime ( dep) ;
11261157 if Some ( mtime) > max {
11271158 max = Some ( mtime) ;
11281159 max_path = Some ( dep. clone ( ) ) ;
11291160 }
1161+ new_contents. extend ( if * proc_macro { b"h" } else { b"t" } ) ;
11301162 new_contents. extend ( dep. to_str ( ) . unwrap ( ) . as_bytes ( ) ) ;
11311163 new_contents. extend ( b"\0 " ) ;
11321164 }
@@ -1138,15 +1170,15 @@ pub fn run_cargo(builder: &Builder,
11381170 if contents_equal && max <= stamp_mtime {
11391171 builder. verbose ( & format ! ( "not updating {:?}; contents equal and {:?} <= {:?}" ,
11401172 stamp, max, stamp_mtime) ) ;
1141- return deps
1173+ return deps. into_iter ( ) . map ( | ( d , _ ) | d ) . collect ( )
11421174 }
11431175 if max > stamp_mtime {
11441176 builder. verbose ( & format ! ( "updating {:?} as {:?} changed" , stamp, max_path) ) ;
11451177 } else {
11461178 builder. verbose ( & format ! ( "updating {:?} as deps changed" , stamp) ) ;
11471179 }
11481180 t ! ( fs:: write( & stamp, & new_contents) ) ;
1149- deps
1181+ deps. into_iter ( ) . map ( | ( d , _ ) | d ) . collect ( )
11501182}
11511183
11521184pub fn stream_cargo (
@@ -1192,13 +1224,19 @@ pub fn stream_cargo(
11921224 status. success ( )
11931225}
11941226
1227+ #[ derive( Deserialize ) ]
1228+ pub struct CargoTarget < ' a > {
1229+ crate_types : Vec < Cow < ' a , str > > ,
1230+ }
1231+
11951232#[ derive( Deserialize ) ]
11961233#[ serde( tag = "reason" , rename_all = "kebab-case" ) ]
11971234pub enum CargoMessage < ' a > {
11981235 CompilerArtifact {
11991236 package_id : Cow < ' a , str > ,
12001237 features : Vec < Cow < ' a , str > > ,
12011238 filenames : Vec < Cow < ' a , str > > ,
1239+ target : CargoTarget < ' a > ,
12021240 } ,
12031241 BuildScriptExecuted {
12041242 package_id : Cow < ' a , str > ,
0 commit comments