40
40
# letters.
41
41
VALID_MSVS_GUID_CHARS = re .compile (r'^[A-F0-9\-]+$' )
42
42
43
+ generator_supports_multiple_toolsets = gyp .common .CrossCompileRequested ()
43
44
44
45
generator_default_variables = {
45
46
'DRIVER_PREFIX' : '' ,
51
52
'STATIC_LIB_SUFFIX' : '.lib' ,
52
53
'SHARED_LIB_SUFFIX' : '.dll' ,
53
54
'INTERMEDIATE_DIR' : '$(IntDir)' ,
54
- 'SHARED_INTERMEDIATE_DIR' : '$(OutDir)obj/global_intermediate' ,
55
+ 'SHARED_INTERMEDIATE_DIR' : '$(OutDir)/ obj/global_intermediate' ,
55
56
'OS' : 'win' ,
56
57
'PRODUCT_DIR' : '$(OutDir)' ,
57
58
'LIB_DIR' : '$(OutDir)lib' ,
@@ -286,7 +287,7 @@ def _ConfigTargetVersion(config_data):
286
287
return config_data .get ('msvs_target_version' , 'Windows7' )
287
288
288
289
289
- def _ConfigPlatform (config_data ):
290
+ def _ConfigPlatform (config_data , spec ):
290
291
return config_data .get ('msvs_configuration_platform' , 'Win32' )
291
292
292
293
@@ -297,8 +298,8 @@ def _ConfigBaseName(config_name, platform_name):
297
298
return config_name
298
299
299
300
300
- def _ConfigFullName (config_name , config_data ):
301
- platform_name = _ConfigPlatform (config_data )
301
+ def _ConfigFullName (config_name , config_data , spec ):
302
+ platform_name = _ConfigPlatform (config_data , spec )
302
303
return '%s|%s' % (_ConfigBaseName (config_name , platform_name ), platform_name )
303
304
304
305
@@ -951,7 +952,7 @@ def _GetMsbuildToolsetOfProject(proj_path, spec, version):
951
952
return toolset
952
953
953
954
954
- def _GenerateProject (project , options , version , generator_flags ):
955
+ def _GenerateProject (project , options , version , generator_flags , spec ):
955
956
"""Generates a vcproj file.
956
957
957
958
Arguments:
@@ -969,7 +970,7 @@ def _GenerateProject(project, options, version, generator_flags):
969
970
return []
970
971
971
972
if version .UsesVcxproj ():
972
- return _GenerateMSBuildProject (project , options , version , generator_flags )
973
+ return _GenerateMSBuildProject (project , options , version , generator_flags , spec )
973
974
else :
974
975
return _GenerateMSVSProject (project , options , version , generator_flags )
975
976
@@ -1091,7 +1092,7 @@ def _GetUniquePlatforms(spec):
1091
1092
# Gather list of unique platforms.
1092
1093
platforms = OrderedSet ()
1093
1094
for configuration in spec ['configurations' ]:
1094
- platforms .add (_ConfigPlatform (spec ['configurations' ][configuration ]))
1095
+ platforms .add (_ConfigPlatform (spec ['configurations' ][configuration ], spec ))
1095
1096
platforms = list (platforms )
1096
1097
return platforms
1097
1098
@@ -1801,6 +1802,8 @@ def _GatherSolutionFolders(sln_projects, project_objects, flat):
1801
1802
# Convert into a tree of dicts on path.
1802
1803
for p in sln_projects :
1803
1804
gyp_file , target = gyp .common .ParseQualifiedTarget (p )[0 :2 ]
1805
+ if p .endswith ("#host" ):
1806
+ target += "_host"
1804
1807
gyp_dir = os .path .dirname (gyp_file )
1805
1808
path_dict = _GetPathDict (root , gyp_dir )
1806
1809
path_dict [target + '.vcproj' ] = project_objects [p ]
@@ -1819,7 +1822,10 @@ def _GetPathOfProject(qualified_target, spec, options, msvs_version):
1819
1822
default_config = _GetDefaultConfiguration (spec )
1820
1823
proj_filename = default_config .get ('msvs_existing_vcproj' )
1821
1824
if not proj_filename :
1822
- proj_filename = (spec ['target_name' ] + options .suffix +
1825
+ proj_filename = spec ['target_name' ]
1826
+ if spec ['toolset' ] == 'host' :
1827
+ proj_filename += "_host"
1828
+ proj_filename = (proj_filename + options .suffix +
1823
1829
msvs_version .ProjectExtension ())
1824
1830
1825
1831
build_file = gyp .common .BuildFile (qualified_target )
@@ -1838,10 +1844,12 @@ def _GetPlatformOverridesOfProject(spec):
1838
1844
# solution configurations for this target.
1839
1845
config_platform_overrides = {}
1840
1846
for config_name , c in spec ['configurations' ].items ():
1841
- config_fullname = _ConfigFullName (config_name , c )
1842
- platform = c .get ('msvs_target_platform' , _ConfigPlatform (c ))
1847
+ config_fullname = _ConfigFullName (config_name , c , spec )
1848
+ platform = c .get ('msvs_target_platform' , _ConfigPlatform (c , spec ))
1843
1849
fixed_config_fullname = '%s|%s' % (
1844
- _ConfigBaseName (config_name , _ConfigPlatform (c )), platform )
1850
+ _ConfigBaseName (config_name , _ConfigPlatform (c , spec )), platform )
1851
+ if spec ['toolset' ] == 'host' and generator_supports_multiple_toolsets :
1852
+ fixed_config_fullname = '%s|x64' % (config_name ,)
1845
1853
config_platform_overrides [config_fullname ] = fixed_config_fullname
1846
1854
return config_platform_overrides
1847
1855
@@ -1862,19 +1870,18 @@ def _CreateProjectObjects(target_list, target_dicts, options, msvs_version):
1862
1870
projects = {}
1863
1871
for qualified_target in target_list :
1864
1872
spec = target_dicts [qualified_target ]
1865
- if spec ['toolset' ] != 'target' :
1866
- raise GypError (
1867
- 'Multiple toolsets not supported in msvs build (target %s)' %
1868
- qualified_target )
1869
1873
proj_path , fixpath_prefix = _GetPathOfProject (qualified_target , spec ,
1870
1874
options , msvs_version )
1871
1875
guid = _GetGuidOfProject (proj_path , spec )
1872
1876
overrides = _GetPlatformOverridesOfProject (spec )
1873
1877
build_file = gyp .common .BuildFile (qualified_target )
1874
1878
# Create object for this project.
1879
+ target_name = spec ['target_name' ]
1880
+ if spec ['toolset' ] == 'host' :
1881
+ target_name += '_host'
1875
1882
obj = MSVSNew .MSVSProject (
1876
1883
proj_path ,
1877
- name = spec [ ' target_name' ] ,
1884
+ name = target_name ,
1878
1885
guid = guid ,
1879
1886
spec = spec ,
1880
1887
build_file = build_file ,
@@ -2041,7 +2048,10 @@ def GenerateOutput(target_list, target_dicts, data, params):
2041
2048
for qualified_target in target_list :
2042
2049
spec = target_dicts [qualified_target ]
2043
2050
for config_name , config in spec ['configurations' ].items ():
2044
- configs .add (_ConfigFullName (config_name , config ))
2051
+ config_name = _ConfigFullName (config_name , config , spec )
2052
+ configs .add (config_name )
2053
+ if config_name == 'Release|arm64' :
2054
+ configs .add ("Release|x64" )
2045
2055
configs = list (configs )
2046
2056
2047
2057
# Figure out all the projects that will be generated and their guids
@@ -2053,11 +2063,14 @@ def GenerateOutput(target_list, target_dicts, data, params):
2053
2063
for project in project_objects .values ():
2054
2064
fixpath_prefix = project .fixpath_prefix
2055
2065
missing_sources .extend (_GenerateProject (project , options , msvs_version ,
2056
- generator_flags ))
2066
+ generator_flags , spec ))
2057
2067
fixpath_prefix = None
2058
2068
2059
2069
for build_file in data :
2060
2070
# Validate build_file extension
2071
+ target_only_configs = configs
2072
+ if generator_supports_multiple_toolsets :
2073
+ target_only_configs = [i for i in configs if i .endswith ('arm64' )]
2061
2074
if not build_file .endswith ('.gyp' ):
2062
2075
continue
2063
2076
sln_path = os .path .splitext (build_file )[0 ] + options .suffix + '.sln'
@@ -2072,7 +2085,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
2072
2085
# Create solution.
2073
2086
sln = MSVSNew .MSVSSolution (sln_path ,
2074
2087
entries = root_entries ,
2075
- variants = configs ,
2088
+ variants = target_only_configs ,
2076
2089
websiteProperties = False ,
2077
2090
version = msvs_version )
2078
2091
sln .Write ()
@@ -2674,21 +2687,23 @@ def _GenerateMSBuildRuleXmlFile(xml_path, msbuild_rules):
2674
2687
easy_xml .WriteXmlIfChanged (content , xml_path , pretty = True , win32 = True )
2675
2688
2676
2689
2677
- def _GetConfigurationAndPlatform (name , settings ):
2690
+ def _GetConfigurationAndPlatform (name , settings , spec ):
2678
2691
configuration = name .rsplit ('_' , 1 )[0 ]
2679
2692
platform = settings .get ('msvs_configuration_platform' , 'Win32' )
2693
+ if spec ['toolset' ] == 'host' and platform == 'arm64' :
2694
+ platform = 'x64' # Host-only tools are always built for x64
2680
2695
return (configuration , platform )
2681
2696
2682
2697
2683
- def _GetConfigurationCondition (name , settings ):
2698
+ def _GetConfigurationCondition (name , settings , spec ):
2684
2699
return (r"'$(Configuration)|$(Platform)'=='%s|%s'" %
2685
- _GetConfigurationAndPlatform (name , settings ))
2700
+ _GetConfigurationAndPlatform (name , settings , spec ))
2686
2701
2687
2702
2688
- def _GetMSBuildProjectConfigurations (configurations ):
2703
+ def _GetMSBuildProjectConfigurations (configurations , spec ):
2689
2704
group = ['ItemGroup' , {'Label' : 'ProjectConfigurations' }]
2690
2705
for (name , settings ) in sorted (configurations .items ()):
2691
- configuration , platform = _GetConfigurationAndPlatform (name , settings )
2706
+ configuration , platform = _GetConfigurationAndPlatform (name , settings , spec )
2692
2707
designation = '%s|%s' % (configuration , platform )
2693
2708
group .append (
2694
2709
['ProjectConfiguration' , {'Include' : designation },
@@ -2740,7 +2755,7 @@ def _GetMSBuildGlobalProperties(spec, version, guid, gyp_file_name):
2740
2755
platform_name = None
2741
2756
msvs_windows_sdk_version = None
2742
2757
for configuration in spec ['configurations' ].values ():
2743
- platform_name = platform_name or _ConfigPlatform (configuration )
2758
+ platform_name = platform_name or _ConfigPlatform (configuration , spec )
2744
2759
msvs_windows_sdk_version = (msvs_windows_sdk_version or
2745
2760
_ConfigWindowsTargetPlatformVersion (configuration , version ))
2746
2761
if platform_name and msvs_windows_sdk_version :
@@ -2762,7 +2777,7 @@ def _GetMSBuildConfigurationDetails(spec, build_file):
2762
2777
properties = {}
2763
2778
for name , settings in spec ['configurations' ].items ():
2764
2779
msbuild_attributes = _GetMSBuildAttributes (spec , settings , build_file )
2765
- condition = _GetConfigurationCondition (name , settings )
2780
+ condition = _GetConfigurationCondition (name , settings , spec )
2766
2781
character_set = msbuild_attributes .get ('CharacterSet' )
2767
2782
config_type = msbuild_attributes .get ('ConfigurationType' )
2768
2783
_AddConditionalProperty (properties , condition , 'ConfigurationType' ,
@@ -2790,12 +2805,12 @@ def _GetMSBuildLocalProperties(msbuild_toolset):
2790
2805
return properties
2791
2806
2792
2807
2793
- def _GetMSBuildPropertySheets (configurations ):
2808
+ def _GetMSBuildPropertySheets (configurations , spec ):
2794
2809
user_props = r'$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props'
2795
2810
additional_props = {}
2796
2811
props_specified = False
2797
2812
for name , settings in sorted (configurations .items ()):
2798
- configuration = _GetConfigurationCondition (name , settings )
2813
+ configuration = _GetConfigurationCondition (name , settings , spec )
2799
2814
if 'msbuild_props' in settings :
2800
2815
additional_props [configuration ] = _FixPaths (settings ['msbuild_props' ])
2801
2816
props_specified = True
@@ -2946,7 +2961,7 @@ def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file):
2946
2961
2947
2962
properties = {}
2948
2963
for (name , configuration ) in sorted (configurations .items ()):
2949
- condition = _GetConfigurationCondition (name , configuration )
2964
+ condition = _GetConfigurationCondition (name , configuration , spec )
2950
2965
attributes = _GetMSBuildAttributes (spec , configuration , build_file )
2951
2966
msbuild_settings = configuration ['finalized_msbuild_settings' ]
2952
2967
_AddConditionalProperty (properties , condition , 'IntDir' ,
@@ -3055,7 +3070,9 @@ def _GetMSBuildToolSettingsSections(spec, configurations):
3055
3070
for (name , configuration ) in sorted (configurations .items ()):
3056
3071
msbuild_settings = configuration ['finalized_msbuild_settings' ]
3057
3072
group = ['ItemDefinitionGroup' ,
3058
- {'Condition' : _GetConfigurationCondition (name , configuration )}
3073
+ {'Condition' :
3074
+ _GetConfigurationCondition (name , configuration , spec )
3075
+ }
3059
3076
]
3060
3077
for tool_name , tool_settings in sorted (msbuild_settings .items ()):
3061
3078
# Skip the tool named '' which is a holder of global settings handled
@@ -3277,7 +3294,9 @@ def _AddSources2(spec, sources, exclusions, grouped_sources,
3277
3294
extensions_excluded_from_precompile = ['.c' ]
3278
3295
3279
3296
if precompiled_source == source :
3280
- condition = _GetConfigurationCondition (config_name , configuration )
3297
+ condition = _GetConfigurationCondition (
3298
+ config_name , configuration , spec
3299
+ )
3281
3300
detail .append (['PrecompiledHeader' ,
3282
3301
{'Condition' : condition },
3283
3302
'Create'
@@ -3296,12 +3315,26 @@ def _AddSources2(spec, sources, exclusions, grouped_sources,
3296
3315
_GetUniquePlatforms (spec ))
3297
3316
grouped_sources [group ].append ([element , {'Include' : source }] + detail )
3298
3317
3299
-
3300
- def _GetMSBuildProjectReferences ( project ):
3318
+ def _GetMSBuildProjectReferences ( project , spec ):
3319
+ current_configuration = spec [ 'default_configuration' ]
3301
3320
references = []
3302
3321
if project .dependencies :
3303
3322
group = ['ItemGroup' ]
3323
+ added_dependency_set = set ()
3304
3324
for dependency in project .dependencies :
3325
+ dependency_spec = dependency .spec
3326
+ should_skip_dep = False
3327
+ if project .spec ["toolset" ] == 'target' :
3328
+ if dependency_spec ['toolset' ] == 'host' :
3329
+ if dependency_spec ['type' ] == 'static_library' :
3330
+ should_skip_dep = True
3331
+ if dependency .name .startswith ('run_' ):
3332
+ should_skip_dep = False
3333
+ if should_skip_dep :
3334
+ continue
3335
+
3336
+ canonical_name = dependency .name .replace ('_host' , '' )
3337
+ added_dependency_set .add (canonical_name )
3305
3338
guid = dependency .guid
3306
3339
project_dir = os .path .split (project .path )[0 ]
3307
3340
relative_path = gyp .common .RelativePath (dependency .path , project_dir )
@@ -3323,7 +3356,7 @@ def _GetMSBuildProjectReferences(project):
3323
3356
return references
3324
3357
3325
3358
3326
- def _GenerateMSBuildProject (project , options , version , generator_flags ):
3359
+ def _GenerateMSBuildProject (project , options , version , generator_flags , spec ):
3327
3360
spec = project .spec
3328
3361
configurations = spec ['configurations' ]
3329
3362
project_dir , project_file_name = os .path .split (project .path )
@@ -3411,7 +3444,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
3411
3444
'DefaultTargets' : 'Build'
3412
3445
}]
3413
3446
3414
- content += _GetMSBuildProjectConfigurations (configurations )
3447
+ content += _GetMSBuildProjectConfigurations (configurations , spec )
3415
3448
content += _GetMSBuildGlobalProperties (spec , version , project .guid ,
3416
3449
project_file_name )
3417
3450
content += import_default_section
@@ -3422,18 +3455,18 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
3422
3455
content += _GetMSBuildLocalProperties (project .msbuild_toolset )
3423
3456
content += import_cpp_props_section
3424
3457
content += import_masm_props_section
3425
- if spec .get ('msvs_enable_marmasm' ):
3458
+ if spec .get ('msvs_enable_marmasm' ) or True :
3426
3459
content += import_marmasm_props_section
3427
3460
content += _GetMSBuildExtensions (props_files_of_rules )
3428
- content += _GetMSBuildPropertySheets (configurations )
3461
+ content += _GetMSBuildPropertySheets (configurations , spec )
3429
3462
content += macro_section
3430
3463
content += _GetMSBuildConfigurationGlobalProperties (spec , configurations ,
3431
3464
project .build_file )
3432
3465
content += _GetMSBuildToolSettingsSections (spec , configurations )
3433
3466
content += _GetMSBuildSources (
3434
3467
spec , sources , exclusions , rule_dependencies , extension_to_rule_name ,
3435
3468
actions_spec , sources_handled_by_action , list_excluded )
3436
- content += _GetMSBuildProjectReferences (project )
3469
+ content += _GetMSBuildProjectReferences (project , spec )
3437
3470
content += import_cpp_targets_section
3438
3471
content += import_masm_targets_section
3439
3472
if spec .get ('msvs_enable_marmasm' ):
@@ -3516,15 +3549,25 @@ def _GenerateActionsForMSBuild(spec, actions_to_add):
3516
3549
sources_handled_by_action = OrderedSet ()
3517
3550
actions_spec = []
3518
3551
for primary_input , actions in actions_to_add .items ():
3552
+ if generator_supports_multiple_toolsets :
3553
+ primary_input = primary_input .replace (".exe" , "_host.exe" )
3519
3554
inputs = OrderedSet ()
3520
3555
outputs = OrderedSet ()
3521
3556
descriptions = []
3522
3557
commands = []
3523
3558
for action in actions :
3559
+ def fixup_host_exe (i ):
3560
+ if "$(OutDir)" in i :
3561
+ i = i .replace ('.exe' , '_host.exe' )
3562
+ return i
3563
+ if generator_supports_multiple_toolsets :
3564
+ action ['inputs' ] = [fixup_host_exe (i ) for i in action ['inputs' ]]
3524
3565
inputs .update (OrderedSet (action ['inputs' ]))
3525
3566
outputs .update (OrderedSet (action ['outputs' ]))
3526
3567
descriptions .append (action ['description' ])
3527
3568
cmd = action ['command' ]
3569
+ if generator_supports_multiple_toolsets :
3570
+ cmd = cmd .replace ('.exe' , "_host.exe" )
3528
3571
# For most actions, add 'call' so that actions that invoke batch files
3529
3572
# return and continue executing. msbuild_use_call provides a way to
3530
3573
# disable this but I have not seen any adverse effect from doing that
0 commit comments