Skip to content

Commit c817d03

Browse files
committed
[WindowsDriver] Always consider WinSdkVersion
Currently, the `-Xmicrosoft-windows-sdk-version` is only used if `-Xmicrosoft-windows-sdk-root` is also provided. This is a surprising behavior since the argument should still be taking effect if LLVM uses the Windows SDK root from the registry. Tested locally in a simple Hello World program including `Windows.h` and compiled with `-Xmicrosoft-windows-sdk-version 10.0.18362.0` on a system where the SDK 10.0.22621.0 is also installed and verified that the correct header was included.
1 parent 21d973d commit c817d03

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

llvm/lib/WindowsDriver/MSVCPaths.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,22 @@ getHighestNumericTupleInDirectory(llvm::vfs::FileSystem &VFS,
8585
return Highest;
8686
}
8787

88-
static bool getWindows10SDKVersionFromPath(llvm::vfs::FileSystem &VFS,
89-
const std::string &SDKPath,
90-
std::string &SDKVersion) {
88+
static bool getWindows10SDKVersionFromPath(
89+
llvm::vfs::FileSystem &VFS, const std::string &SDKPath,
90+
std::optional<llvm::StringRef> WinSdkVersion, std::string &SDKVersion) {
9191
llvm::SmallString<128> IncludePath(SDKPath);
9292
llvm::sys::path::append(IncludePath, "Include");
93+
94+
if (WinSdkVersion) {
95+
// Use the provided version, if it exists.
96+
llvm::SmallString<128> VersionIncludePath(IncludePath);
97+
llvm::sys::path::append(VersionIncludePath, *WinSdkVersion);
98+
if (VFS.exists(VersionIncludePath)) {
99+
SDKVersion = *WinSdkVersion;
100+
return true;
101+
}
102+
}
103+
93104
SDKVersion = getHighestNumericTupleInDirectory(VFS, IncludePath);
94105
return !SDKVersion.empty();
95106
}
@@ -122,7 +133,8 @@ static bool getWindowsSDKDirViaCommandLine(
122133
if (!SDKVersion.empty()) {
123134
Major = SDKVersion.getMajor();
124135
Version = SDKVersion.getAsString();
125-
} else if (getWindows10SDKVersionFromPath(VFS, Path, Version)) {
136+
} else if (getWindows10SDKVersionFromPath(VFS, Path, WinSdkVersion,
137+
Version)) {
126138
Major = 10;
127139
}
128140
return true;
@@ -444,7 +456,8 @@ bool getWindowsSDKDir(vfs::FileSystem &VFS, std::optional<StringRef> WinSdkDir,
444456
return !WindowsSDKLibVersion.empty();
445457
}
446458
if (Major == 10) {
447-
if (!getWindows10SDKVersionFromPath(VFS, Path, WindowsSDKIncludeVersion))
459+
if (!getWindows10SDKVersionFromPath(VFS, Path, WinSdkVersion,
460+
WindowsSDKIncludeVersion))
448461
return false;
449462
WindowsSDKLibVersion = WindowsSDKIncludeVersion;
450463
return true;
@@ -475,7 +488,7 @@ bool getUniversalCRTSdkDir(vfs::FileSystem &VFS,
475488
Path, nullptr))
476489
return false;
477490

478-
return getWindows10SDKVersionFromPath(VFS, Path, UCRTVersion);
491+
return getWindows10SDKVersionFromPath(VFS, Path, WinSdkVersion, UCRTVersion);
479492
}
480493

481494
bool findVCToolChainViaCommandLine(vfs::FileSystem &VFS,

0 commit comments

Comments
 (0)