Skip to content

Commit 196d44b

Browse files
committed
Apply downstream VS 2017 support.
Ref pypa/setuptools#2663 and pypa/setuptools#3950 and pypa/setuptools#4600
1 parent 23e3bfa commit 196d44b

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

distutils/_msvccompiler.py

+32-24
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 = {

0 commit comments

Comments
 (0)