From: Martin Storsjo Date: Fri, 19 Apr 2019 19:04:22 +0000 (+0000) Subject: [MSVC] If unable to find link.exe from a MSVC installation, look for link.exe next... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30418fa5f7bd6b2ef238385acb3fa07c938981cb;p=clang [MSVC] If unable to find link.exe from a MSVC installation, look for link.exe next to cl.exe Previously, if the MSVC installation isn't detected properly, clang will later just fail to execute link.exe. This improves using clang in msvc mode on linux, where one intentionally might not want to point clang to the MSVC installation itself (which isn't executable as such), but where a link.exe named wine wrapper is available in the path next to a cl.exe named wine wrapper. Differential Revision: https://reviews.llvm.org/D60094 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358778 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains/MSVC.cpp b/lib/Driver/ToolChains/MSVC.cpp index e3801c55a9..3a789627c5 100644 --- a/lib/Driver/ToolChains/MSVC.cpp +++ b/lib/Driver/ToolChains/MSVC.cpp @@ -488,8 +488,18 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, // their own link.exe which may come first. linkPath = FindVisualStudioExecutable(TC, "link.exe"); - if (!TC.FoundMSVCInstall() && !llvm::sys::fs::can_execute(linkPath)) - C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found); + if (!TC.FoundMSVCInstall() && !llvm::sys::fs::can_execute(linkPath)) { + llvm::SmallString<128> ClPath; + ClPath = TC.GetProgramPath("cl.exe"); + if (llvm::sys::fs::can_execute(ClPath)) { + linkPath = llvm::sys::path::parent_path(ClPath); + llvm::sys::path::append(linkPath, "link.exe"); + if (!llvm::sys::fs::can_execute(linkPath)) + C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found); + } else { + C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found); + } + } #ifdef _WIN32 // When cross-compiling with VS2017 or newer, link.exe expects to have