1# Copyright 2024 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""All providers for rule-based bazel toolchain config.""" 15 16load( 17 "//cc/toolchains/impl:collect.bzl", 18 "collect_args_lists", 19) 20load(":cc_toolchain_info.bzl", "ArgsListInfo") 21 22def _cc_args_list_impl(ctx): 23 return [collect_args_lists(ctx.attr.args, ctx.label)] 24 25cc_args_list = rule( 26 implementation = _cc_args_list_impl, 27 doc = """An ordered list of cc_args. 28 29 This is a convenience rule to allow you to group a set of multiple `cc_args` into a 30 single list. This particularly useful for toolchain behaviors that require different flags for 31 different actions. 32 33 Note: The order of the arguments in `args` is preserved to support order-sensitive flags. 34 35 Example usage: 36 ``` 37 load("//cc/toolchains:cc_args.bzl", "cc_args") 38 load("//cc/toolchains:args_list.bzl", "cc_args_list") 39 40 cc_args( 41 name = "gc_sections", 42 actions = [ 43 "//cc/toolchains/actions:link_actions", 44 ], 45 args = ["-Wl,--gc-sections"], 46 ) 47 48 cc_args( 49 name = "function_sections", 50 actions = [ 51 "//cc/toolchains/actions:compile_actions", 52 "//cc/toolchains/actions:link_actions", 53 ], 54 args = ["-ffunction-sections"], 55 ) 56 57 cc_args_list( 58 name = "gc_functions", 59 args = [ 60 ":function_sections", 61 ":gc_sections", 62 ], 63 ) 64 ``` 65 """, 66 attrs = { 67 "args": attr.label_list( 68 providers = [ArgsListInfo], 69 doc = "(ordered) cc_args to include in this list.", 70 ), 71 }, 72 provides = [ArgsListInfo], 73) 74