Skip to content

Commit 81fcb53

Browse files
authored
In windows_registry::find_tool, set the ToolFamily to Msvc (#499)
* In windows_registry::find_tool, set the ToolFamily to Msvc Ensures that the `Tool` returned from `windows_registry::find_tool` will always return true for `is_like_msvc()`. * fmt * Add #[cfg(windows)] for items only used in Windows * cfg(windows) on imports
1 parent 3c69f1d commit 81fcb53

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,6 +2393,21 @@ impl Tool {
23932393
Self::with_features(path, clang_driver, false)
23942394
}
23952395

2396+
#[cfg(windows)]
2397+
/// Explictly set the `ToolFamily`, skipping name-based detection.
2398+
fn with_family(path: PathBuf, family: ToolFamily) -> Self {
2399+
Self {
2400+
path: path,
2401+
cc_wrapper_path: None,
2402+
cc_wrapper_args: Vec::new(),
2403+
args: Vec::new(),
2404+
env: Vec::new(),
2405+
family: family,
2406+
cuda: false,
2407+
removed_args: Vec::new(),
2408+
}
2409+
}
2410+
23962411
fn with_features(path: PathBuf, clang_driver: Option<&str>, cuda: bool) -> Self {
23972412
// Try to detect family of the tool from its name, falling back to Gnu.
23982413
let family = if let Some(fname) = path.file_name().and_then(|p| p.to_str()) {

src/windows_registry.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
use std::process::Command;
1515

1616
use crate::Tool;
17+
#[cfg(windows)]
18+
use crate::ToolFamily;
19+
20+
#[cfg(windows)]
21+
const MSVC_FAMILY: ToolFamily = ToolFamily::Msvc { clang_cl: false };
1722

1823
/// Attempts to find a tool within an MSVC installation using the Windows
1924
/// registry as a point to search from.
@@ -70,7 +75,7 @@ pub fn find_tool(target: &str, tool: &str) -> Option<Tool> {
7075
.map(|p| p.join(tool))
7176
.find(|p| p.exists())
7277
})
73-
.map(|path| Tool::new(path.into()));
78+
.map(|path| Tool::with_family(path.into(), MSVC_FAMILY));
7479
}
7580

7681
// Ok, if we're here, now comes the fun part of the probing. Default shells
@@ -175,6 +180,7 @@ mod impl_ {
175180
use std::path::{Path, PathBuf};
176181
use std::str::FromStr;
177182

183+
use super::MSVC_FAMILY;
178184
use crate::Tool;
179185

180186
struct MsvcTool {
@@ -201,7 +207,7 @@ mod impl_ {
201207
path,
202208
include,
203209
} = self;
204-
let mut tool = Tool::new(tool.into());
210+
let mut tool = Tool::with_family(tool.into(), MSVC_FAMILY);
205211
add_env(&mut tool, "LIB", libs);
206212
add_env(&mut tool, "PATH", path);
207213
add_env(&mut tool, "INCLUDE", include);
@@ -234,7 +240,7 @@ mod impl_ {
234240
if !path.is_file() {
235241
return None;
236242
}
237-
let mut tool = Tool::new(path);
243+
let mut tool = Tool::with_family(path, MSVC_FAMILY);
238244
if target.contains("x86_64") {
239245
tool.env.push(("Platform".into(), "X64".into()));
240246
}
@@ -315,7 +321,7 @@ mod impl_ {
315321
}
316322

317323
path.map(|path| {
318-
let mut tool = Tool::new(path);
324+
let mut tool = Tool::with_family(path, MSVC_FAMILY);
319325
if target.contains("x86_64") {
320326
tool.env.push(("Platform".into(), "X64".into()));
321327
}
@@ -760,7 +766,7 @@ mod impl_ {
760766
.map(|path| {
761767
let mut path = PathBuf::from(path);
762768
path.push("MSBuild.exe");
763-
let mut tool = Tool::new(path);
769+
let mut tool = Tool::with_family(path, MSVC_FAMILY);
764770
if target.contains("x86_64") {
765771
tool.env.push(("Platform".into(), "X64".into()));
766772
}

0 commit comments

Comments
 (0)