@@ -19,11 +19,21 @@ load("//cc/common:cc_helper.bzl", "cc_helper")
1919load ("//cc/common:semantics.bzl" , "semantics" )
2020load ("//cc/private/rules_impl/fdo:fdo_context.bzl" , "create_fdo_context" )
2121load ("//cc/toolchains:cc_toolchain_config_info.bzl" , "CcToolchainConfigInfo" )
22+ load ("//cc/toolchains:cc_toolchain_info.bzl" , "ActionTypeSetInfo" , "FeatureSetInfo" , "ToolConfigInfo" )
23+ load ("//cc/toolchains:legacy_file_group.bzl" , "LEGACY_FILE_GROUPS" )
24+ load ("//cc/toolchains/impl:collect.bzl" , "collect_action_types" )
25+ load ("//cc/toolchains/impl:toolchain_config.bzl" , "CC_TOOLCHAIN_CONFIG_PUBLIC_ATTRS" , "cc_toolchain_config_impl_helper" )
2226load (":cc_toolchain_provider_helper.bzl" , "get_cc_toolchain_provider" )
2327
2428ToolchainInfo = platform_common .ToolchainInfo
2529TemplateVariableInfo = platform_common .TemplateVariableInfo
2630
31+ LEGACY_ACTION_SET_DEPS = [
32+ action
33+ for actions in LEGACY_FILE_GROUPS .values ()
34+ for action in actions
35+ ]
36+
2737def _files (ctx , attr_name ):
2838 attr = getattr (ctx .attr , attr_name , None )
2939 files = []
@@ -81,42 +91,81 @@ def _attributes(ctx):
8191
8292 latebound_libc = _latebound_libc (ctx , "libc_top" , "_libc_top" )
8393
84- all_files = _files (ctx , "all_files" )
94+ if ctx .attr .toolchain_config :
95+ for key in CC_TOOLCHAIN_CONFIG_PUBLIC_ATTRS .keys ():
96+ if getattr (ctx .attr , key ):
97+ fail ("Must not pass %s when passing `toolchain_config`" % key )
98+
99+ cc_toolchain_config_info = ctx .attr .toolchain_config [CcToolchainConfigInfo ]
100+ all_files = _files (ctx , "all_files" )
101+
102+ legacy_file_groups = {
103+ "as_files" : _files (ctx , "as_files" ),
104+ "ar_files" : _files (ctx , "ar_files" ),
105+ "dwp_files" : _files (ctx , "dwp_files" ),
106+ "compiler_files" : _files (ctx , "compiler_files" ),
107+ "strip_files" : _files (ctx , "strip_files" ),
108+ "objcopy_files" : _files (ctx , "objcopy_files" ),
109+ "coverage_files" : _files (ctx , "coverage_files" ) or all_files ,
110+ }
111+
112+ linker_files = _files (ctx , "linker_files" )
113+
114+ else :
115+ if not ctx .attr .tool_map :
116+ fail ("Must pass `tool_map` when not passing `toolchain_config`" )
117+ toolchain_config_info , cc_toolchain_config_info = cc_toolchain_config_impl_helper (ctx )
118+
119+ legacy_action_set_lookup = {
120+ target .label : target
121+ for target in ctx .attr ._legacy_action_sets
122+ }
123+
124+ legacy_file_groups = {}
125+ for group , actions in LEGACY_FILE_GROUPS .items ():
126+ action_targets = [
127+ legacy_action_set_lookup [action ]
128+ for action in actions
129+ ]
130+ legacy_file_groups [group ] = depset (transitive = [
131+ toolchain_config_info .files [action ]
132+ for action in collect_action_types (action_targets ).to_list ()
133+ if action in toolchain_config_info .files
134+ ])
135+
136+ all_files = depset (transitive = legacy_file_groups .values ())
137+ legacy_file_groups ["coverage_files" ] = legacy_file_groups ["coverage_files" ] or all_files
138+ linker_files = legacy_file_groups .pop ("linker_files" )
139+
85140 return struct (
86141 supports_param_files = ctx .attr .supports_param_files ,
87142 runtime_solib_dir_base = "_solib__" + cc_common .escape_label (label = ctx .label ),
88- cc_toolchain_config_info = _provider ( ctx . attr . toolchain_config , CcToolchainConfigInfo ) ,
143+ cc_toolchain_config_info = cc_toolchain_config_info ,
89144 static_runtime_lib = ctx .attr .static_runtime_lib ,
90145 dynamic_runtime_lib = ctx .attr .dynamic_runtime_lib ,
91146 supports_header_parsing = ctx .attr .supports_header_parsing ,
92147 all_files = all_files ,
93- compiler_files = _files (ctx , "compiler_files" ),
94- strip_files = _files (ctx , "strip_files" ),
95- objcopy_files = _files (ctx , "objcopy_files" ),
96148 link_dynamic_library_tool = ctx .file ._link_dynamic_library_tool ,
97149 grep_includes = grep_includes ,
98150 aggregate_ddi = _single_file (ctx , "_aggregate_ddi" ),
99151 generate_modmap = _single_file (ctx , "_generate_modmap" ),
100152 module_map = ctx .attr .module_map ,
101- as_files = _files (ctx , "as_files" ),
102- ar_files = _files (ctx , "ar_files" ),
103- dwp_files = _files (ctx , "dwp_files" ),
104153 module_map_artifact = _single_file (ctx , "module_map" ),
105- all_files_including_libc = depset (transitive = [_files ( ctx , " all_files" ) , _files (ctx , latebound_libc )]),
154+ all_files_including_libc = depset (transitive = [all_files , _files (ctx , latebound_libc )]),
106155 zipper = ctx .file ._zipper ,
107156 linker_files = _full_inputs_for_link (
108157 ctx ,
109- _files ( ctx , " linker_files" ) ,
158+ linker_files ,
110159 _files (ctx , latebound_libc ),
111160 ),
112161 cc_toolchain_label = ctx .label ,
113- coverage_files = _files (ctx , "coverage_files" ) or all_files ,
114162 compiler_files_without_includes = _files (ctx , "compiler_files_without_includes" ),
115163 libc = _files (ctx , latebound_libc ),
116164 libc_top_label = _label (ctx , latebound_libc ),
117165 if_so_builder = ctx .file ._interface_library_builder ,
118166 allowlist_for_layering_check = _package_specification_provider (ctx , "disabling_parse_headers_and_layering_check_allowed" ),
119167 build_info_files = _provider (ctx .attr ._build_info_translator , OutputGroupInfo ),
168+ ** legacy_file_groups
120169 )
121170
122171def _cc_toolchain_impl (ctx ):
@@ -200,7 +249,6 @@ crosstool_config.toolchain.
200249 ),
201250 "all_files" : attr .label (
202251 allow_files = True ,
203- mandatory = True ,
204252 doc = """
205253Collection of all cc_toolchain artifacts. These artifacts will be added as inputs to all
206254rules_cc related actions (with the exception of actions that are using more precise sets of
@@ -214,7 +262,6 @@ rules using C++ toolchain.</p>""",
214262 ),
215263 "compiler_files" : attr .label (
216264 allow_files = True ,
217- mandatory = True ,
218265 doc = """
219266Collection of all cc_toolchain artifacts required for compile actions.""" ,
220267 ),
@@ -226,13 +273,11 @@ input discovery is supported (currently Google-only).""",
226273 ),
227274 "strip_files" : attr .label (
228275 allow_files = True ,
229- mandatory = True ,
230276 doc = """
231277Collection of all cc_toolchain artifacts required for strip actions.""" ,
232278 ),
233279 "objcopy_files" : attr .label (
234280 allow_files = True ,
235- mandatory = True ,
236281 doc = """
237282Collection of all cc_toolchain artifacts required for objcopy actions.""" ,
238283 ),
@@ -248,13 +293,11 @@ Collection of all cc_toolchain artifacts required for archiving actions.""",
248293 ),
249294 "linker_files" : attr .label (
250295 allow_files = True ,
251- mandatory = True ,
252296 doc = """
253297Collection of all cc_toolchain artifacts required for linking actions.""" ,
254298 ),
255299 "dwp_files" : attr .label (
256300 allow_files = True ,
257- mandatory = True ,
258301 doc = """
259302Collection of all cc_toolchain artifacts required for dwp actions.""" ,
260303 ),
@@ -307,7 +350,6 @@ Set to True when cc_toolchain supports header parsing actions.""",
307350 ),
308351 "toolchain_config" : attr .label (
309352 allow_files = False ,
310- mandatory = True ,
311353 providers = [CcToolchainConfigInfo ],
312354 doc = """
313355The label of the rule providing <code>cc_toolchain_config_info</code>.""" ,
@@ -340,5 +382,16 @@ The label of the rule providing <code>cc_toolchain_config_info</code>.""",
340382 default = semantics .BUILD_INFO_TRANLATOR_LABEL ,
341383 providers = [OutputGroupInfo ],
342384 ),
385+ "_legacy_action_sets" : attr .label_list (
386+ default = LEGACY_ACTION_SET_DEPS ,
387+ providers = [ActionTypeSetInfo ],
388+ ),
389+ } | CC_TOOLCHAIN_CONFIG_PUBLIC_ATTRS | {
390+ # Override tool_map to make it optional and exec-configured.
391+ "tool_map" : attr .label (
392+ cfg = "exec" ,
393+ providers = [ToolConfigInfo ],
394+ ),
395+ "_builtin_features" : attr .label (default = "//cc/toolchains/features:all_builtin_features" , providers = [FeatureSetInfo ]),
343396 } | semantics .cpp_modules_tools (), # buildifier: disable=unsorted-dict-items
344397)
0 commit comments