Skip to content

Commit 02b145a

Browse files
committed
Enabling /ZW (CompileAsWinRT) option for msvs
This change enables someone using gyp to specify the CompileAsWinRT option (i.e. use the /ZW compiler flag). The change also includes: - Test for CompileAsWinRT (change in test/win/compiler-flags) - Enabling Visual Studio 2015 to be targeted by tests (change in testgyp.py) - Detecting Windows SDK version if 'msvs_windows_sdk_version' is used (change in msvs.py) - Enabling arm target architecture to be specified (change in msvs.py) Patch from [email protected]. [email protected] Review URL: https://codereview.chromium.org/1946883002 .
1 parent e24c837 commit 02b145a

6 files changed

Lines changed: 86 additions & 0 deletions

File tree

pylib/gyp/MSVSSettings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ def _ValidateSettings(validators, settings, stderr):
592592
_Same(_compile, 'UseFullPaths', _boolean) # /FC
593593
_Same(_compile, 'WholeProgramOptimization', _boolean) # /GL
594594
_Same(_compile, 'XMLDocumentationFileName', _file_name)
595+
_Same(_compile, 'CompileAsWinRT', _boolean) # /ZW
595596

596597
_Same(_compile, 'AssemblerOutput',
597598
_Enumeration(['NoListing',

pylib/gyp/generator/msvs.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ def _ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset=False):
257257
if not tools.get(tool_name):
258258
tools[tool_name] = dict()
259259
tool = tools[tool_name]
260+
if 'CompileAsWinRT' == setting:
261+
return
260262
if tool.get(setting):
261263
if only_if_unset: return
262264
if type(tool[setting]) == list and type(value) == list:
@@ -286,6 +288,21 @@ def _ConfigFullName(config_name, config_data):
286288
return '%s|%s' % (_ConfigBaseName(config_name, platform_name), platform_name)
287289

288290

291+
def _ConfigWindowsTargetPlatformVersion(config_data):
292+
ver = config_data.get('msvs_windows_sdk_version')
293+
294+
for key in [r'HKLM\Software\Microsoft\Microsoft SDKs\Windows\%s',
295+
r'HKLM\Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows\%s']:
296+
sdk_dir = MSVSVersion._RegistryGetValue(key % ver, 'InstallationFolder')
297+
if not sdk_dir:
298+
continue
299+
version = MSVSVersion._RegistryGetValue(key % ver, 'ProductVersion') or ''
300+
# Find a matching entry in sdk_dir\include.
301+
names = sorted([x for x in os.listdir(r'%s\include' % sdk_dir)
302+
if x.startswith(version)], reverse=True)
303+
return names[0]
304+
305+
289306
def _BuildCommandLineForRuleRaw(spec, cmd, cygwin_shell, has_input_path,
290307
quote_cmd, do_setup_env):
291308

@@ -2676,6 +2693,21 @@ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
26762693
else:
26772694
properties[0].append(['ApplicationType', 'Windows Store'])
26782695

2696+
platform_name = None
2697+
msvs_windows_sdk_version = None
2698+
for configuration in spec['configurations'].itervalues():
2699+
platform_name = platform_name or _ConfigPlatform(configuration)
2700+
msvs_windows_sdk_version = (msvs_windows_sdk_version or
2701+
_ConfigWindowsTargetPlatformVersion(configuration))
2702+
if platform_name and msvs_windows_sdk_version:
2703+
break
2704+
2705+
if platform_name == 'ARM':
2706+
properties[0].append(['WindowsSDKDesktopARMSupport', 'true'])
2707+
if msvs_windows_sdk_version:
2708+
properties[0].append(['WindowsTargetPlatformVersion',
2709+
str(msvs_windows_sdk_version)])
2710+
26792711
return properties
26802712

26812713
def _GetMSBuildConfigurationDetails(spec, build_file):

test/lib/TestGyp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ def FindVisualStudioInstallation():
706706
for drive in range(ord('C'), ord('Z') + 1)
707707
for suffix in ['', ' (x86)']]
708708
possible_paths = {
709+
'2015': r'Microsoft Visual Studio 14.0\Common7\IDE\devenv.com',
709710
'2013': r'Microsoft Visual Studio 12.0\Common7\IDE\devenv.com',
710711
'2012': r'Microsoft Visual Studio 11.0\Common7\IDE\devenv.com',
711712
'2010': r'Microsoft Visual Studio 10.0\Common7\IDE\devenv.com',
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2016 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+
using namespace Platform;
6+
7+
int main() {
8+
wchar_t msg[] = L"Test";
9+
String^ str1 = ref new String(msg);
10+
auto str2 = String::Concat(str1, " Concat");
11+
return 0;
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2016 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+
'targets': [
7+
{
8+
'target_name': 'test-compile-as-winrt',
9+
'type': 'executable',
10+
'msvs_windows_sdk_version': 'v10.0',
11+
'msvs_settings': {
12+
'VCCLCompilerTool': {
13+
'AdditionalUsingDirectories': ['$(VCInstallDir)vcpackages;$(WindowsSdkDir)UnionMetadata;%(AdditionalUsingDirectories)'],
14+
'CompileAsWinRT': 'true'
15+
}
16+
},
17+
'sources': ['compile-as-winrt.cc']
18+
}
19+
]
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2016 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+
import TestGyp
6+
7+
import os
8+
import sys
9+
10+
if (sys.platform == 'win32' and
11+
int(os.environ.get('GYP_MSVS_VERSION', 0)) >= 2015):
12+
test = TestGyp.TestGyp(formats=['msvs'])
13+
14+
CHDIR = 'compiler-flags'
15+
16+
test.run_gyp('compile-as-winrt.gyp', chdir=CHDIR)
17+
18+
test.build('compile-as-winrt.gyp', 'test-compile-as-winrt', chdir=CHDIR)
19+
20+
test.pass_test()

0 commit comments

Comments
 (0)