@@ -206,7 +206,7 @@ pub fn link_exe_cmd(sess: &Session) -> Command {
206
206
return max_key
207
207
}
208
208
209
- fn get_windows_sdk_path ( ) -> Option < ( PathBuf , usize ) > {
209
+ fn get_windows_sdk_path ( ) -> Option < ( PathBuf , usize , Option < OsString > ) > {
210
210
let key = r"SOFTWARE\Microsoft\Microsoft SDKs\Windows" ;
211
211
let key = LOCAL_MACHINE . open ( key. as_ref ( ) ) ;
212
212
let ( n, k) = match key. ok ( ) . as_ref ( ) . and_then ( max_version) {
@@ -217,28 +217,29 @@ pub fn link_exe_cmd(sess: &Session) -> Command {
217
217
let major = parts. next ( ) . unwrap ( ) . parse :: < usize > ( ) . unwrap ( ) ;
218
218
let _minor = parts. next ( ) . unwrap ( ) . parse :: < usize > ( ) . unwrap ( ) ;
219
219
k. query_str ( "InstallationFolder" ) . ok ( ) . map ( |folder| {
220
- ( PathBuf :: from ( folder) , major)
220
+ let ver = k. query_str ( "ProductVersion" ) ;
221
+ ( PathBuf :: from ( folder) , major, ver. ok ( ) )
221
222
} )
222
223
}
223
224
224
225
fn get_windows_sdk_lib_path ( sess : & Session ) -> Option < PathBuf > {
225
- let ( mut path, major) = match get_windows_sdk_path ( ) {
226
+ let ( mut path, major, ver ) = match get_windows_sdk_path ( ) {
226
227
Some ( p) => p,
227
228
None => return None ,
228
229
} ;
229
230
path. push ( "Lib" ) ;
230
231
if major <= 7 {
231
232
// In Windows SDK 7.x, x86 libraries are directly in the Lib folder,
232
- // x64 libraries are inside, and it's not necessary to link agains
233
+ // x64 libraries are inside, and it's not necessary to link against
233
234
// the SDK 7.x when targeting ARM or other architectures.
234
235
let x86 = match & sess. target . target . arch [ ..] {
235
236
"x86" => true ,
236
237
"x86_64" => false ,
237
238
_ => return None ,
238
239
} ;
239
240
Some ( if x86 { path} else { path. join ( "x64" ) } )
240
- } else {
241
- // Windows SDK 8.x installes libraries in a folder whose names
241
+ } else if major <= 8 {
242
+ // Windows SDK 8.x installs libraries in a folder whose names
242
243
// depend on the version of the OS you're targeting. By default
243
244
// choose the newest, which usually corresponds to the version of
244
245
// the OS you've installed the SDK on.
@@ -251,7 +252,25 @@ pub fn link_exe_cmd(sess: &Session) -> Command {
251
252
} ) . map ( |path| {
252
253
path. join ( "um" ) . join ( extra)
253
254
} )
254
- }
255
+ } else if let Some ( mut ver) = ver {
256
+ // Windows SDK 10 splits the libraries into architectures the same
257
+ // as Windows SDK 8.x, except for the addition of arm64.
258
+ // Additionally, the SDK 10 is split by Windows 10 build numbers
259
+ // rather than the OS version like the SDK 8.x does.
260
+ let extra = match windows_sdk_v10_subdir ( sess) {
261
+ Some ( e) => e,
262
+ None => return None ,
263
+ } ;
264
+ // To get the correct directory we need to get the Windows SDK 10
265
+ // version, and so far it looks like the "ProductVersion" of the SDK
266
+ // corresponds to the folder name that the libraries are located in
267
+ // except that the folder contains an extra ".0". For now just
268
+ // append a ".0" to look for find the directory we're in. This logic
269
+ // will likely want to be refactored one day.
270
+ ver. push ( ".0" ) ;
271
+ let p = path. join ( ver) . join ( "um" ) . join ( extra) ;
272
+ fs:: metadata ( & p) . ok ( ) . map ( |_| p)
273
+ } else { None }
255
274
}
256
275
257
276
fn windows_sdk_v8_subdir ( sess : & Session ) -> Option < & ' static str > {
@@ -263,6 +282,16 @@ pub fn link_exe_cmd(sess: &Session) -> Command {
263
282
}
264
283
}
265
284
285
+ fn windows_sdk_v10_subdir ( sess : & Session ) -> Option < & ' static str > {
286
+ match & sess. target . target . arch [ ..] {
287
+ "x86" => Some ( "x86" ) ,
288
+ "x86_64" => Some ( "x64" ) ,
289
+ "arm" => Some ( "arm" ) ,
290
+ "aarch64" => Some ( "arm64" ) , // FIXME - Check if aarch64 is correct
291
+ _ => return None ,
292
+ }
293
+ }
294
+
266
295
fn ucrt_install_dir ( vs_install_dir : & Path ) -> Option < ( PathBuf , String ) > {
267
296
let is_vs_14 = vs_install_dir. iter ( ) . filter_map ( |p| p. to_str ( ) ) . any ( |s| {
268
297
s == "Microsoft Visual Studio 14.0"
0 commit comments