Skip to content

Commit 58fe058

Browse files
authored
Merge pull request #289 from pypa/debt/vs2017
Consolidate VS 2017 support from Setuptools
2 parents b8c70bb + 5f1160f commit 58fe058

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

distutils/_msvccompiler.py

+37-25
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,40 @@ def _find_vc2017():
7979
if not root:
8080
return None, None
8181

82-
try:
83-
path = subprocess.check_output(
84-
[
85-
os.path.join(
86-
root, "Microsoft Visual Studio", "Installer", "vswhere.exe"
87-
),
88-
"-latest",
89-
"-prerelease",
90-
"-requires",
91-
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
92-
"-property",
93-
"installationPath",
94-
"-products",
95-
"*",
96-
],
97-
encoding="mbcs",
98-
errors="strict",
99-
).strip()
100-
except (subprocess.CalledProcessError, OSError, UnicodeDecodeError):
101-
return None, None
82+
variant = 'arm64' if get_platform() == 'win-arm64' else 'x86.x64'
83+
suitable_components = (
84+
f"Microsoft.VisualStudio.Component.VC.Tools.{variant}",
85+
"Microsoft.VisualStudio.Workload.WDExpress",
86+
)
87+
88+
for component in suitable_components:
89+
# Workaround for `-requiresAny` (only available on VS 2017 > 15.6)
90+
with contextlib.suppress(
91+
subprocess.CalledProcessError, OSError, UnicodeDecodeError
92+
):
93+
path = (
94+
subprocess.check_output([
95+
os.path.join(
96+
root, "Microsoft Visual Studio", "Installer", "vswhere.exe"
97+
),
98+
"-latest",
99+
"-prerelease",
100+
"-requires",
101+
component,
102+
"-property",
103+
"installationPath",
104+
"-products",
105+
"*",
106+
])
107+
.decode(encoding="mbcs", errors="strict")
108+
.strip()
109+
)
102110

103-
path = os.path.join(path, "VC", "Auxiliary", "Build")
104-
if os.path.isdir(path):
105-
return 15, path
111+
path = os.path.join(path, "VC", "Auxiliary", "Build")
112+
if os.path.isdir(path):
113+
return 15, path
106114

107-
return None, None
115+
return None, None # no suitable component found
108116

109117

110118
PLAT_SPEC_TO_RUNTIME = {
@@ -140,7 +148,11 @@ def _get_vc_env(plat_spec):
140148

141149
vcvarsall, _ = _find_vcvarsall(plat_spec)
142150
if not vcvarsall:
143-
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
151+
raise DistutilsPlatformError(
152+
'Microsoft Visual C++ 14.0 or greater is required. '
153+
'Get it with "Microsoft C++ Build Tools": '
154+
'https://visualstudio.microsoft.com/visual-cpp-build-tools/'
155+
)
144156

145157
try:
146158
out = subprocess.check_output(

0 commit comments

Comments
 (0)