Skip to content

Commit 0744896

Browse files
committed
msvs: Support ARM64 configuration platform
* This change is intent to support top-level ARM64 configuration, so a project can be built as ARM64 project. * Unit test also included
1 parent 949e8bb commit 0744896

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed

pylib/gyp/MSVS/MSVSSettings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ def _ValidateSettings(validators, settings, stderr):
978978
_Same(_midl, 'TargetEnvironment',
979979
_Enumeration(['NotSet',
980980
'Win32', # /env win32
981+
'ARM64', # /env arm64
981982
'Itanium', # /env ia64
982983
'X64'])) # /env x64
983984
_Same(_midl, 'EnableErrorChecks',

pylib/gyp/generator/msvs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,8 @@ def _InitNinjaFlavor(params, target_list, target_dicts):
18251825
configuration = '$(Configuration)'
18261826
if params.get('target_arch') == 'x64':
18271827
configuration += '_x64'
1828+
if params.get('target_arch') == 'arm64':
1829+
configuration += '_arm64'
18281830
spec['msvs_external_builder_out_dir'] = os.path.join(
18291831
gyp.common.RelativePath(params['options'].toplevel_dir, gyp_dir),
18301832
ninja_generator.ComputeOutputDir(params),

pylib/gyp/msvs_emulation.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ def GetExtension(self):
200200
def GetVSMacroEnv(self, base_to_build=None, config=None):
201201
"""Get a dict of variables mapping internal VS macro names to their gyp
202202
equivalents."""
203-
target_platform = 'Win32' if self.GetArch(config) == 'x86' else 'x64'
203+
target_arch = self.GetArch(config)
204+
if target_arch == 'x86':
205+
target_platform = 'Win32'
206+
else:
207+
target_platform = target_arch
204208
target_name = self.spec.get('product_prefix', '') + self.spec.get('product_name', self.spec['target_name'])
205209
target_dir = base_to_build + '\\' if base_to_build else ''
206210
target_ext = '.' + self.GetExtension()
@@ -276,7 +280,7 @@ def GetArch(self, config):
276280
if not platform: # If no specific override, use the configuration's.
277281
platform = configuration_platform
278282
# Map from platform to architecture.
279-
return {'Win32': 'x86', 'x64': 'x64'}.get(platform, 'x86')
283+
return {'Win32': 'x86', 'x64': 'x64', 'ARM64': 'arm64'}.get(platform, 'x86')
280284

281285
def _TargetConfig(self, config):
282286
"""Returns the target-specific configuration."""
@@ -475,7 +479,10 @@ def GetLibFlags(self, config, gyp_to_build_path):
475479
lib = self._GetWrapper(self, self.msvs_settings[config], 'VCLibrarianTool', append=libflags)
476480
libflags.extend(self._GetAdditionalLibraryDirectories('VCLibrarianTool', config, gyp_to_build_path))
477481
lib('LinkTimeCodeGeneration', map={'true': '/LTCG'})
478-
lib('TargetMachine', map={'1': 'X86', '17': 'X64', '3': 'ARM'}, prefix='/MACHINE:')
482+
# TODO: These 'map' values come from machineTypeOption enum,
483+
# and does not have an official value for ARM64 in VS2017 (yet).
484+
# It needs to verify the ARM64 value when machineTypeOption is updated.
485+
lib('TargetMachine', map={'1': 'X86', '17': 'X64', '3': 'ARM', '18': 'ARM64'}, prefix='/MACHINE:')
479486
lib('AdditionalOptions')
480487
return libflags
481488

@@ -514,7 +521,10 @@ def GetLdflags(self, config, gyp_to_build_path, expand_special, manifest_base_na
514521
ld = self._GetWrapper(self, self.msvs_settings[config], 'VCLinkerTool', append=ldflags)
515522
self._GetDefFileAsLdflags(ldflags, gyp_to_build_path)
516523
ld('GenerateDebugInformation', map={'true': '/DEBUG'})
517-
ld('TargetMachine', map={'1': 'X86', '17': 'X64', '3': 'ARM'}, prefix='/MACHINE:')
524+
# TODO: These 'map' values come from machineTypeOption enum,
525+
# and does not have an official value for ARM64 in VS2017 (yet).
526+
# It needs to verify the ARM64 value when machineTypeOption is updated.
527+
ld('TargetMachine', map={'1': 'X86', '17': 'X64', '3': 'ARM', '18': 'ARM64'}, prefix='/MACHINE:')
518528
ldflags.extend(self._GetAdditionalLibraryDirectories('VCLinkerTool', config, gyp_to_build_path))
519529
ld('DelayLoadDLLs', prefix='/DELAYLOAD:')
520530
ld('TreatLinkerWarningAsErrors', prefix='/WX', map={'true': '', 'false': ':NO'})
@@ -764,7 +774,9 @@ def midl(name, default=None):
764774
output = [header, dlldata, iid, proxy]
765775
variables = [('tlb', tlb), ('h', header), ('dlldata', dlldata), ('iid', iid), ('proxy', proxy)]
766776
# TODO(scottmg): Are there configuration settings to set these flags?
767-
target_platform = 'win32' if self.GetArch(config) == 'x86' else 'x64'
777+
target_platform = self.GetArch(config)
778+
if target_platform == 'x86':
779+
target_platform = 'win32'
768780
flags = ['/char', 'signed', '/env', target_platform, '/Oicf']
769781
return outdir, output, variables, flags
770782

@@ -921,7 +933,7 @@ def GenerateEnvironmentFiles(toplevel_build_dir, generator_flags):
921933
if generator_flags.get('ninja_use_custom_environment_files', False) or not vs.path:
922934
return
923935

924-
archs = ('x86', 'x64')
936+
archs = ('x86', 'x64', 'arm64')
925937
for arch in archs:
926938
env = _GetEnvironment(arch, vs)
927939
env_block = NUL.join(encode(k) + '=' + encode(v) for k, v in env.items()) + NUL + NUL
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main(void) {
4+
printf("Hello ARM64\n");
5+
return 0;
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2009 Google Inc. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
{
6+
'target_defaults': {
7+
'configurations': {
8+
'Debug': {
9+
'msvs_configuration_platform': 'ARM64',
10+
},
11+
},
12+
},
13+
'targets': [
14+
{
15+
'target_name': 'configurationsARM64',
16+
'type': 'executable',
17+
'sources': [
18+
'configurations.c',
19+
],
20+
},
21+
],
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2012 Google Inc. All rights reserved.
4+
# Use of this source code is governed by a BSD-style license that can be
5+
# found in the LICENSE file.
6+
7+
"""
8+
Verifies build of an executable for ARM64 configurations.
9+
"""
10+
11+
import TestGyp
12+
13+
import sys
14+
15+
if sys.platform == 'win32':
16+
formats = ['msvs', 'ninja']
17+
test = TestGyp.TestGyp(formats=formats)
18+
19+
test.run_gyp('configurations.gyp')
20+
test.set_configuration('Debug|ARM64')
21+
test.build('configurations.gyp', test.ALL)
22+
23+
output = test.run_dumpbin('/headers', test.built_file_path('configurations%s.exe' % 'ARM64'))
24+
if 'AA64 machine (ARM64)' not in output:
25+
test.fail_test()
26+
test.pass_test()

0 commit comments

Comments
 (0)