summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Vladu <avladu@cloudbasesolutions.com>2021-03-04 18:59:12 +0200
committerGitHub <noreply@github.com>2021-03-04 08:59:12 -0800
commitcb7bc7640935f6b05e9d2acfe4b33d496e8f8666 (patch)
tree6eb6c908f038e3e8a9d1070fdb0c7e7788b12658
parent40d1b831ecd1b5b6a4fce9a908a6e61b50b360a0 (diff)
downloadcpython-git-cb7bc7640935f6b05e9d2acfe4b33d496e8f8666.tar.gz
bpo-42405: fix C extensions build on Windows ARM64 (GH-23399)
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. Work in progress to remove the hardcoded bits and to change the path query fixes to the proper location. Automerge-Triggered-By: GH:jaraco
-rw-r--r--Lib/distutils/msvc9compiler.py23
-rw-r--r--Misc/NEWS.d/next/Windows/2020-11-23-10-14-03.bpo-42405.4vQUja.rst1
2 files changed, 23 insertions, 1 deletions
diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py
index 6934e964ab..b2b52e56c8 100644
--- a/Lib/distutils/msvc9compiler.py
+++ b/Lib/distutils/msvc9compiler.py
@@ -54,6 +54,7 @@ else:
PLAT_TO_VCVARS = {
'win32' : 'x86',
'win-amd64' : 'amd64',
+ 'win-arm64' : 'arm64',
}
class Reg:
@@ -342,7 +343,7 @@ class MSVCCompiler(CCompiler) :
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,))
@@ -371,6 +372,9 @@ class MSVCCompiler(CCompiler) :
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']
@@ -385,6 +389,12 @@ class MSVCCompiler(CCompiler) :
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')
@@ -634,6 +644,17 @@ class MSVCCompiler(CCompiler) :
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)
diff --git a/Misc/NEWS.d/next/Windows/2020-11-23-10-14-03.bpo-42405.4vQUja.rst b/Misc/NEWS.d/next/Windows/2020-11-23-10-14-03.bpo-42405.4vQUja.rst
new file mode 100644
index 0000000000..9d71c922ab
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2020-11-23-10-14-03.bpo-42405.4vQUja.rst
@@ -0,0 +1 @@
+In distutils, add support for building C extensions on Windows ARM64.