@@ -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
@@ -431,8 +432,12 @@ impl Step for TestLink {
431
432
& compiler. host,
432
433
target_compiler. host,
433
434
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
+ ) ;
436
441
437
442
builder. cargo ( target_compiler, Mode :: ToolTest , target, "clean" ) ;
438
443
}
@@ -496,8 +501,8 @@ impl Step for Rustc {
496
501
return ;
497
502
}
498
503
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 {
501
506
compiler : builder. compiler ( self . compiler . stage , builder. config . build ) ,
502
507
target : builder. config . build ,
503
508
} ) ;
@@ -592,8 +597,12 @@ impl Step for RustcLink {
592
597
& compiler. host,
593
598
target_compiler. host,
594
599
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
+ ) ;
597
606
builder. cargo ( target_compiler, Mode :: ToolRustc , target, "clean" ) ;
598
607
}
599
608
}
@@ -1015,10 +1024,20 @@ impl Step for Assemble {
1015
1024
///
1016
1025
/// For a particular stage this will link the file listed in `stamp` into the
1017
1026
/// `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
+ ) {
1019
1033
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
+ }
1022
1041
}
1023
1042
}
1024
1043
@@ -1047,8 +1066,14 @@ pub fn run_cargo(builder: &Builder<'_>,
1047
1066
let mut deps = Vec :: new ( ) ;
1048
1067
let mut toplevel = Vec :: new ( ) ;
1049
1068
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) ,
1052
1077
_ => return ,
1053
1078
} ;
1054
1079
for filename in filenames {
@@ -1063,15 +1088,19 @@ pub fn run_cargo(builder: &Builder<'_>,
1063
1088
let filename = Path :: new ( & * filename) ;
1064
1089
1065
1090
// 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
1067
1092
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
+ }
1068
1097
continue ;
1069
1098
}
1070
1099
1071
1100
// If this was output in the `deps` dir then this is a precise file
1072
1101
// name (hash included) so we start tracking it.
1073
1102
if filename. starts_with ( & target_deps_dir) {
1074
- deps. push ( filename. to_path_buf ( ) ) ;
1103
+ deps. push ( ( filename. to_path_buf ( ) , false ) ) ;
1075
1104
continue ;
1076
1105
}
1077
1106
@@ -1124,10 +1153,10 @@ pub fn run_cargo(builder: &Builder<'_>,
1124
1153
let candidate = format ! ( "{}.lib" , path_to_add) ;
1125
1154
let candidate = PathBuf :: from ( candidate) ;
1126
1155
if candidate. exists ( ) {
1127
- deps. push ( candidate) ;
1156
+ deps. push ( ( candidate, false ) ) ;
1128
1157
}
1129
1158
}
1130
- deps. push ( path_to_add. into ( ) ) ;
1159
+ deps. push ( ( path_to_add. into ( ) , false ) ) ;
1131
1160
}
1132
1161
1133
1162
// Now we want to update the contents of the stamp file, if necessary. First
@@ -1140,12 +1169,13 @@ pub fn run_cargo(builder: &Builder<'_>,
1140
1169
let mut new_contents = Vec :: new ( ) ;
1141
1170
let mut max = None ;
1142
1171
let mut max_path = None ;
1143
- for dep in deps. iter ( ) {
1172
+ for ( dep, proc_macro ) in deps. iter ( ) {
1144
1173
let mtime = mtime ( dep) ;
1145
1174
if Some ( mtime) > max {
1146
1175
max = Some ( mtime) ;
1147
1176
max_path = Some ( dep. clone ( ) ) ;
1148
1177
}
1178
+ new_contents. extend ( if * proc_macro { b"h" } else { b"t" } ) ;
1149
1179
new_contents. extend ( dep. to_str ( ) . unwrap ( ) . as_bytes ( ) ) ;
1150
1180
new_contents. extend ( b"\0 " ) ;
1151
1181
}
@@ -1157,15 +1187,15 @@ pub fn run_cargo(builder: &Builder<'_>,
1157
1187
if contents_equal && max <= stamp_mtime {
1158
1188
builder. verbose ( & format ! ( "not updating {:?}; contents equal and {:?} <= {:?}" ,
1159
1189
stamp, max, stamp_mtime) ) ;
1160
- return deps
1190
+ return deps. into_iter ( ) . map ( | ( d , _ ) | d ) . collect ( )
1161
1191
}
1162
1192
if max > stamp_mtime {
1163
1193
builder. verbose ( & format ! ( "updating {:?} as {:?} changed" , stamp, max_path) ) ;
1164
1194
} else {
1165
1195
builder. verbose ( & format ! ( "updating {:?} as deps changed" , stamp) ) ;
1166
1196
}
1167
1197
t ! ( fs:: write( & stamp, & new_contents) ) ;
1168
- deps
1198
+ deps. into_iter ( ) . map ( | ( d , _ ) | d ) . collect ( )
1169
1199
}
1170
1200
1171
1201
pub fn stream_cargo (
@@ -1211,13 +1241,19 @@ pub fn stream_cargo(
1211
1241
status. success ( )
1212
1242
}
1213
1243
1244
+ #[ derive( Deserialize ) ]
1245
+ pub struct CargoTarget < ' a > {
1246
+ crate_types : Vec < Cow < ' a , str > > ,
1247
+ }
1248
+
1214
1249
#[ derive( Deserialize ) ]
1215
1250
#[ serde( tag = "reason" , rename_all = "kebab-case" ) ]
1216
1251
pub enum CargoMessage < ' a > {
1217
1252
CompilerArtifact {
1218
1253
package_id : Cow < ' a , str > ,
1219
1254
features : Vec < Cow < ' a , str > > ,
1220
1255
filenames : Vec < Cow < ' a , str > > ,
1256
+ target : CargoTarget < ' a > ,
1221
1257
} ,
1222
1258
BuildScriptExecuted {
1223
1259
package_id : Cow < ' a , str > ,
0 commit comments