Skip to content

Commit f72e44e

Browse files
authored
Merge pull request #389 from Zoxc/vs2019
Autodetect VS 2019
2 parents aa6aac8 + e9c290b commit f72e44e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/windows_registry.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ mod impl_ {
181181
use std::fs::File;
182182
use std::io::Read;
183183
use std::mem;
184+
use std::iter;
184185
use std::path::{Path, PathBuf};
185186

186187
use Tool;
@@ -217,6 +218,41 @@ mod impl_ {
217218
}
218219
}
219220

221+
fn vs16_instances() -> Box<Iterator<Item=PathBuf>> {
222+
let instances = if let Some(instances) = vs15_instances() {
223+
instances
224+
} else {
225+
return Box::new(iter::empty());
226+
};
227+
Box::new(instances.filter_map(|instance| {
228+
let instance = instance.ok()?;
229+
let installation_name = instance.installation_name().ok()?;
230+
if installation_name.to_str()?.starts_with("VisualStudio/16.") {
231+
Some(PathBuf::from(instance.installation_path().ok()?))
232+
} else {
233+
None
234+
}
235+
}))
236+
}
237+
238+
fn find_tool_in_vs16_path(tool: &str, target: &str) -> Option<Tool> {
239+
vs16_instances().find_map(|path| {
240+
let path = path.join(tool);
241+
if !path.is_file() {
242+
return None;
243+
}
244+
let mut tool = Tool::new(path);
245+
if target.contains("x86_64") {
246+
tool.env.push(("Platform".into(), "X64".into()));
247+
}
248+
Some(tool)
249+
})
250+
}
251+
252+
fn find_msbuild_vs16(target: &str) -> Option<Tool> {
253+
find_tool_in_vs16_path(r"MSBuild\Current\Bin\MSBuild.exe", target)
254+
}
255+
220256
// In MSVC 15 (2017) MS once again changed the scheme for locating
221257
// the tooling. Now we must go through some COM interfaces, which
222258
// is super fun for Rust.
@@ -662,6 +698,10 @@ mod impl_ {
662698

663699
pub fn has_msbuild_version(version: &str) -> bool {
664700
match version {
701+
"16.0" => {
702+
find_msbuild_vs16("x86_64-pc-windows-msvc").is_some()
703+
|| find_msbuild_vs16("i686-pc-windows-msvc").is_some()
704+
}
665705
"15.0" => {
666706
find_msbuild_vs15("x86_64-pc-windows-msvc").is_some()
667707
|| find_msbuild_vs15("i686-pc-windows-msvc").is_some()

0 commit comments

Comments
 (0)