From c2aa0d36952250b45000b5d6cd6df19e049ca8d5 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Thu, 22 Aug 2024 18:15:13 -0600 Subject: [PATCH] msvc: allow finding tools from path if VisualStudioDir is set --- src/windows/find_tools.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/windows/find_tools.rs b/src/windows/find_tools.rs index e124c577..8a305621 100644 --- a/src/windows/find_tools.rs +++ b/src/windows/find_tools.rs @@ -361,14 +361,20 @@ mod impl_ { target: TargetArch<'_>, env_getter: &dyn EnvGetter, ) -> Option { - // Early return if the environment doesn't contain a VC install. - env_getter.get_env("VCINSTALLDIR")?; - let vs_install_dir: PathBuf = env_getter.get_env("VSINSTALLDIR")?.into(); + // Early return if the environment isn't one that is known to have compiler toolsets in PATH + // `VCINSTALLDIR` is set from vcvarsall.bat (developer command prompt) + // `VisualStudioDir` is set by msbuild when invoking custom build steps + if env_getter.get_env("VCINSTALLDIR").is_none() + && env_getter.get_env("VisualStudioDir").is_none() + { + return None; + } // If the vscmd target differs from the requested target then // attempt to get the tool using the VS install directory. if is_vscmd_target(target, env_getter) == Some(false) { // We will only get here with versions 15+. + let vs_install_dir: PathBuf = env_getter.get_env("VSINSTALLDIR")?.into(); tool_from_vs15plus_instance(tool, target, &vs_install_dir, env_getter) } else { // Fallback to simply using the current environment.