Skip to content

Commit eca016f

Browse files
committed
Reuse setuptools' logic for plat_dir
1 parent 7d7e3a8 commit eca016f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

setup.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@
7878
# dll_base_address later in this file...
7979
dll_base_address = 0x1E200000
8080

81+
# Same as setuptools._distutils.compilers.C.msvc._vcvars_names
82+
_vcvars_names = {
83+
"win32": "x86",
84+
"win-amd64": "amd64",
85+
"win-arm32": "arm",
86+
"win-arm64": "arm64",
87+
}
88+
8189

8290
class WinExt(Extension):
8391
# Base class for all win32 extensions, with some predefined
@@ -160,18 +168,15 @@ def __init__(
160168
)
161169
self.depends = depends or [] # stash it here, as py22 doesn't have it.
162170

163-
def finalize_options(self, build_ext):
171+
def finalize_options(self, build_ext: my_build_ext) -> None:
164172
# distutils doesn't define this function for an Extension - it is
165173
# our own invention, and called just before the extension is built.
166174
if not build_ext.mingw32:
167175
if self.pch_header:
168176
self.extra_compile_args = self.extra_compile_args or []
169177

170178
# bugger - add this to python!
171-
if build_ext.plat_name == "win32":
172-
self.extra_link_args.append("/MACHINE:x86")
173-
else:
174-
self.extra_link_args.append("/MACHINE:%s" % build_ext.plat_name[4:])
179+
self.extra_link_args.append(f"/MACHINE:{build_ext.plat_dir}")
175180

176181
# like Python, always use debug info, even in release builds
177182
# (note the compiler doesn't include debug info, so you only get
@@ -366,10 +371,7 @@ class my_build_ext(build_ext):
366371
def finalize_options(self):
367372
build_ext.finalize_options(self)
368373

369-
self.plat_dir = {
370-
"win-amd64": "x64",
371-
"win-arm64": "arm64",
372-
}.get(self.plat_name, "x86")
374+
self.plat_dir = _vcvars_names.get(self.plat_name, "x86")
373375

374376
# The pywintypes library is created in the build_temp
375377
# directory, so we need to add this to library_dirs
@@ -608,7 +610,7 @@ def build_extensions(self):
608610
return
609611
if not vcbase:
610612
raise RuntimeError("Can't find MFC redist DLLs with unkown VC base path")
611-
redist_globs = [vcbase + r"redist\%s\*MFC\mfc140u.dll" % self.plat_dir]
613+
redist_globs = [vcbase + r"redist\{}\*MFC\mfc140u.dll".format(self.plat_dir)]
612614
m = re.search(r"\\VC\\Tools\\", vcbase)
613615
if m:
614616
# typical path on newer Visual Studios

0 commit comments

Comments
 (0)