https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/236691
Backport e41fd4ca37f3a3a59e913ca68a07742967a4bfe2 Requested by: @mstorsjo >From 5fde63a44aa6b140b3e167de0117e4d697bc912c Mon Sep 17 00:00:00 2001 From: ykiko <[email protected]> Date: Thu, 29 Oct 2026 01:23:49 +0800 Subject: [PATCH] [WindowsDriver] Find Visual Studio through the Setup API on MinGW (#226794) The Setup API lookup of Visual Studio 2017 and later has been limited to MSVC builds since 545202b8f186. A MinGW-built clang, and every tool built on its libraries, finds Visual Studio 2017 and later only from a Developer Command Prompt (`VCToolsInstallDir` or `cl.exe` in `PATH`); otherwise it falls back to the registry and to the directories of Visual Studio 2010 to 2005. Use the Setup API on all Windows hosts. mingw-w64 has the `comdef.h` and COM smart pointers the lookup uses; the `_Deref_out_opt_` annotation in `sal.h` and the definitions of `_set_com_error_handler` and `_com_raise_error` in `comdef.h` are there since mingw-w64 v10.0.0. LLVM already needs that version: `llvm/lib/Support/raw_socket_stream.cpp` includes `afunix.h`, also new in v10.0.0. mingw-w64's `__uuidof` is emulated and takes the interface IDs from `__CRT_UUID_DECL`; declare them next to the include, so that `MSVCSetupApi.h` stays as Microsoft ships it. ole32 and oleaut32 come from CMake's default libraries on Windows. (cherry picked from commit e41fd4ca37f3a3a59e913ca68a07742967a4bfe2) --- llvm/lib/WindowsDriver/MSVCPaths.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/llvm/lib/WindowsDriver/MSVCPaths.cpp b/llvm/lib/WindowsDriver/MSVCPaths.cpp index 09468dab102605..ec3ad7dfb3154f 100644 --- a/llvm/lib/WindowsDriver/MSVCPaths.cpp +++ b/llvm/lib/WindowsDriver/MSVCPaths.cpp @@ -33,11 +33,6 @@ #define NOMINMAX #endif #include <windows.h> -#endif - -#ifdef _MSC_VER -// Don't support SetupApi on MinGW. -#define USE_MSVC_SETUP_API // Make sure this comes before MSVCSetupApi.h #include <comdef.h> @@ -51,6 +46,24 @@ #ifdef __clang__ #pragma clang diagnostic pop #endif +#ifdef __MINGW32__ +// mingw-w64 emulates __uuidof, which takes the IIDs from __CRT_UUID_DECL +// rather than from the DECLSPEC_UUID in MSVCSetupApi.h. +__CRT_UUID_DECL(ISetupInstance, 0xB41463C3, 0x8866, 0x43B5, 0xBC, 0x33, 0x2B, + 0x06, 0x76, 0xF7, 0xF4, 0x2E) +__CRT_UUID_DECL(ISetupInstance2, 0x89143C9A, 0x05AF, 0x49B0, 0xB7, 0x17, 0x72, + 0xE2, 0x18, 0xA2, 0x18, 0x5C) +__CRT_UUID_DECL(IEnumSetupInstances, 0x6380BCFF, 0x41D3, 0x4B2E, 0x8B, 0x2E, + 0xBF, 0x8A, 0x68, 0x10, 0xC8, 0x48) +__CRT_UUID_DECL(ISetupConfiguration, 0x42843719, 0xDB4C, 0x46C2, 0x8E, 0x7C, + 0x64, 0xF1, 0x81, 0x6E, 0xFD, 0x5B) +__CRT_UUID_DECL(ISetupConfiguration2, 0x26AAB78C, 0x4A60, 0x49D6, 0xAF, 0x3B, + 0x3C, 0x35, 0xBC, 0x93, 0x36, 0x5D) +__CRT_UUID_DECL(ISetupHelper, 0x42B21B78, 0x6192, 0x463E, 0x87, 0xBF, 0xD5, + 0x77, 0x83, 0x8F, 0x1D, 0x5C) +__CRT_UUID_DECL(SetupConfiguration, 0x177F0C4A, 0x1CD3, 0x4DE7, 0xA3, 0x2C, + 0x71, 0xDB, 0xBB, 0x9F, 0xA3, 0x6D) +#endif _COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration)); _COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2)); _COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper)); @@ -634,7 +647,7 @@ bool llvm::findVCToolChainViaEnvironment(vfs::FileSystem &VFS, bool llvm::findVCToolChainViaSetupConfig( vfs::FileSystem &VFS, std::optional<StringRef> VCToolsVersion, std::string &Path, ToolsetLayout &VSLayout) { -#if !defined(USE_MSVC_SETUP_API) +#ifndef _WIN32 return false; #else // FIXME: This really should be done once in the top-level program's main _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
