Skip to content

Commit 652a346

Browse files
larseggertcclauss
andauthored
feat: Windows ARM64 target architecture support (#331)
* feat: ARM64 target architecture support Extend the MSVC toolchain integration to support Windows ARM64 targets. (I know very little about gyp, so these changes may be a bit rough. They were enough to get NSS building on Windows 11/ARM in CI via mozilla/neqo#2591. Please let me know if anything needs changing!) * Update pylib/gyp/MSVSVersion.py Co-authored-by: Christian Clauss <cclauss@me.com> --------- Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent d20198e commit 652a346

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

pylib/gyp/MSVSVersion.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def DefaultToolset(self):
8787
def _SetupScriptInternal(self, target_arch):
8888
"""Returns a command (with arguments) to be used to set up the
8989
environment."""
90-
assert target_arch in ("x86", "x64"), "target_arch not supported"
90+
assert target_arch in ("x86", "x64", "arm64"), "target_arch not supported"
9191
# If WindowsSDKDir is set and SetEnv.Cmd exists then we are using the
9292
# depot_tools build tools and should run SetEnv.Cmd to set up the
9393
# environment. The check for WindowsSDKDir alone is not sufficient because
@@ -109,8 +109,16 @@ def _SetupScriptInternal(self, target_arch):
109109
)
110110

111111
# Always use a native executable, cross-compiling if necessary.
112-
host_arch = "amd64" if is_host_arch_x64 else "x86"
113-
msvc_target_arch = "amd64" if target_arch == "x64" else "x86"
112+
host_arch = (
113+
"amd64"
114+
if is_host_arch_x64
115+
else (
116+
"arm64"
117+
if os.environ.get("PROCESSOR_ARCHITECTURE") == "ARM64"
118+
else "x86"
119+
)
120+
)
121+
msvc_target_arch = {"x64": "amd64"}.get(target_arch, target_arch)
114122
arg = host_arch
115123
if host_arch != msvc_target_arch:
116124
arg += "_" + msvc_target_arch

pylib/gyp/generator/ninja.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def __init__(
246246
if flavor == "win":
247247
# See docstring of msvs_emulation.GenerateEnvironmentFiles().
248248
self.win_env = {}
249-
for arch in ("x86", "x64"):
249+
for arch in ("x86", "x64", "arm64"):
250250
self.win_env[arch] = "environment." + arch
251251

252252
# Relative path from build output dir to base dir.
@@ -2339,6 +2339,7 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
23392339
master_ninja.variable("rc", "rc.exe")
23402340
master_ninja.variable("ml_x86", "ml.exe")
23412341
master_ninja.variable("ml_x64", "ml64.exe")
2342+
master_ninja.variable("ml_arm64", "armasm64.exe")
23422343
master_ninja.variable("mt", "mt.exe")
23432344
else:
23442345
master_ninja.variable("ld", CommandWithWrapper("LINK", wrappers, ld))

pylib/gyp/msvs_emulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ def GenerateEnvironmentFiles(
11741174
meet your requirement (e.g. for custom toolchains), you can pass
11751175
"-G ninja_use_custom_environment_files" to the gyp to suppress file
11761176
generation and use custom environment files prepared by yourself."""
1177-
archs = ("x86", "x64")
1177+
archs = ("x86", "x64", "arm64")
11781178
if generator_flags.get("ninja_use_custom_environment_files", 0):
11791179
cl_paths = {}
11801180
for arch in archs:

0 commit comments

Comments
 (0)