Skip to content

Commit 1a759ba

Browse files
committed
bpo-42405: fix C extensions build on Windows ARM64
The following changes are required: * add a new platform win-arm64 * replace the emulated compiler executable paths * bump the linker base addressed as ARM64 requires more memory this change might not be needed (investigation required) On Windows 10 ARM64, VS compiler paths look like this: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX86\ARM64\cl.exe Note that the cl.exe for ARM64 is an x32 binary, which can run emulated on Windows 10 ARM64 (it has builtin emulation for x32). The rc.exe and mc.exe paths have to also be changed, as the initial discovery has to be fixed.
1 parent 7d9d25d commit 1a759ba

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Lib/distutils/msvc9compiler.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
PLAT_TO_VCVARS = {
5555
'win32' : 'x86',
5656
'win-amd64' : 'amd64',
57+
'win-arm64' : 'arm64',
5758
}
5859

5960
class Reg:
@@ -342,7 +343,7 @@ def initialize(self, plat_name=None):
342343
if plat_name is None:
343344
plat_name = get_platform()
344345
# sanity check for platforms to prevent obscure errors later.
345-
ok_plats = 'win32', 'win-amd64'
346+
ok_plats = 'win32', 'win-amd64', 'win-arm64'
346347
if plat_name not in ok_plats:
347348
raise DistutilsPlatformError("--plat-name must be one of %s" %
348349
(ok_plats,))
@@ -371,6 +372,9 @@ def initialize(self, plat_name=None):
371372
vc_env = query_vcvarsall(VERSION, plat_spec)
372373

373374
self.__paths = vc_env['path'].split(os.pathsep)
375+
if plat_name == 'win-arm64':
376+
self.__paths = (
377+
vc_env['path'].replace('HostX64', 'HostX86').split(os.pathsep))
374378
os.environ['lib'] = vc_env['lib']
375379
os.environ['include'] = vc_env['include']
376380

@@ -385,6 +389,12 @@ def initialize(self, plat_name=None):
385389
self.lib = self.find_exe("lib.exe")
386390
self.rc = self.find_exe("rc.exe") # resource compiler
387391
self.mc = self.find_exe("mc.exe") # message compiler
392+
if plat_name == 'win-arm64':
393+
self.cc = self.cc.replace('HostX64', 'Hostx86')
394+
self.linker = self.linker.replace('HostX64', 'Hostx86')
395+
self.lib = self.lib.replace('HostX64', 'Hostx86')
396+
self.rc = self.rc.replace('x64', 'arm64')
397+
self.mc = self.mc.replace('x64', 'arm64')
388398
#self.set_path_env_var('lib')
389399
#self.set_path_env_var('include')
390400

@@ -634,6 +644,17 @@ def link(self,
634644
if extra_postargs:
635645
ld_args.extend(extra_postargs)
636646

647+
if get_platform() == 'win-arm64':
648+
ld_args_arm = []
649+
for ld_arg in ld_args:
650+
# VS tries to use the x86 linker
651+
ld_arg_arm = ld_arg.replace(r'\um\x86', r'\um\arm64')
652+
# A larger memory address is required on ARM64
653+
ld_arg_arm = ld_arg_arm.replace("0x1", "0x10")
654+
ld_args_arm += [ld_arg_arm]
655+
656+
ld_args = list(ld_args_arm)
657+
637658
self.mkpath(os.path.dirname(output_filename))
638659
try:
639660
self.spawn([self.linker] + ld_args)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix C extensions build on Windows ARM64

0 commit comments

Comments
 (0)