Skip to content

Commit

Permalink
Add Win10 SDK lib subfolder name
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Atashian <retep998@gmail.com>
  • Loading branch information
retep998 committed Jul 31, 2015
1 parent 7597262 commit 6a8aec3
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions src/librustc_trans/back/msvc/mod.rs
Expand Up @@ -206,7 +206,7 @@ pub fn link_exe_cmd(sess: &Session) -> Command {
return max_key
}

fn get_windows_sdk_path() -> Option<(PathBuf, usize)> {
fn get_windows_sdk_path() -> Option<(PathBuf, usize, Option<OsString>)> {
let key = r"SOFTWARE\Microsoft\Microsoft SDKs\Windows";
let key = LOCAL_MACHINE.open(key.as_ref());
let (n, k) = match key.ok().as_ref().and_then(max_version) {
Expand All @@ -217,28 +217,29 @@ pub fn link_exe_cmd(sess: &Session) -> Command {
let major = parts.next().unwrap().parse::<usize>().unwrap();
let _minor = parts.next().unwrap().parse::<usize>().unwrap();
k.query_str("InstallationFolder").ok().map(|folder| {
(PathBuf::from(folder), major)
let ver = k.query_str("ProductVersion");
(PathBuf::from(folder), major, ver.ok())
})
}

fn get_windows_sdk_lib_path(sess: &Session) -> Option<PathBuf> {
let (mut path, major) = match get_windows_sdk_path() {
let (mut path, major, ver) = match get_windows_sdk_path() {
Some(p) => p,
None => return None,
};
path.push("Lib");
if major <= 7 {
// In Windows SDK 7.x, x86 libraries are directly in the Lib folder,
// x64 libraries are inside, and it's not necessary to link agains
// x64 libraries are inside, and it's not necessary to link against
// the SDK 7.x when targeting ARM or other architectures.
let x86 = match &sess.target.target.arch[..] {
"x86" => true,
"x86_64" => false,
_ => return None,
};
Some(if x86 {path} else {path.join("x64")})
} else {
// Windows SDK 8.x installes libraries in a folder whose names
} else if major <= 8 {
// Windows SDK 8.x installs libraries in a folder whose names
// depend on the version of the OS you're targeting. By default
// choose the newest, which usually corresponds to the version of
// the OS you've installed the SDK on.
Expand All @@ -251,7 +252,25 @@ pub fn link_exe_cmd(sess: &Session) -> Command {
}).map(|path| {
path.join("um").join(extra)
})
}
} else if let Some(mut ver) = ver {
// Windows SDK 10 splits the libraries into architectures the same
// as Windows SDK 8.x, except for the addition of arm64.
// Additionally, the SDK 10 is split by Windows 10 build numbers
// rather than the OS version like the SDK 8.x does.
let extra = match windows_sdk_v10_subdir(sess) {
Some(e) => e,
None => return None,
};
// To get the correct directory we need to get the Windows SDK 10
// version, and so far it looks like the "ProductVersion" of the SDK
// corresponds to the folder name that the libraries are located in
// except that the folder contains an extra ".0". For now just
// append a ".0" to look for find the directory we're in. This logic
// will likely want to be refactored one day.
ver.push(".0");
let p = path.join(ver).join("um").join(extra);
fs::metadata(&p).ok().map(|_| p)
} else { None }
}

fn windows_sdk_v8_subdir(sess: &Session) -> Option<&'static str> {
Expand All @@ -263,6 +282,16 @@ pub fn link_exe_cmd(sess: &Session) -> Command {
}
}

fn windows_sdk_v10_subdir(sess: &Session) -> Option<&'static str> {
match &sess.target.target.arch[..] {
"x86" => Some("x86"),
"x86_64" => Some("x64"),
"arm" => Some("arm"),
"aarch64" => Some("arm64"), // FIXME - Check if aarch64 is correct
_ => return None,
}
}

fn ucrt_install_dir(vs_install_dir: &Path) -> Option<(PathBuf, String)> {
let is_vs_14 = vs_install_dir.iter().filter_map(|p| p.to_str()).any(|s| {
s == "Microsoft Visual Studio 14.0"
Expand Down

0 comments on commit 6a8aec3

Please sign in to comment.