Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msvs: Support ARM64 configuration platform #33

Merged
merged 3 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion gyp/MSVS/MSVSSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,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
3 changes: 1 addition & 2 deletions gyp/MSVS/MSVSVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import os
import glob
from typing import Dict
from gyp.MSVS.MSVSUtil import TryQueryRegistryValue

msvs_version_map = {
Expand Down Expand Up @@ -130,7 +129,7 @@ def SetupScript(self, target_arch):
return script_data


MSVS_VERSIONS = { # type: Dict[str, VisualStudioVersion]
MSVS_VERSIONS = {
'2019':
VisualStudioVersion(
short_name='2019',
Expand Down
4 changes: 3 additions & 1 deletion 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 Expand Up @@ -2563,7 +2565,7 @@ def _GenerateMSBuildRuleXmlFile(xml_path, msbuild_rules):

def _GetConfigurationAndPlatform(name, settings):
configuration = name.rsplit('_', 1)[0]
platform = settings.get('msvs_configuration_platform', 'Win32')
platform = settings.get('msvs_configuration_platform', 'x64')
return configuration, platform


Expand Down
22 changes: 17 additions & 5 deletions 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
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',
],
},
],
}
27 changes: 27 additions & 0 deletions test/configurations/arm64/gyptest-arm64.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/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

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

test.run_gyp('configurations.gyp')
test.set_configuration('Debug|ARM64')
refack marked this conversation as resolved.
Show resolved Hide resolved
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()
4 changes: 2 additions & 2 deletions test/win/gyptest-midl-rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

CHDIR = 'idl-rules'
test.run_gyp('basic-idl.gyp', chdir=CHDIR)
for platform in ['Win32', 'x64']:
for platform in ['Win32', 'x64', 'ARM64']:
test.set_configuration('Debug|%s' % platform)
test.build('basic-idl.gyp', test.ALL, chdir=CHDIR)

# Make sure ninja win_tool.py filters out noisy lines.
if test.format == 'ninja' and 'Processing' in test.stdout():
test.fail_test()

test.pass_test()
test.pass_test()
4 changes: 4 additions & 0 deletions test/win/idl-rules/basic-idl.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
'inherit_from': ['Debug'],
'msvs_configuration_platform': 'x64',
},
'Debug_ARM64': {
'inherit_from': ['Debug'],
'msvs_configuration_platform': 'ARM64',
},
},
},
'targets': [
Expand Down
25 changes: 17 additions & 8 deletions testlib/TestGyp.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ def configuration_dirname(self):
else:
return 'Default'

def configuration_platform(self):
if self.configuration and '|' in self.configuration:
return self.configuration.split('|')[1]
else:
return ''

def configuration_buildname(self):
if self.configuration:
return self.configuration
Expand Down Expand Up @@ -802,7 +808,10 @@ def FindVisualStudioInstallation():
'-requires', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
]
vswhere_json = subprocess.check_output(args1)
top_vs_info = json.loads(vswhere_json)[0]
vswhere_infos = json.loads(vswhere_json)
if len(vswhere_infos) == 0:
raise IOError("vswhere did not find any MSVS instances.")
top_vs_info = vswhere_infos[0]
if top_vs_info:
inst_path = top_vs_info['installationPath']
args2 = ['cmd.exe', '/d', '/c',
Expand Down Expand Up @@ -972,8 +981,6 @@ def build(self, gyp_file, target=None, rebuild=False, clean=False, **kw):
from the specified gyp_file.
"""
if '15.0' in self.build_tool or 'Current' in self.build_tool:
configuration = '/p:Configuration=' + (
self.configuration or self.configuration_buildname())
build = '/t'
if target not in (None, self.ALL, self.DEFAULT):
build += ':' + target
Expand All @@ -984,19 +991,21 @@ def build(self, gyp_file, target=None, rebuild=False, clean=False, **kw):
elif ':' not in build:
build += ':Build'
arguments = kw.get('arguments', [])[:]
arguments.extend([gyp_file.replace('.gyp', '.sln'),
build, configuration])
configuration_arg = '/p:Configuration=%s' % self.configuration_dirname()
arguments.extend([gyp_file.replace('.gyp', '.sln'), build, configuration_arg])
platform = self.configuration_platform()
if platform:
arguments.append('/p:Platform=%s' % platform)
else:
configuration = self.configuration_buildname()
configuration_arg = self.configuration_buildname()
if clean:
build = '/Clean'
elif rebuild:
build = '/Rebuild'
else:
build = '/Build'
arguments = kw.get('arguments', [])[:]
arguments.extend([gyp_file.replace('.gyp', '.sln'),
build, configuration])
arguments.extend([gyp_file.replace('.gyp', '.sln'), build, configuration_arg])
# Note: the Visual Studio generator doesn't add an explicit 'all'
# target, so we just treat it the same as the default.
if target not in (None, self.ALL, self.DEFAULT):
Expand Down