Skip to content

bpo-42405: fix C extensions build on Windows ARM64 #23399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
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
23 changes: 22 additions & 1 deletion Lib/distutils/msvc9compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
PLAT_TO_VCVARS = {
'win32' : 'x86',
'win-amd64' : 'amd64',
'win-arm64' : 'arm64',
}

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

self.__paths = vc_env['path'].split(os.pathsep)
if plat_name == 'win-arm64':
self.__paths = (
vc_env['path'].replace('HostX64', 'HostX86').split(os.pathsep))
os.environ['lib'] = vc_env['lib']
os.environ['include'] = vc_env['include']

Expand All @@ -385,6 +389,12 @@ def initialize(self, plat_name=None):
self.lib = self.find_exe("lib.exe")
self.rc = self.find_exe("rc.exe") # resource compiler
self.mc = self.find_exe("mc.exe") # message compiler
if plat_name == 'win-arm64':
self.cc = self.cc.replace('HostX64', 'Hostx86')
self.linker = self.linker.replace('HostX64', 'Hostx86')
self.lib = self.lib.replace('HostX64', 'Hostx86')
self.rc = self.rc.replace('x64', 'arm64')
self.mc = self.mc.replace('x64', 'arm64')
#self.set_path_env_var('lib')
#self.set_path_env_var('include')

Expand Down Expand Up @@ -634,6 +644,17 @@ def link(self,
if extra_postargs:
ld_args.extend(extra_postargs)

if get_platform() == 'win-arm64':
ld_args_arm = []
for ld_arg in ld_args:
# VS tries to use the x86 linker
ld_arg_arm = ld_arg.replace(r'\um\x86', r'\um\arm64')
# A larger memory address is required on ARM64
ld_arg_arm = ld_arg_arm.replace("0x1", "0x10")
ld_args_arm += [ld_arg_arm]

ld_args = list(ld_args_arm)

self.mkpath(os.path.dirname(output_filename))
try:
self.spawn([self.linker] + ld_args)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In distutils, add support for building C extensions on Windows ARM64.