Skip to content

Commit

Permalink
Also scan Win10-specific places, maybe
Browse files Browse the repository at this point in the history
Ref: #5
  • Loading branch information
nabijaczleweli committed Jun 22, 2017
1 parent 8fc139b commit 7a5f6c0
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/windows_msvc.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
use std::path::{PathBuf, Path};
use std::process::Command;
use winreg::enums::*;
use std::env;
use std::{env, fs};
use winreg;

macro_rules! try_opt {
($opt:expr) => {
if let Some(o) = $opt {
o
} else {
return None;
}
}
}

pub const SUPPORTED: bool = true;

#[derive(Clone, Copy, Eq, PartialEq)]
Expand Down Expand Up @@ -31,6 +41,7 @@ fn find_windows_sdk_rc_exe() -> Option<PathBuf> {
.or_else(|| find_windows_kits_rc_exe("KitsRoot81", arch))
.or_else(|| find_windows_kits_rc_exe("KitsRoot", arch))
.or_else(|| find_latest_windows_sdk_rc_exe(arch))
.or_else(|| find_windows_10_kits_rc_exe("KitsRoot10", arch))
}

// Windows 8 - 10
Expand All @@ -53,6 +64,29 @@ fn find_latest_windows_sdk_rc_exe(arch: Arch) -> Option<PathBuf> {
.and_then(try_rc_exe)
}

// Windows 10 with subdir support
fn find_windows_10_kits_rc_exe(key: &str, arch: Arch) -> Option<PathBuf> {
let root_dir = try_opt!(winreg::RegKey::predef(HKEY_LOCAL_MACHINE)
.open_subkey_with_flags(r"SOFTWARE\Microsoft\Windows Kits\Installed Roots", KEY_QUERY_VALUE)
.and_then(|reg_key| reg_key.get_value::<String, _>(key))
.ok()) + "/bin";

for entry in try_opt!(fs::read_dir(&root_dir).ok()).filter(|d| d.is_ok()).map(Result::unwrap) {
let fname = entry.file_name().into_string();
let ftype = entry.file_type();
if fname.is_err() || ftype.is_err() || ftype.unwrap().is_file() {
continue;
}

let fname = entry.file_name().into_string().unwrap();
if let Some(rc) = try_bin_dir(root_dir.clone(), &format!("{}/x86", fname), &format!("{}/x64", fname), arch).and_then(try_rc_exe) {
return Some(rc);
}
}

None
}

fn try_bin_dir(root_dir: String, x86_bin: &str, x64_bin: &str, arch: Arch) -> Option<PathBuf> {
let mut p = PathBuf::from(root_dir);
match arch {
Expand Down

0 comments on commit 7a5f6c0

Please sign in to comment.