@@ -224,7 +224,8 @@ impl Step for StdLink {
224
224
target_compiler. host,
225
225
target) ) ;
226
226
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) ) ;
228
229
229
230
if builder. config . sanitizers && compiler. stage != 0 && target == "x86_64-apple-darwin" {
230
231
// The sanitizers are only built in stage1 or above, so the dylibs will
@@ -426,8 +427,12 @@ impl Step for TestLink {
426
427
& compiler. host,
427
428
target_compiler. host,
428
429
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
+ ) ;
431
436
432
437
builder. cargo ( target_compiler, Mode :: ToolTest , target, "clean" ) ;
433
438
}
@@ -491,8 +496,8 @@ impl Step for Rustc {
491
496
return ;
492
497
}
493
498
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 {
496
501
compiler : builder. compiler ( self . compiler . stage , builder. config . build ) ,
497
502
target : builder. config . build ,
498
503
} ) ;
@@ -587,8 +592,12 @@ impl Step for RustcLink {
587
592
& compiler. host,
588
593
target_compiler. host,
589
594
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
+ ) ;
592
601
builder. cargo ( target_compiler, Mode :: ToolRustc , target, "clean" ) ;
593
602
}
594
603
}
@@ -996,10 +1005,22 @@ impl Step for Assemble {
996
1005
///
997
1006
/// For a particular stage this will link the file listed in `stamp` into the
998
1007
/// `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);
1000
1015
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
+ }
1003
1024
}
1004
1025
}
1005
1026
@@ -1028,8 +1049,14 @@ pub fn run_cargo(builder: &Builder,
1028
1049
let mut deps = Vec :: new ( ) ;
1029
1050
let mut toplevel = Vec :: new ( ) ;
1030
1051
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) ,
1033
1060
_ => return ,
1034
1061
} ;
1035
1062
for filename in filenames {
@@ -1044,15 +1071,19 @@ pub fn run_cargo(builder: &Builder,
1044
1071
let filename = Path :: new ( & * filename) ;
1045
1072
1046
1073
// 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
1048
1075
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
+ }
1049
1080
continue ;
1050
1081
}
1051
1082
1052
1083
// If this was output in the `deps` dir then this is a precise file
1053
1084
// name (hash included) so we start tracking it.
1054
1085
if filename. starts_with ( & target_deps_dir) {
1055
- deps. push ( filename. to_path_buf ( ) ) ;
1086
+ deps. push ( ( filename. to_path_buf ( ) , false ) ) ;
1056
1087
continue ;
1057
1088
}
1058
1089
@@ -1105,10 +1136,10 @@ pub fn run_cargo(builder: &Builder,
1105
1136
let candidate = format ! ( "{}.lib" , path_to_add) ;
1106
1137
let candidate = PathBuf :: from ( candidate) ;
1107
1138
if candidate. exists ( ) {
1108
- deps. push ( candidate) ;
1139
+ deps. push ( ( candidate, false ) ) ;
1109
1140
}
1110
1141
}
1111
- deps. push ( path_to_add. into ( ) ) ;
1142
+ deps. push ( ( path_to_add. into ( ) , false ) ) ;
1112
1143
}
1113
1144
1114
1145
// Now we want to update the contents of the stamp file, if necessary. First
@@ -1121,12 +1152,13 @@ pub fn run_cargo(builder: &Builder,
1121
1152
let mut new_contents = Vec :: new ( ) ;
1122
1153
let mut max = None ;
1123
1154
let mut max_path = None ;
1124
- for dep in deps. iter ( ) {
1155
+ for ( dep, proc_macro ) in deps. iter ( ) {
1125
1156
let mtime = mtime ( dep) ;
1126
1157
if Some ( mtime) > max {
1127
1158
max = Some ( mtime) ;
1128
1159
max_path = Some ( dep. clone ( ) ) ;
1129
1160
}
1161
+ new_contents. extend ( if * proc_macro { b"h" } else { b"t" } ) ;
1130
1162
new_contents. extend ( dep. to_str ( ) . unwrap ( ) . as_bytes ( ) ) ;
1131
1163
new_contents. extend ( b"\0 " ) ;
1132
1164
}
@@ -1138,15 +1170,15 @@ pub fn run_cargo(builder: &Builder,
1138
1170
if contents_equal && max <= stamp_mtime {
1139
1171
builder. verbose ( & format ! ( "not updating {:?}; contents equal and {:?} <= {:?}" ,
1140
1172
stamp, max, stamp_mtime) ) ;
1141
- return deps
1173
+ return deps. into_iter ( ) . map ( | ( d , _ ) | d ) . collect ( )
1142
1174
}
1143
1175
if max > stamp_mtime {
1144
1176
builder. verbose ( & format ! ( "updating {:?} as {:?} changed" , stamp, max_path) ) ;
1145
1177
} else {
1146
1178
builder. verbose ( & format ! ( "updating {:?} as deps changed" , stamp) ) ;
1147
1179
}
1148
1180
t ! ( fs:: write( & stamp, & new_contents) ) ;
1149
- deps
1181
+ deps. into_iter ( ) . map ( | ( d , _ ) | d ) . collect ( )
1150
1182
}
1151
1183
1152
1184
pub fn stream_cargo (
@@ -1192,13 +1224,19 @@ pub fn stream_cargo(
1192
1224
status. success ( )
1193
1225
}
1194
1226
1227
+ #[ derive( Deserialize ) ]
1228
+ pub struct CargoTarget < ' a > {
1229
+ crate_types : Vec < Cow < ' a , str > > ,
1230
+ }
1231
+
1195
1232
#[ derive( Deserialize ) ]
1196
1233
#[ serde( tag = "reason" , rename_all = "kebab-case" ) ]
1197
1234
pub enum CargoMessage < ' a > {
1198
1235
CompilerArtifact {
1199
1236
package_id : Cow < ' a , str > ,
1200
1237
features : Vec < Cow < ' a , str > > ,
1201
1238
filenames : Vec < Cow < ' a , str > > ,
1239
+ target : CargoTarget < ' a > ,
1202
1240
} ,
1203
1241
BuildScriptExecuted {
1204
1242
package_id : Cow < ' a , str > ,
0 commit comments