Skip to content
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

Improve WinSDK search mechanism #1935

Merged
merged 5 commits into from
Aug 22, 2022
Merged

Conversation

CristiFati
Copy link
Contributor

@CristiFati CristiFati commented Aug 20, 2022

Found this when building for #1928.

Not sure if anyone else ran into this. I must mention that I have 9 different VStudio versions installed (and each one installed its "own" WinSDK version). At some point I did some cleanup (as there were too many WinSDKs), I don't remember if I did that from Programs and Features or from a VStudio installer (in any case I didn't manually alter the paths or registry keys).

Bottom line is that I have a discrepancy between registry and disk (1st entry returned by registry does not exist on disk) and due to (what I consider) a bug in setup.py, I end up in the following situation:

[cfati@CFATI-5510-0:e:\Work\Dev\GitHub\CristiFati\pywin32\src]> dir /b "c:\Program Files (x86)\Windows Kits\10\Include"
10.0.10150.0
10.0.10240.0
10.0.17763.0
10.0.18362.0
10.0.19041.0
10.0.22000.0

[cfati@CFATI-5510-0:e:\Work\Dev\GitHub\CristiFati\pywin32\src]> "e:\Work\Dev\VEnvs\py_pc064_03.09_test0\Scripts\python.exe" setup.py -h
Building pywin32 3.9.304.1
Windows 10 SDK version 10.0.16299.0 is preferred, but that's not installed
Installed versions are ['10.0.17134.0', '10.0.17763.0', '10.0.18362.0', '10.0.19041.0', '10.0.22000.0']
Using 10.0.17134.0
Found Windows sdk in ['C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17134.0\\um'] but it doesn't appear to have windows.h

It looks like you are trying to build pywin32 in an environment without
the necessary tools installed. It's much easier to grab binaries!

Please read the docstring at the top of this file, or read README.md
for more information.

Traceback (most recent call last):
  File "e:\Work\Dev\GitHub\CristiFati\pywin32\src\setup.py", line 156, in <module>
    raise RuntimeError("Can't find the Windows SDK")
RuntimeError: Can't find the Windows SDK

even if I have valid WinSDK version(s).

Besides the fix, I also extracted registry code in a different function (will be easier to maintain in case MS decides to also release 064bit WinSDK versions), and renamed some variables.

This can be worked around by setting MSSDK_* variables, but it should also work OOTB.

Copy link
Owner

@mhammond mhammond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable, thanks!

@mhammond mhammond merged commit f095a26 into mhammond:main Aug 22, 2022
@CristiFati CristiFati deleted the cfati_dev02 branch August 22, 2022 06:50
@kxrob
Copy link
Collaborator

kxrob commented Aug 22, 2022

Note: This required a conflict resolution and rebase of #1936 , which is about to remove the obsolete _fixup_sdk_dirs() mechanism at all, including the find_platform_sdk_dir() and its changes here and the raising of "Can't find the Windows SDK". See also #1897 . Then the distutils mechanism alone will locate the VC & SDK dirs - which searches and uses the "probably best" vcvarsall.bat -> vcvars64.bat etc. (which then uses the up-to-date MS standards) compatible with python in the normative way.

(This should clear up conflicts and mixups of 2 obviously different mechanisms. For the last months at least include & lib dirs of 2 different SDK kits at the same time were seen on compiler command lines on github CI - which resulted from _fixup_sdk_dirs() )

Maybe this removes the initial problem here anyway.
Yet in case the motive for the changes here remains after that, changes / improvements may go into distutils._msvccompiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants