-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[WindowsDriver] Always consider WinSdkVersion
#130377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WindowsDriver] Always consider WinSdkVersion
#130377
Conversation
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.
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-platform-windows Author: Fabrice de Gans (Steelskin) ChangesCurrently, the Tested locally in a simple Hello World program including Full diff: https://github.com/llvm/llvm-project/pull/130377.diff 1 Files Affected:
diff --git a/llvm/lib/WindowsDriver/MSVCPaths.cpp b/llvm/lib/WindowsDriver/MSVCPaths.cpp
index a7bffbb20eba1..60fc096059c62 100644
--- a/llvm/lib/WindowsDriver/MSVCPaths.cpp
+++ b/llvm/lib/WindowsDriver/MSVCPaths.cpp
@@ -85,11 +85,22 @@ getHighestNumericTupleInDirectory(llvm::vfs::FileSystem &VFS,
return Highest;
}
-static bool getWindows10SDKVersionFromPath(llvm::vfs::FileSystem &VFS,
- const std::string &SDKPath,
- std::string &SDKVersion) {
+static bool getWindows10SDKVersionFromPath(
+ llvm::vfs::FileSystem &VFS, const std::string &SDKPath,
+ std::optional<llvm::StringRef> WinSdkVersion, std::string &SDKVersion) {
llvm::SmallString<128> IncludePath(SDKPath);
llvm::sys::path::append(IncludePath, "Include");
+
+ if (WinSdkVersion) {
+ // Use the provided version, if it exists.
+ llvm::SmallString<128> VersionIncludePath(IncludePath);
+ llvm::sys::path::append(VersionIncludePath, *WinSdkVersion);
+ if (VFS.exists(VersionIncludePath)) {
+ SDKVersion = *WinSdkVersion;
+ return true;
+ }
+ }
+
SDKVersion = getHighestNumericTupleInDirectory(VFS, IncludePath);
return !SDKVersion.empty();
}
@@ -122,7 +133,8 @@ static bool getWindowsSDKDirViaCommandLine(
if (!SDKVersion.empty()) {
Major = SDKVersion.getMajor();
Version = SDKVersion.getAsString();
- } else if (getWindows10SDKVersionFromPath(VFS, Path, Version)) {
+ } else if (getWindows10SDKVersionFromPath(VFS, Path, WinSdkVersion,
+ Version)) {
Major = 10;
}
return true;
@@ -444,7 +456,8 @@ bool getWindowsSDKDir(vfs::FileSystem &VFS, std::optional<StringRef> WinSdkDir,
return !WindowsSDKLibVersion.empty();
}
if (Major == 10) {
- if (!getWindows10SDKVersionFromPath(VFS, Path, WindowsSDKIncludeVersion))
+ if (!getWindows10SDKVersionFromPath(VFS, Path, WinSdkVersion,
+ WindowsSDKIncludeVersion))
return false;
WindowsSDKLibVersion = WindowsSDKIncludeVersion;
return true;
@@ -475,7 +488,7 @@ bool getUniversalCRTSdkDir(vfs::FileSystem &VFS,
Path, nullptr))
return false;
- return getWindows10SDKVersionFromPath(VFS, Path, UCRTVersion);
+ return getWindows10SDKVersionFromPath(VFS, Path, WinSdkVersion, UCRTVersion);
}
bool findVCToolChainViaCommandLine(vfs::FileSystem &VFS,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we should do this check this way. Similar to the other arguments if the user specifies the value, we should assume that it is correct rather than basing it on a check that the path exists.
Skip checking that the directory actually exists, trust the user input.
Thanks, I changed it so we always just use the user-provided version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to redo the static functions in this file to take pointers to the arguments rather than pass by reference. It makes it confusing to see which call modifies what.
But I have no idea what the LLVM style recommends.
Do we have any tests for these codepaths, and if not, would it be feasible to add some? |
I think that I convinced myself that there is no good way to test this. The reason is that we want to honour |
Spoke with @mstorsjo "offline" - came to agreement that this is difficult to test. |
As @compnerd mentioned, this is relying on the installation environment. Does LLVM have test facilities for faking the registry and the file system? Otherwise, this is going to require a refactor of this file so we can inject a fake Windows SDK installation path for testing purposes. |
@Steelskin Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/94/builds/5181 Here is the relevant piece of the build log for the reference
|
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. Co-authored-by: Saleem Abdulrasool <[email protected]> (cherrry picked from commit [606e9fa](swiftlang@606e9fa)
…version 🍒 [WindowsDriver] Always consider `WinSdkVersion` (llvm#130377)
Cherry-picked from llvm#10240 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. Co-authored-by: Saleem Abdulrasool <[email protected]> (cherrry picked from commit [606e9fa](swiftlang@606e9fa)
🍒 [WindowsDriver] Always consider `WinSdkVersion` (llvm#130377)
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.