Skip to content

Commit

Permalink
msvs: Support ARM64 configuration platform
Browse files Browse the repository at this point in the history
* This change is intent to support top-level ARM64 configuration, so a
project can be built as ARM64 project.
* Unit test also included
  • Loading branch information
kaadam committed Mar 14, 2019
1 parent 949e8bb commit 0744896
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 6 deletions.
1 change: 1 addition & 0 deletions pylib/gyp/MSVS/MSVSSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ def _ValidateSettings(validators, settings, stderr):
_Same(_midl, 'TargetEnvironment',
_Enumeration(['NotSet',
'Win32', # /env win32
'ARM64', # /env arm64
'Itanium', # /env ia64
'X64'])) # /env x64
_Same(_midl, 'EnableErrorChecks',
Expand Down
2 changes: 2 additions & 0 deletions pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,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
24 changes: 18 additions & 6 deletions pylib/gyp/msvs_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,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 ''
target_ext = '.' + self.GetExtension()
Expand Down Expand Up @@ -276,7 +280,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 @@ -475,7 +479,10 @@ def GetLibFlags(self, config, gyp_to_build_path):
lib = self._GetWrapper(self, self.msvs_settings[config], 'VCLibrarianTool', append=libflags)
libflags.extend(self._GetAdditionalLibraryDirectories('VCLibrarianTool', config, gyp_to_build_path))
lib('LinkTimeCodeGeneration', map={'true': '/LTCG'})
lib('TargetMachine', map={'1': 'X86', '17': 'X64', '3': 'ARM'}, prefix='/MACHINE:')
# 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.
lib('TargetMachine', map={'1': 'X86', '17': 'X64', '3': 'ARM', '18': 'ARM64'}, prefix='/MACHINE:')
lib('AdditionalOptions')
return libflags

Expand Down Expand Up @@ -514,7 +521,10 @@ def GetLdflags(self, config, gyp_to_build_path, expand_special, manifest_base_na
ld = self._GetWrapper(self, self.msvs_settings[config], 'VCLinkerTool', append=ldflags)
self._GetDefFileAsLdflags(ldflags, gyp_to_build_path)
ld('GenerateDebugInformation', map={'true': '/DEBUG'})
ld('TargetMachine', map={'1': 'X86', '17': 'X64', '3': 'ARM'}, prefix='/MACHINE:')
# 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))
ld('DelayLoadDLLs', prefix='/DELAYLOAD:')
ld('TreatLinkerWarningAsErrors', prefix='/WX', map={'true': '', 'false': ':NO'})
Expand Down Expand Up @@ -764,7 +774,9 @@ def midl(name, default=None):
output = [header, dlldata, iid, proxy]
variables = [('tlb', tlb), ('h', header), ('dlldata', dlldata), ('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 Expand Up @@ -921,7 +933,7 @@ def GenerateEnvironmentFiles(toplevel_build_dir, generator_flags):
if generator_flags.get('ninja_use_custom_environment_files', False) or not vs.path:
return

archs = ('x86', 'x64')
archs = ('x86', 'x64', 'arm64')
for arch in archs:
env = _GetEnvironment(arch, vs)
env_block = NUL.join(encode(k) + '=' + encode(v) for k, v in env.items()) + NUL + NUL
Expand Down
6 changes: 6 additions & 0 deletions test/configurations/arm64/configurations.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

int main(void) {
printf("Hello ARM64\n");
return 0;
}
22 changes: 22 additions & 0 deletions test/configurations/arm64/configurations.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2009 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

{
'target_defaults': {
'configurations': {
'Debug': {
'msvs_configuration_platform': 'ARM64',
},
},
},
'targets': [
{
'target_name': 'configurationsARM64',
'type': 'executable',
'sources': [
'configurations.c',
],
},
],
}
26 changes: 26 additions & 0 deletions test/configurations/arm64/gyptest-arm64.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python

# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Verifies build of an executable for ARM64 configurations.
"""

import TestGyp

import sys

if sys.platform == 'win32':
formats = ['msvs', 'ninja']
test = TestGyp.TestGyp(formats=formats)

test.run_gyp('configurations.gyp')
test.set_configuration('Debug|ARM64')
test.build('configurations.gyp', test.ALL)

output = test.run_dumpbin('/headers', test.built_file_path('configurations%s.exe' % 'ARM64'))
if 'AA64 machine (ARM64)' not in output:
test.fail_test()
test.pass_test()

0 comments on commit 0744896

Please sign in to comment.