Skip to content

Commit

Permalink
gyp: add support for Windows on Arm
Browse files Browse the repository at this point in the history
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 <refack@gmail.com>
Reviewed-By: João Reis <reis@janeasystems.com>
  • Loading branch information
richard-townsend-arm authored and joaocgreis committed May 7, 2019
1 parent 81f3a92 commit 91744bf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion gyp/pylib/gyp/MSVSSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,9 @@ def _ValidateSettings(validators, settings, stderr):
_Enumeration(['NotSet',
'Win32', # /env win32
'Itanium', # /env ia64
'X64'])) # /env x64
'X64', # /env x64
'ARM64', # /env arm64
]))
_Same(_midl, 'EnableErrorChecks',
_Enumeration(['EnableCustom',
'None', # /error none
Expand Down
2 changes: 2 additions & 0 deletions gyp/pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,8 @@ def _InitNinjaFlavor(params, target_list, target_dicts):
configuration = '$(Configuration)'
if params.get('target_arch') == 'x64':
configuration += '_x64'
if params.get('target_arch') == 'arm64':
configuration += '_arm64'
spec['msvs_external_builder_out_dir'] = os.path.join(
gyp.common.RelativePath(params['options'].toplevel_dir, gyp_dir),
ninja_generator.ComputeOutputDir(params),
Expand Down
17 changes: 13 additions & 4 deletions gyp/pylib/gyp/msvs_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ def GetExtension(self):
def GetVSMacroEnv(self, base_to_build=None, config=None):
"""Get a dict of variables mapping internal VS macro names to their gyp
equivalents."""
target_platform = 'Win32' if self.GetArch(config) == 'x86' else 'x64'
target_arch = self.GetArch(config)
if target_arch == 'x86':
target_platform = 'Win32'
else:
target_platform = target_arch
target_name = self.spec.get('product_prefix', '') + \
self.spec.get('product_name', self.spec['target_name'])
target_dir = base_to_build + '\\' if base_to_build else ''
Expand Down Expand Up @@ -299,7 +303,7 @@ def GetArch(self, config):
if not platform: # If no specific override, use the configuration's.
platform = configuration_platform
# Map from platform to architecture.
return {'Win32': 'x86', 'x64': 'x64'}.get(platform, 'x86')
return {'Win32': 'x86', 'x64': 'x64', 'ARM64': 'arm64'}.get(platform, 'x86')

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

Expand Down
3 changes: 3 additions & 0 deletions lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ function configure (gyp, argv, callback) {

// set the target_arch variable
variables.target_arch = gyp.opts.arch || process.arch || 'ia32'
if (variables.target_arch == 'arm64') {
defaults['msvs_configuration_platform'] = 'ARM64'
}

// set the node development directory
variables.nodedir = nodeDir
Expand Down

0 comments on commit 91744bf

Please sign in to comment.