Skip to content

Commit 91744bf

Browse files
richard-townsend-armjoaocgreis
authored andcommitted
gyp: add support for Windows on Arm
Cherry-pick of refack/GYP3#33, supersedes #1678 until GYP3 is merged. `npm test` passes Change-Id: I2b1e1e03e378b4812d34afa527087793864d1576 PR-URL: #1739 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: João Reis <[email protected]>
1 parent 81f3a92 commit 91744bf

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

gyp/pylib/gyp/MSVSSettings.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,9 @@ def _ValidateSettings(validators, settings, stderr):
973973
_Enumeration(['NotSet',
974974
'Win32', # /env win32
975975
'Itanium', # /env ia64
976-
'X64'])) # /env x64
976+
'X64', # /env x64
977+
'ARM64', # /env arm64
978+
]))
977979
_Same(_midl, 'EnableErrorChecks',
978980
_Enumeration(['EnableCustom',
979981
'None', # /error none

gyp/pylib/gyp/generator/msvs.py

+2
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,8 @@ def _InitNinjaFlavor(params, target_list, target_dicts):
18871887
configuration = '$(Configuration)'
18881888
if params.get('target_arch') == 'x64':
18891889
configuration += '_x64'
1890+
if params.get('target_arch') == 'arm64':
1891+
configuration += '_arm64'
18901892
spec['msvs_external_builder_out_dir'] = os.path.join(
18911893
gyp.common.RelativePath(params['options'].toplevel_dir, gyp_dir),
18921894
ninja_generator.ComputeOutputDir(params),

gyp/pylib/gyp/msvs_emulation.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ def GetExtension(self):
237237
def GetVSMacroEnv(self, base_to_build=None, config=None):
238238
"""Get a dict of variables mapping internal VS macro names to their gyp
239239
equivalents."""
240-
target_platform = 'Win32' if self.GetArch(config) == 'x86' else 'x64'
240+
target_arch = self.GetArch(config)
241+
if target_arch == 'x86':
242+
target_platform = 'Win32'
243+
else:
244+
target_platform = target_arch
241245
target_name = self.spec.get('product_prefix', '') + \
242246
self.spec.get('product_name', self.spec['target_name'])
243247
target_dir = base_to_build + '\\' if base_to_build else ''
@@ -299,7 +303,7 @@ def GetArch(self, config):
299303
if not platform: # If no specific override, use the configuration's.
300304
platform = configuration_platform
301305
# Map from platform to architecture.
302-
return {'Win32': 'x86', 'x64': 'x64'}.get(platform, 'x86')
306+
return {'Win32': 'x86', 'x64': 'x64', 'ARM64': 'arm64'}.get(platform, 'x86')
303307

304308
def _TargetConfig(self, config):
305309
"""Returns the target-specific configuration."""
@@ -563,7 +567,10 @@ def GetLdflags(self, config, gyp_to_build_path, expand_special,
563567
'VCLinkerTool', append=ldflags)
564568
self._GetDefFileAsLdflags(ldflags, gyp_to_build_path)
565569
ld('GenerateDebugInformation', map={'true': '/DEBUG'})
566-
ld('TargetMachine', map={'1': 'X86', '17': 'X64', '3': 'ARM'},
570+
# TODO: These 'map' values come from machineTypeOption enum,
571+
# and does not have an official value for ARM64 in VS2017 (yet).
572+
# It needs to verify the ARM64 value when machineTypeOption is updated.
573+
ld('TargetMachine', map={'1': 'X86', '17': 'X64', '3': 'ARM', '18': 'ARM64'},
567574
prefix='/MACHINE:')
568575
ldflags.extend(self._GetAdditionalLibraryDirectories(
569576
'VCLinkerTool', config, gyp_to_build_path))
@@ -860,7 +867,9 @@ def midl(name, default=None):
860867
('iid', iid),
861868
('proxy', proxy)]
862869
# TODO(scottmg): Are there configuration settings to set these flags?
863-
target_platform = 'win32' if self.GetArch(config) == 'x86' else 'x64'
870+
target_platform = self.GetArch(config)
871+
if target_platform == 'x86':
872+
target_platform = 'win32'
864873
flags = ['/char', 'signed', '/env', target_platform, '/Oicf']
865874
return outdir, output, variables, flags
866875

lib/configure.js

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ function configure (gyp, argv, callback) {
134134

135135
// set the target_arch variable
136136
variables.target_arch = gyp.opts.arch || process.arch || 'ia32'
137+
if (variables.target_arch == 'arm64') {
138+
defaults['msvs_configuration_platform'] = 'ARM64'
139+
}
137140

138141
// set the node development directory
139142
variables.nodedir = nodeDir

0 commit comments

Comments
 (0)