Skip to content

Commit 15a5784

Browse files
Allow using VCToolsVersion to request a specific msvc version
1 parent d740f9b commit 15a5784

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

find-msvc-tools/src/find_tools.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ mod impl_ {
787787
instance_path: &Path,
788788
env_getter: &dyn EnvGetter,
789789
) -> Option<(PathBuf, PathBuf, PathBuf, PathBuf, Option<PathBuf>, PathBuf)> {
790-
let version = vs15plus_vc_read_version(instance_path)?;
790+
let version = vs15plus_vc_read_version(instance_path, env_getter)?;
791791

792792
let hosts = match host_arch() {
793793
X86 => &["X86"],
@@ -843,7 +843,13 @@ mod impl_ {
843843
))
844844
}
845845

846-
fn vs15plus_vc_read_version(dir: &Path) -> Option<String> {
846+
fn vs15plus_vc_read_version(dir: &Path, env_getter: &dyn EnvGetter) -> Option<String> {
847+
if let Some(version) = env_getter.get_env("VCToolsVersion") {
848+
// Restrict the search to a specific msvc version; if it doesn't exist then
849+
// our caller will fail to find the tool for this instance and move on.
850+
return version.to_str().map(|s| s.to_string());
851+
}
852+
847853
// Try to open the default version file.
848854
let mut version_path: PathBuf =
849855
dir.join(r"VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt");
@@ -919,6 +925,11 @@ mod impl_ {
919925
target: TargetArch,
920926
env_getter: &dyn EnvGetter,
921927
) -> Option<Tool> {
928+
if env_getter.get_env("VCToolsVersion").is_some() {
929+
// VCToolsVersion is not set/supported for MSVC 14
930+
return None;
931+
}
932+
922933
let vcdir = get_vc_dir("14.0")?;
923934
let sdk_info = get_sdks(target, env_getter)?;
924935
let mut tool = get_tool(tool, &vcdir, target, &sdk_info)?;

0 commit comments

Comments
 (0)