39
39
# letters.
40
40
VALID_MSVS_GUID_CHARS = re .compile (r"^[A-F0-9\-]+$" )
41
41
42
+ generator_supports_multiple_toolsets = gyp .common .CrossCompileRequested ()
42
43
43
44
generator_default_variables = {
44
45
"DRIVER_PREFIX" : "" ,
50
51
"STATIC_LIB_SUFFIX" : ".lib" ,
51
52
"SHARED_LIB_SUFFIX" : ".dll" ,
52
53
"INTERMEDIATE_DIR" : "$(IntDir)" ,
53
- "SHARED_INTERMEDIATE_DIR" : "$(OutDir)obj/global_intermediate" ,
54
+ "SHARED_INTERMEDIATE_DIR" : "$(OutDir)/ obj/global_intermediate" ,
54
55
"OS" : "win" ,
55
56
"PRODUCT_DIR" : "$(OutDir)" ,
56
57
"LIB_DIR" : "$(OutDir)lib" ,
@@ -1005,7 +1006,7 @@ def _GetMsbuildToolsetOfProject(proj_path, spec, version):
1005
1006
return toolset
1006
1007
1007
1008
1008
- def _GenerateProject (project , options , version , generator_flags ):
1009
+ def _GenerateProject (project , options , version , generator_flags , spec ):
1009
1010
"""Generates a vcproj file.
1010
1011
1011
1012
Arguments:
@@ -1023,7 +1024,7 @@ def _GenerateProject(project, options, version, generator_flags):
1023
1024
return []
1024
1025
1025
1026
if version .UsesVcxproj ():
1026
- return _GenerateMSBuildProject (project , options , version , generator_flags )
1027
+ return _GenerateMSBuildProject (project , options , version , generator_flags , spec )
1027
1028
else :
1028
1029
return _GenerateMSVSProject (project , options , version , generator_flags )
1029
1030
@@ -1903,6 +1904,8 @@ def _GatherSolutionFolders(sln_projects, project_objects, flat):
1903
1904
# Convert into a tree of dicts on path.
1904
1905
for p in sln_projects :
1905
1906
gyp_file , target = gyp .common .ParseQualifiedTarget (p )[0 :2 ]
1907
+ if p .endswith ("#host" ):
1908
+ target += "_host"
1906
1909
gyp_dir = os .path .dirname (gyp_file )
1907
1910
path_dict = _GetPathDict (root , gyp_dir )
1908
1911
path_dict [target + ".vcproj" ] = project_objects [p ]
@@ -1921,9 +1924,10 @@ def _GetPathOfProject(qualified_target, spec, options, msvs_version):
1921
1924
default_config = _GetDefaultConfiguration (spec )
1922
1925
proj_filename = default_config .get ("msvs_existing_vcproj" )
1923
1926
if not proj_filename :
1924
- proj_filename = (
1925
- spec ["target_name" ] + options .suffix + msvs_version .ProjectExtension ()
1926
- )
1927
+ proj_filename = spec ["target_name" ]
1928
+ if spec ["toolset" ] == "host" :
1929
+ proj_filename += "_host"
1930
+ proj_filename = proj_filename + options .suffix + msvs_version .ProjectExtension ()
1927
1931
1928
1932
build_file = gyp .common .BuildFile (qualified_target )
1929
1933
proj_path = os .path .join (os .path .dirname (build_file ), proj_filename )
@@ -1948,6 +1952,8 @@ def _GetPlatformOverridesOfProject(spec):
1948
1952
_ConfigBaseName (config_name , _ConfigPlatform (c )),
1949
1953
platform ,
1950
1954
)
1955
+ if spec ["toolset" ] == "host" and generator_supports_multiple_toolsets :
1956
+ fixed_config_fullname = "%s|x64" % (config_name ,)
1951
1957
config_platform_overrides [config_fullname ] = fixed_config_fullname
1952
1958
return config_platform_overrides
1953
1959
@@ -1968,21 +1974,19 @@ def _CreateProjectObjects(target_list, target_dicts, options, msvs_version):
1968
1974
projects = {}
1969
1975
for qualified_target in target_list :
1970
1976
spec = target_dicts [qualified_target ]
1971
- if spec ["toolset" ] != "target" :
1972
- raise GypError (
1973
- "Multiple toolsets not supported in msvs build (target %s)"
1974
- % qualified_target
1975
- )
1976
1977
proj_path , fixpath_prefix = _GetPathOfProject (
1977
1978
qualified_target , spec , options , msvs_version
1978
1979
)
1979
1980
guid = _GetGuidOfProject (proj_path , spec )
1980
1981
overrides = _GetPlatformOverridesOfProject (spec )
1981
1982
build_file = gyp .common .BuildFile (qualified_target )
1982
1983
# Create object for this project.
1984
+ target_name = spec ["target_name" ]
1985
+ if spec ["toolset" ] == "host" :
1986
+ target_name += "_host"
1983
1987
obj = MSVSNew .MSVSProject (
1984
1988
proj_path ,
1985
- name = spec [ " target_name" ] ,
1989
+ name = target_name ,
1986
1990
guid = guid ,
1987
1991
spec = spec ,
1988
1992
build_file = build_file ,
@@ -2161,7 +2165,10 @@ def GenerateOutput(target_list, target_dicts, data, params):
2161
2165
for qualified_target in target_list :
2162
2166
spec = target_dicts [qualified_target ]
2163
2167
for config_name , config in spec ["configurations" ].items ():
2164
- configs .add (_ConfigFullName (config_name , config ))
2168
+ config_name = _ConfigFullName (config_name , config )
2169
+ configs .add (config_name )
2170
+ if config_name == "Release|arm64" :
2171
+ configs .add ("Release|x64" )
2165
2172
configs = list (configs )
2166
2173
2167
2174
# Figure out all the projects that will be generated and their guids
@@ -2174,12 +2181,15 @@ def GenerateOutput(target_list, target_dicts, data, params):
2174
2181
for project in project_objects .values ():
2175
2182
fixpath_prefix = project .fixpath_prefix
2176
2183
missing_sources .extend (
2177
- _GenerateProject (project , options , msvs_version , generator_flags )
2184
+ _GenerateProject (project , options , msvs_version , generator_flags , spec )
2178
2185
)
2179
2186
fixpath_prefix = None
2180
2187
2181
2188
for build_file in data :
2182
2189
# Validate build_file extension
2190
+ target_only_configs = configs
2191
+ if generator_supports_multiple_toolsets :
2192
+ target_only_configs = [i for i in configs if i .endswith ("arm64" )]
2183
2193
if not build_file .endswith (".gyp" ):
2184
2194
continue
2185
2195
sln_path = os .path .splitext (build_file )[0 ] + options .suffix + ".sln"
@@ -2196,7 +2206,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
2196
2206
sln = MSVSNew .MSVSSolution (
2197
2207
sln_path ,
2198
2208
entries = root_entries ,
2199
- variants = configs ,
2209
+ variants = target_only_configs ,
2200
2210
websiteProperties = False ,
2201
2211
version = msvs_version ,
2202
2212
)
@@ -2930,22 +2940,24 @@ def _GenerateMSBuildRuleXmlFile(xml_path, msbuild_rules):
2930
2940
easy_xml .WriteXmlIfChanged (content , xml_path , pretty = True , win32 = True )
2931
2941
2932
2942
2933
- def _GetConfigurationAndPlatform (name , settings ):
2943
+ def _GetConfigurationAndPlatform (name , settings , spec ):
2934
2944
configuration = name .rsplit ("_" , 1 )[0 ]
2935
2945
platform = settings .get ("msvs_configuration_platform" , "Win32" )
2946
+ if spec ["toolset" ] == "host" and platform == "arm64" :
2947
+ platform = "x64" # Host-only tools are always built for x64
2936
2948
return (configuration , platform )
2937
2949
2938
2950
2939
- def _GetConfigurationCondition (name , settings ):
2951
+ def _GetConfigurationCondition (name , settings , spec ):
2940
2952
return r"'$(Configuration)|$(Platform)'=='%s|%s'" % _GetConfigurationAndPlatform (
2941
- name , settings
2953
+ name , settings , spec
2942
2954
)
2943
2955
2944
2956
2945
- def _GetMSBuildProjectConfigurations (configurations ):
2957
+ def _GetMSBuildProjectConfigurations (configurations , spec ):
2946
2958
group = ["ItemGroup" , {"Label" : "ProjectConfigurations" }]
2947
2959
for (name , settings ) in sorted (configurations .items ()):
2948
- configuration , platform = _GetConfigurationAndPlatform (name , settings )
2960
+ configuration , platform = _GetConfigurationAndPlatform (name , settings , spec )
2949
2961
designation = "%s|%s" % (configuration , platform )
2950
2962
group .append (
2951
2963
[
@@ -3033,7 +3045,7 @@ def _GetMSBuildConfigurationDetails(spec, build_file):
3033
3045
properties = {}
3034
3046
for name , settings in spec ["configurations" ].items ():
3035
3047
msbuild_attributes = _GetMSBuildAttributes (spec , settings , build_file )
3036
- condition = _GetConfigurationCondition (name , settings )
3048
+ condition = _GetConfigurationCondition (name , settings , spec )
3037
3049
character_set = msbuild_attributes .get ("CharacterSet" )
3038
3050
config_type = msbuild_attributes .get ("ConfigurationType" )
3039
3051
_AddConditionalProperty (properties , condition , "ConfigurationType" , config_type )
@@ -3064,12 +3076,12 @@ def _GetMSBuildLocalProperties(msbuild_toolset):
3064
3076
return properties
3065
3077
3066
3078
3067
- def _GetMSBuildPropertySheets (configurations ):
3079
+ def _GetMSBuildPropertySheets (configurations , spec ):
3068
3080
user_props = r"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
3069
3081
additional_props = {}
3070
3082
props_specified = False
3071
3083
for name , settings in sorted (configurations .items ()):
3072
- configuration = _GetConfigurationCondition (name , settings )
3084
+ configuration = _GetConfigurationCondition (name , settings , spec )
3073
3085
if "msbuild_props" in settings :
3074
3086
additional_props [configuration ] = _FixPaths (settings ["msbuild_props" ])
3075
3087
props_specified = True
@@ -3222,7 +3234,7 @@ def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file):
3222
3234
3223
3235
properties = {}
3224
3236
for (name , configuration ) in sorted (configurations .items ()):
3225
- condition = _GetConfigurationCondition (name , configuration )
3237
+ condition = _GetConfigurationCondition (name , configuration , spec )
3226
3238
attributes = _GetMSBuildAttributes (spec , configuration , build_file )
3227
3239
msbuild_settings = configuration ["finalized_msbuild_settings" ]
3228
3240
_AddConditionalProperty (
@@ -3345,7 +3357,7 @@ def _GetMSBuildToolSettingsSections(spec, configurations):
3345
3357
msbuild_settings = configuration ["finalized_msbuild_settings" ]
3346
3358
group = [
3347
3359
"ItemDefinitionGroup" ,
3348
- {"Condition" : _GetConfigurationCondition (name , configuration )},
3360
+ {"Condition" : _GetConfigurationCondition (name , configuration , spec )},
3349
3361
]
3350
3362
for tool_name , tool_settings in sorted (msbuild_settings .items ()):
3351
3363
# Skip the tool named '' which is a holder of global settings handled
@@ -3625,7 +3637,7 @@ def _AddSources2(
3625
3637
3626
3638
if precompiled_source == source :
3627
3639
condition = _GetConfigurationCondition (
3628
- config_name , configuration
3640
+ config_name , configuration , spec
3629
3641
)
3630
3642
detail .append (
3631
3643
["PrecompiledHeader" , {"Condition" : condition }, "Create" ]
@@ -3652,7 +3664,21 @@ def _GetMSBuildProjectReferences(project):
3652
3664
references = []
3653
3665
if project .dependencies :
3654
3666
group = ["ItemGroup" ]
3667
+ added_dependency_set = set ()
3655
3668
for dependency in project .dependencies :
3669
+ dependency_spec = dependency .spec
3670
+ should_skip_dep = False
3671
+ if project .spec ["toolset" ] == "target" :
3672
+ if dependency_spec ["toolset" ] == "host" :
3673
+ if dependency_spec ["type" ] == "static_library" :
3674
+ should_skip_dep = True
3675
+ if dependency .name .startswith ("run_" ):
3676
+ should_skip_dep = False
3677
+ if should_skip_dep :
3678
+ continue
3679
+
3680
+ canonical_name = dependency .name .replace ("_host" , "" )
3681
+ added_dependency_set .add (canonical_name )
3656
3682
guid = dependency .guid
3657
3683
project_dir = os .path .split (project .path )[0 ]
3658
3684
relative_path = gyp .common .RelativePath (dependency .path , project_dir )
@@ -3675,7 +3701,7 @@ def _GetMSBuildProjectReferences(project):
3675
3701
return references
3676
3702
3677
3703
3678
- def _GenerateMSBuildProject (project , options , version , generator_flags ):
3704
+ def _GenerateMSBuildProject (project , options , version , generator_flags , spec ):
3679
3705
spec = project .spec
3680
3706
configurations = spec ["configurations" ]
3681
3707
project_dir , project_file_name = os .path .split (project .path )
@@ -3774,7 +3800,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
3774
3800
},
3775
3801
]
3776
3802
3777
- content += _GetMSBuildProjectConfigurations (configurations )
3803
+ content += _GetMSBuildProjectConfigurations (configurations , spec )
3778
3804
content += _GetMSBuildGlobalProperties (
3779
3805
spec , version , project .guid , project_file_name
3780
3806
)
@@ -3789,7 +3815,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
3789
3815
if spec .get ("msvs_enable_marmasm" ):
3790
3816
content += import_marmasm_props_section
3791
3817
content += _GetMSBuildExtensions (props_files_of_rules )
3792
- content += _GetMSBuildPropertySheets (configurations )
3818
+ content += _GetMSBuildPropertySheets (configurations , spec )
3793
3819
content += macro_section
3794
3820
content += _GetMSBuildConfigurationGlobalProperties (
3795
3821
spec , configurations , project .build_file
@@ -3893,15 +3919,27 @@ def _GenerateActionsForMSBuild(spec, actions_to_add):
3893
3919
sources_handled_by_action = OrderedSet ()
3894
3920
actions_spec = []
3895
3921
for primary_input , actions in actions_to_add .items ():
3922
+ if generator_supports_multiple_toolsets :
3923
+ primary_input = primary_input .replace (".exe" , "_host.exe" )
3896
3924
inputs = OrderedSet ()
3897
3925
outputs = OrderedSet ()
3898
3926
descriptions = []
3899
3927
commands = []
3900
3928
for action in actions :
3929
+
3930
+ def fixup_host_exe (i ):
3931
+ if "$(OutDir)" in i :
3932
+ i = i .replace (".exe" , "_host.exe" )
3933
+ return i
3934
+
3935
+ if generator_supports_multiple_toolsets :
3936
+ action ["inputs" ] = [fixup_host_exe (i ) for i in action ["inputs" ]]
3901
3937
inputs .update (OrderedSet (action ["inputs" ]))
3902
3938
outputs .update (OrderedSet (action ["outputs" ]))
3903
3939
descriptions .append (action ["description" ])
3904
3940
cmd = action ["command" ]
3941
+ if generator_supports_multiple_toolsets :
3942
+ cmd = cmd .replace (".exe" , "_host.exe" )
3905
3943
# For most actions, add 'call' so that actions that invoke batch files
3906
3944
# return and continue executing. msbuild_use_call provides a way to
3907
3945
# disable this but I have not seen any adverse effect from doing that
0 commit comments