@@ -19,6 +19,9 @@ 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" , "ToolConfigInfo" )
23+ load ("//cc/toolchains/impl:collect.bzl" , "collect_action_types" )
24+ load ("//cc/toolchains/impl:toolchain_config.bzl" , "CC_TOOLCHAIN_CONFIG_PUBLIC_ATTRS" , "cc_toolchain_config_impl_helper" )
2225load (":cc_toolchain_provider_helper.bzl" , "get_cc_toolchain_provider" )
2326
2427ToolchainInfo = platform_common .ToolchainInfo
@@ -74,49 +77,111 @@ def _single_file(ctx, attr_name):
7477 return files [0 ]
7578 return None
7679
80+ # Taken from https://bazel.build/docs/cc-toolchain-config-reference#actions
81+ # TODO: This is best-effort. Update this with the correct file groups once we
82+ # work out what actions correspond to what file groups.
83+ LEGACY_FILE_GROUPS = {
84+ "ar_files" : [
85+ Label ("//cc/toolchains/actions:ar_actions" ),
86+ ],
87+ "as_files" : [
88+ Label ("//cc/toolchains/actions:assembly_actions" ),
89+ ],
90+ "compiler_files" : [
91+ Label ("//cc/toolchains/actions:cc_flags_make_variable" ),
92+ Label ("//cc/toolchains/actions:c_compile" ),
93+ Label ("//cc/toolchains/actions:cpp_compile" ),
94+ Label ("//cc/toolchains/actions:cpp_header_parsing" ),
95+ ],
96+ # There are no actions listed for coverage and objcopy in action_names.bzl.
97+ "coverage_files" : [],
98+ "dwp_files" : [
99+ Label ("//cc/toolchains/actions:dwp" ),
100+ ],
101+ "linker_files" : [
102+ Label ("//cc/toolchains/actions:cpp_link_dynamic_library" ),
103+ Label ("//cc/toolchains/actions:cpp_link_nodeps_dynamic_library" ),
104+ Label ("//cc/toolchains/actions:cpp_link_executable" ),
105+ ],
106+ "objcopy_files" : [],
107+ "strip_files" : [
108+ Label ("//cc/toolchains/actions:strip" ),
109+ ],
110+ }
111+
77112def _attributes (ctx ):
78113 grep_includes = None
79114 if not semantics .is_bazel :
80115 grep_includes = _single_file (ctx , "_grep_includes" )
81116
82117 latebound_libc = _latebound_libc (ctx , "libc_top" , "_libc_top" )
83118
84- all_files = _files (ctx , "all_files" )
119+ if ctx .attr .toolchain_config :
120+ for key in CC_TOOLCHAIN_CONFIG_PUBLIC_ATTRS .keys ():
121+ if getattr (ctx .attr , key ):
122+ fail ("Must not pass %s when passing `toolchain_config`" % key )
123+
124+ cc_toolchain_config_info = ctx .attr .toolchain_config [CcToolchainConfigInfo ]
125+ all_files = _files (ctx , "all_files" )
126+
127+ legacy_file_groups = {
128+ "as_files" : _files (ctx , "as_files" ),
129+ "ar_files" : _files (ctx , "ar_files" ),
130+ "dwp_files" : _files (ctx , "dwp_files" ),
131+ "compiler_files" : _files (ctx , "compiler_files" ),
132+ "strip_files" : _files (ctx , "strip_files" ),
133+ "objcopy_files" : _files (ctx , "objcopy_files" ),
134+ "coverage_files" : _files (ctx , "coverage_files" ) or all_files ,
135+ }
136+
137+ linker_files = _files (ctx , "linker_files" )
138+
139+ else :
140+ if not ctx .attr .tool_map :
141+ fail ("Must pass `tool_map` when not passing `toolchain_config`" )
142+ toolchain_config_info , cc_toolchain_config_info = cc_toolchain_config_impl_helper (ctx )
143+
144+ legacy_file_groups = {}
145+ for group , actions in LEGACY_FILE_GROUPS .items ():
146+ legacy_file_groups [group ] = depset (transitive = [
147+ toolchain_config_info .files [action ]
148+ for action in collect_action_types (actions ).to_list ()
149+ if action in toolchain_config_info .files
150+ ])
151+
152+ all_files = depset (transitive = [legacy_file_groups .values ()])
153+ legacy_file_groups ["coverage_files" ] = legacy_file_groups ["coverage_files" ] or all_files
154+ linker_files = legacy_file_groups .pop ("linker_files" )
155+
85156 return struct (
86157 supports_param_files = ctx .attr .supports_param_files ,
87158 runtime_solib_dir_base = "_solib__" + cc_common .escape_label (label = ctx .label ),
88- cc_toolchain_config_info = _provider ( ctx . attr . toolchain_config , CcToolchainConfigInfo ) ,
159+ cc_toolchain_config_info = cc_toolchain_config_info ,
89160 static_runtime_lib = ctx .attr .static_runtime_lib ,
90161 dynamic_runtime_lib = ctx .attr .dynamic_runtime_lib ,
91162 supports_header_parsing = ctx .attr .supports_header_parsing ,
92163 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" ),
96164 link_dynamic_library_tool = ctx .file ._link_dynamic_library_tool ,
97165 grep_includes = grep_includes ,
98166 aggregate_ddi = _single_file (ctx , "_aggregate_ddi" ),
99167 generate_modmap = _single_file (ctx , "_generate_modmap" ),
100168 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" ),
104169 module_map_artifact = _single_file (ctx , "module_map" ),
105- all_files_including_libc = depset (transitive = [_files ( ctx , " all_files" ) , _files (ctx , latebound_libc )]),
170+ all_files_including_libc = depset (transitive = [all_files , _files (ctx , latebound_libc )]),
106171 zipper = ctx .file ._zipper ,
107172 linker_files = _full_inputs_for_link (
108173 ctx ,
109- _files ( ctx , " linker_files" ) ,
174+ linker_files ,
110175 _files (ctx , latebound_libc ),
111176 ),
112177 cc_toolchain_label = ctx .label ,
113- coverage_files = _files (ctx , "coverage_files" ) or all_files ,
114178 compiler_files_without_includes = _files (ctx , "compiler_files_without_includes" ),
115179 libc = _files (ctx , latebound_libc ),
116180 libc_top_label = _label (ctx , latebound_libc ),
117181 if_so_builder = ctx .file ._interface_library_builder ,
118182 allowlist_for_layering_check = _package_specification_provider (ctx , "disabling_parse_headers_and_layering_check_allowed" ),
119183 build_info_files = _provider (ctx .attr ._build_info_translator , OutputGroupInfo ),
184+ ** legacy_file_groups
120185 )
121186
122187def _cc_toolchain_impl (ctx ):
@@ -200,7 +265,6 @@ crosstool_config.toolchain.
200265 ),
201266 "all_files" : attr .label (
202267 allow_files = True ,
203- mandatory = True ,
204268 doc = """
205269Collection of all cc_toolchain artifacts. These artifacts will be added as inputs to all
206270rules_cc related actions (with the exception of actions that are using more precise sets of
@@ -214,7 +278,6 @@ rules using C++ toolchain.</p>""",
214278 ),
215279 "compiler_files" : attr .label (
216280 allow_files = True ,
217- mandatory = True ,
218281 doc = """
219282Collection of all cc_toolchain artifacts required for compile actions.""" ,
220283 ),
@@ -226,13 +289,11 @@ input discovery is supported (currently Google-only).""",
226289 ),
227290 "strip_files" : attr .label (
228291 allow_files = True ,
229- mandatory = True ,
230292 doc = """
231293Collection of all cc_toolchain artifacts required for strip actions.""" ,
232294 ),
233295 "objcopy_files" : attr .label (
234296 allow_files = True ,
235- mandatory = True ,
236297 doc = """
237298Collection of all cc_toolchain artifacts required for objcopy actions.""" ,
238299 ),
@@ -248,13 +309,11 @@ Collection of all cc_toolchain artifacts required for archiving actions.""",
248309 ),
249310 "linker_files" : attr .label (
250311 allow_files = True ,
251- mandatory = True ,
252312 doc = """
253313Collection of all cc_toolchain artifacts required for linking actions.""" ,
254314 ),
255315 "dwp_files" : attr .label (
256316 allow_files = True ,
257- mandatory = True ,
258317 doc = """
259318Collection of all cc_toolchain artifacts required for dwp actions.""" ,
260319 ),
@@ -307,7 +366,6 @@ Set to True when cc_toolchain supports header parsing actions.""",
307366 ),
308367 "toolchain_config" : attr .label (
309368 allow_files = False ,
310- mandatory = True ,
311369 providers = [CcToolchainConfigInfo ],
312370 doc = """
313371The label of the rule providing <code>cc_toolchain_config_info</code>.""" ,
@@ -340,5 +398,12 @@ The label of the rule providing <code>cc_toolchain_config_info</code>.""",
340398 default = semantics .BUILD_INFO_TRANLATOR_LABEL ,
341399 providers = [OutputGroupInfo ],
342400 ),
401+ } | CC_TOOLCHAIN_CONFIG_PUBLIC_ATTRS | {
402+ # Override tool_map to make it optional.
403+ "tool_map" : attr .label (
404+ cfg = "exec" ,
405+ providers = [ToolConfigInfo ],
406+ ),
407+ "_builtin_features" : attr .label (default = "//cc/toolchains/features:all_builtin_features" ),
343408 } | semantics .cpp_modules_tools (), # buildifier: disable=unsorted-dict-items
344409)
0 commit comments