diff --git a/compiler/rustc_windows_rc/src/lib.rs b/compiler/rustc_windows_rc/src/lib.rs index caa5e5ef27656..15ad2d875cb59 100644 --- a/compiler/rustc_windows_rc/src/lib.rs +++ b/compiler/rustc_windows_rc/src/lib.rs @@ -135,20 +135,30 @@ fn parse_version(version: &str) -> Option { /// Find the Windows SDK resource compiler `rc.exe` for the given architecture or target triple. /// Returns `None` if the tool could not be found. fn find_resource_compiler(arch_or_target: &str) -> Option { - find_windows_sdk_tool(arch_or_target, "rc.exe") + // If "rc.exe" is on the PATH, use it. Otherwise, try to find the tool in a Windows SDK + find_tool_in_env("rc.exe").or_else(|| find_windows_sdk_tool(arch_or_target, "rc.exe")) } /// Find a Windows SDK tool for the given architecture or target triple. /// Returns `None` if the tool could not be found. fn find_windows_sdk_tool(arch_or_target: &str, tool_name: &str) -> Option { // windows_registry::find_tool can only find MSVC tools, not Windows SDK tools, but - // cc does include the Windows SDK tools in the PATH environment of MSVC tools. + // cc does include the Windows SDK tools in the PATH environment of an MSVC tool, if + // the MSVC tool itself was not found via the PATH. + if find_tool_in_env("link.exe").is_some() { + return None; + } let msvc_linker = windows_registry::find_tool(arch_or_target, "link.exe")?; let path = &msvc_linker.env().iter().find(|(k, _)| k == "PATH")?.1; find_tool_in_path(tool_name, path) } +/// Find a tool in the directories of the PATH environment variable +fn find_tool_in_env(tool_name: &str) -> Option { + env::var_os("PATH").and_then(|p| find_tool_in_path(tool_name, p)) +} + /// Find a tool in the directories in a given PATH-like string. fn find_tool_in_path>(tool_name: &str, path: P) -> Option { env::split_paths(path.as_ref()).find_map(|p| {