From 8e37948c38c36e540c1a5264f11ce3a1730aeb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sat, 6 Apr 2019 11:38:52 +0200 Subject: [PATCH 1/2] Autodetect VS 2019 --- src/windows_registry.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/windows_registry.rs b/src/windows_registry.rs index a1a1954..4e00db4 100644 --- a/src/windows_registry.rs +++ b/src/windows_registry.rs @@ -217,6 +217,34 @@ mod impl_ { } } + fn vs16_instance() -> Option { + vs15_instances()?.find_map(|instance| { + let instance = instance.ok()?; + let installation_name = instance.installation_name().ok()?;; + if installation_name.to_str()?.starts_with("VisualStudio/16.") { + Some(PathBuf::from(instance.installation_path().ok()?)) + } else { + None + } + }) + } + + fn find_tool_in_vs16_path(tool: &str, target: &str) -> Option { + let path = vs16_instance()?.join(tool); + if !path.is_file() { + return None; + } + let mut tool = Tool::new(path); + if target.contains("x86_64") { + tool.env.push(("Platform".into(), "X64".into())); + } + Some(tool) + } + + fn find_msbuild_vs16(target: &str) -> Option { + find_tool_in_vs16_path(r"MSBuild\Current\Bin\MSBuild.exe", target) + } + // In MSVC 15 (2017) MS once again changed the scheme for locating // the tooling. Now we must go through some COM interfaces, which // is super fun for Rust. @@ -662,6 +690,10 @@ mod impl_ { pub fn has_msbuild_version(version: &str) -> bool { match version { + "16.0" => { + find_msbuild_vs16("x86_64-pc-windows-msvc").is_some() + || find_msbuild_vs16("i686-pc-windows-msvc").is_some() + } "15.0" => { find_msbuild_vs15("x86_64-pc-windows-msvc").is_some() || find_msbuild_vs15("i686-pc-windows-msvc").is_some() From e9c290b214f4274b7ca311bea1a52bfd48be4f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sat, 6 Apr 2019 11:58:57 +0200 Subject: [PATCH 2/2] Make detection more robust --- src/windows_registry.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/windows_registry.rs b/src/windows_registry.rs index 4e00db4..0d3ea6c 100644 --- a/src/windows_registry.rs +++ b/src/windows_registry.rs @@ -181,6 +181,7 @@ mod impl_ { use std::fs::File; use std::io::Read; use std::mem; + use std::iter; use std::path::{Path, PathBuf}; use Tool; @@ -217,28 +218,35 @@ mod impl_ { } } - fn vs16_instance() -> Option { - vs15_instances()?.find_map(|instance| { + fn vs16_instances() -> Box> { + let instances = if let Some(instances) = vs15_instances() { + instances + } else { + return Box::new(iter::empty()); + }; + Box::new(instances.filter_map(|instance| { let instance = instance.ok()?; - let installation_name = instance.installation_name().ok()?;; + let installation_name = instance.installation_name().ok()?; if installation_name.to_str()?.starts_with("VisualStudio/16.") { Some(PathBuf::from(instance.installation_path().ok()?)) } else { None } - }) + })) } fn find_tool_in_vs16_path(tool: &str, target: &str) -> Option { - let path = vs16_instance()?.join(tool); - if !path.is_file() { - return None; - } - let mut tool = Tool::new(path); - if target.contains("x86_64") { - tool.env.push(("Platform".into(), "X64".into())); - } - Some(tool) + vs16_instances().find_map(|path| { + let path = path.join(tool); + if !path.is_file() { + return None; + } + let mut tool = Tool::new(path); + if target.contains("x86_64") { + tool.env.push(("Platform".into(), "X64".into())); + } + Some(tool) + }) } fn find_msbuild_vs16(target: &str) -> Option {