Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 46 additions & 29 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,60 +88,77 @@
# dll_base_address later in this file...
dll_base_address = 0x1E200000

# We need to know the platform SDK dir before we can list the extensions.
def find_platform_sdk_dir():
# The user might have their current environment setup for the
# SDK, in which case "MSSDK_INCLUDE" and "MSSDK_LIB" vars must be set.
if "MSSDK_INCLUDE" in os.environ and "MSSDK_LIB" in os.environ:
print("Using SDK as specified in the environment")
return {
"include": os.environ["MSSDK_INCLUDE"].split(os.path.pathsep),
"lib": os.environ["MSSDK_LIB"].split(os.path.pathsep),
}

def registry_data():
# Find the win 10 SDKs installed.
installedVersions = []
root = ""
versions = []
try:
key = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Microsoft\Windows Kits\Installed Roots",
0,
winreg.KEY_READ | winreg.KEY_WOW64_32KEY,
)
installRoot = winreg.QueryValueEx(key, "KitsRoot10")[0]
root = winreg.QueryValueEx(key, "KitsRoot10")[0]
keyNo = 0
while 1:
try:
installedVersions.append(winreg.EnumKey(key, keyNo))
versions.append(winreg.EnumKey(key, keyNo))
keyNo += 1
except winreg.error:
break
except EnvironmentError:
pass
if not installedVersions:
return root, versions


# We need to know the platform SDK dir before we can list the extensions.
def find_platform_sdk_dir():
# The user might have their current environment setup for the
# SDK, in which case "MSSDK_INCLUDE" and "MSSDK_LIB" vars must be set.
if "MSSDK_INCLUDE" in os.environ and "MSSDK_LIB" in os.environ:
print("Using SDK as specified in the environment")
return {
"include": os.environ["MSSDK_INCLUDE"].split(os.path.pathsep),
"lib": os.environ["MSSDK_LIB"].split(os.path.pathsep),
}

install_root, installed_versions = registry_data()
if not installed_versions:
print("Can't find a windows 10 sdk")
return None

# We don't want to automatically used the latest as that's going to always
# be a moving target. Github's automation has "10.0.16299.0", so we target
# that if it exists, otherwise we use the earliest installed version.
ver = "10.0.16299.0"
if ver not in installedVersions:
print("Windows 10 SDK version", ver, "is preferred, but that's not installed")
print("Installed versions are", installedVersions)
ver = installedVersions[0]
print("Using", ver)
# no idea what these 'um' and 'winv6.3' paths actually mean and whether
# hard-coding them is appropriate, but here we are...
include = [os.path.join(installRoot, "include", ver, "um")]
if not os.path.exists(os.path.join(include[0], "windows.h")):
preferred_ver = "10.0.16299.0"
if preferred_ver not in installed_versions:
print(
"Found Windows sdk in", include, "but it doesn't appear to have windows.h"
"Windows 10 SDK version",
preferred_ver,
"is preferred, but that's not installed.",
)
return None
include.append(os.path.join(installRoot, "include", ver, "shared"))
lib = [os.path.join(installRoot, "lib", ver, "um")]
return {"include": include, "lib": lib}
print("Installed versions are", installed_versions)
else:
installed_versions = [e for e in installed_versions if e != preferred_ver]
installed_versions.insert(0, preferred_ver)
user_mode = "um"
for ver in installed_versions:
print("Attempting", ver)
include_base = os.path.join(install_root, "include", ver)
include = [os.path.join(include_base, user_mode)]
if not os.path.exists(os.path.join(include[0], "windows.h")):
print(
"Found Windows sdk in",
include,
"but it doesn't appear to have windows.h",
)
continue
include.append(os.path.join(include_base, "shared"))
lib = [os.path.join(install_root, "lib", ver, user_mode)]
return {"include": include, "lib": lib}
return None # Redundant (for readability)


sdk_info = find_platform_sdk_dir()
Expand Down