WinSysRoot, VCToolChainPath, VSLayout) ||
llvm::findVCToolChainViaEnvironment(getVFS(), VCToolChainPath,
VSLayout) ||
- llvm::findVCToolChainViaSetupConfig(getVFS(), VCToolChainPath,
- VSLayout) ||
+ llvm::findVCToolChainViaSetupConfig(getVFS(), VCToolsVersion,
+ VCToolChainPath, VSLayout) ||
llvm::findVCToolChainViaRegistry(VCToolChainPath, VSLayout);
}
llvm::SmallString<128> libPath(sdkPath);
llvm::sys::path::append(libPath, "Lib");
+ if (sdkMajor >= 10)
+ if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
+ WinSdkVersion.has_value())
+ windowsSDKLibVersion = *WinSdkVersion;
if (sdkMajor >= 8)
llvm::sys::path::append(libPath, windowsSDKLibVersion, "um");
return llvm::appendArchToWindowsSDKLibPath(sdkMajor, libPath, getArch(),
UCRTVersion))
return false;
+ if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
+ WinSdkVersion.has_value())
+ UCRTVersion = *WinSdkVersion;
+
StringRef ArchName = llvm::archToWindowsSDKArch(getArch());
if (ArchName.empty())
return false;
if (llvm::getUniversalCRTSdkDir(getVFS(), WinSdkDir, WinSdkVersion,
WinSysRoot, UniversalCRTSdkPath,
UCRTVersion)) {
+ if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
+ WinSdkVersion.has_value())
+ UCRTVersion = *WinSdkVersion;
AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, UniversalCRTSdkPath,
"Include", UCRTVersion, "ucrt");
}
if (llvm::getWindowsSDKDir(getVFS(), WinSdkDir, WinSdkVersion, WinSysRoot,
WindowsSDKDir, major, windowsSDKIncludeVersion,
windowsSDKLibVersion)) {
+ if (major >= 10)
+ if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
+ WinSdkVersion.has_value())
+ windowsSDKIncludeVersion = windowsSDKLibVersion = *WinSdkVersion;
if (major >= 8) {
// Note: windowsSDKIncludeVersion is empty for SDKs prior to v10.
// Anyway, llvm::sys::path::append is able to manage it.
WinSysRoot, vcToolChainPath, vsLayout) &&
(Args.hasArg(OPT_lldignoreenv) ||
!findVCToolChainViaEnvironment(*VFS, vcToolChainPath, vsLayout)) &&
- !findVCToolChainViaSetupConfig(*VFS, vcToolChainPath, vsLayout) &&
+ !findVCToolChainViaSetupConfig(*VFS, {}, vcToolChainPath, vsLayout) &&
!findVCToolChainViaRegistry(vcToolChainPath, vsLayout))
return;
ToolsetLayout &VSLayout);
// Query the Setup Config server for installs, then pick the newest version
-// and find its default VC toolchain.
+// and find its default VC toolchain. If `VCToolsVersion` is specified, that
+// version is preferred over the latest version.
+//
// This is the preferred way to discover new Visual Studios, as they're no
// longer listed in the registry.
-bool findVCToolChainViaSetupConfig(vfs::FileSystem &VFS, std::string &Path,
- ToolsetLayout &VSLayout);
+bool
+findVCToolChainViaSetupConfig(vfs::FileSystem &VFS,
+ std::optional<llvm::StringRef> VCToolsVersion,
+ std::string &Path, ToolsetLayout &VSLayout);
// Look in the registry for Visual Studio installs, and use that to get
// a toolchain path. VS2017 and newer don't get added to the registry.
if (!findVCToolChainViaCommandLine(*VFS, std::nullopt, std::nullopt,
std::nullopt, VCToolChainPath, VSLayout) &&
!findVCToolChainViaEnvironment(*VFS, VCToolChainPath, VSLayout) &&
- !findVCToolChainViaSetupConfig(*VFS, VCToolChainPath, VSLayout) &&
+ !findVCToolChainViaSetupConfig(*VFS, {}, VCToolChainPath, VSLayout) &&
!findVCToolChainViaRegistry(VCToolChainPath, VSLayout))
return make_error<StringError>("Couldn't find msvc toolchain.",
inconvertibleErrorCode());
return false;
}
-bool findVCToolChainViaSetupConfig(vfs::FileSystem &VFS, std::string &Path,
- ToolsetLayout &VSLayout) {
+bool findVCToolChainViaSetupConfig(vfs::FileSystem &VFS,
+ std::optional<StringRef> VCToolsVersion,
+ std::string &Path, ToolsetLayout &VSLayout) {
#if !defined(USE_MSVC_SETUP_API)
return false;
#else
std::string VCRootPath;
convertWideToUTF8(std::wstring(VCPathWide), VCRootPath);
- SmallString<256> ToolsVersionFilePath(VCRootPath);
- sys::path::append(ToolsVersionFilePath, "Auxiliary", "Build",
- "Microsoft.VCToolsVersion.default.txt");
+ std::string ToolsVersion;
+ if (VCToolsVersion.has_value()) {
+ ToolsVersion = *VCToolsVersion;
+ } else {
+ SmallString<256> ToolsVersionFilePath(VCRootPath);
+ sys::path::append(ToolsVersionFilePath, "Auxiliary", "Build",
+ "Microsoft.VCToolsVersion.default.txt");
+
+ auto ToolsVersionFile = MemoryBuffer::getFile(ToolsVersionFilePath);
+ if (!ToolsVersionFile)
+ return false;
+
+ ToolsVersion = ToolsVersionFile->get()->getBuffer().rtrim();
+ }
- auto ToolsVersionFile = MemoryBuffer::getFile(ToolsVersionFilePath);
- if (!ToolsVersionFile)
- return false;
SmallString<256> ToolchainPath(VCRootPath);
- sys::path::append(ToolchainPath, "Tools", "MSVC",
- ToolsVersionFile->get()->getBuffer().rtrim());
+ sys::path::append(ToolchainPath, "Tools", "MSVC", ToolsVersion);
auto Status = VFS.status(ToolchainPath);
if (!Status || !Status->isDirectory())
return false;