xref: /aosp_15_r20/external/pigweed/pw_toolchain_bazel/api.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_toolchain_bazel-api:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker=============
4*61c4878aSAndroid Build Coastguard WorkerAPI reference
5*61c4878aSAndroid Build Coastguard Worker=============
6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module-subpage::
7*61c4878aSAndroid Build Coastguard Worker   :name: pw_toolchain_bazel
8*61c4878aSAndroid Build Coastguard Worker
9*61c4878aSAndroid Build Coastguard Worker.. py:class:: pw_cc_toolchain
10*61c4878aSAndroid Build Coastguard Worker
11*61c4878aSAndroid Build Coastguard Worker  This rule is the core of a C/C++ toolchain definition. Critically, it is
12*61c4878aSAndroid Build Coastguard Worker  intended to fully specify the following:
13*61c4878aSAndroid Build Coastguard Worker
14*61c4878aSAndroid Build Coastguard Worker  * Which tools to use for various compile/link actions.
15*61c4878aSAndroid Build Coastguard Worker  * Which `well-known features <https://bazel.build/docs/cc-toolchain-config-reference#wellknown-features>`_
16*61c4878aSAndroid Build Coastguard Worker    are supported.
17*61c4878aSAndroid Build Coastguard Worker  * Which flags to apply to various actions.
18*61c4878aSAndroid Build Coastguard Worker
19*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: action_configs
20*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
21*61c4878aSAndroid Build Coastguard Worker
22*61c4878aSAndroid Build Coastguard Worker      List of :py:class:`pw_cc_action_config` labels that bind tools to the
23*61c4878aSAndroid Build Coastguard Worker      appropriate actions. This is how Bazel knows which binaries to use when
24*61c4878aSAndroid Build Coastguard Worker      compiling, linking, or taking other actions like embedding data using
25*61c4878aSAndroid Build Coastguard Worker      objcopy.
26*61c4878aSAndroid Build Coastguard Worker
27*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: flag_sets
28*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
29*61c4878aSAndroid Build Coastguard Worker
30*61c4878aSAndroid Build Coastguard Worker      List of flag sets to unconditionally apply to the respective
31*61c4878aSAndroid Build Coastguard Worker      :py:class:`pw_cc_action_config`\s. The labels listed here will point to
32*61c4878aSAndroid Build Coastguard Worker      :py:class:`pw_cc_flag_set` rules.
33*61c4878aSAndroid Build Coastguard Worker
34*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: extra_action_files
35*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
36*61c4878aSAndroid Build Coastguard Worker
37*61c4878aSAndroid Build Coastguard Worker      List of extra files to give to each different type of action. Replaces
38*61c4878aSAndroid Build Coastguard Worker      all_files, ar_files, compiler_files, ... in the existing toolchain
39*61c4878aSAndroid Build Coastguard Worker      definition.
40*61c4878aSAndroid Build Coastguard Worker
41*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: toolchain_identifier
42*61c4878aSAndroid Build Coastguard Worker      :type: str
43*61c4878aSAndroid Build Coastguard Worker
44*61c4878aSAndroid Build Coastguard Worker      See  `cc_common.create_cc_toolchain_config_info() <https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info>`_\.
45*61c4878aSAndroid Build Coastguard Worker
46*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: host_system_name
47*61c4878aSAndroid Build Coastguard Worker      :type: str
48*61c4878aSAndroid Build Coastguard Worker
49*61c4878aSAndroid Build Coastguard Worker      See  `cc_common.create_cc_toolchain_config_info() <https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info>`_\.
50*61c4878aSAndroid Build Coastguard Worker
51*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: target_system_name
52*61c4878aSAndroid Build Coastguard Worker      :type: str
53*61c4878aSAndroid Build Coastguard Worker
54*61c4878aSAndroid Build Coastguard Worker      See  `cc_common.create_cc_toolchain_config_info() <https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info>`_\.
55*61c4878aSAndroid Build Coastguard Worker
56*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: target_cpu
57*61c4878aSAndroid Build Coastguard Worker      :type: str
58*61c4878aSAndroid Build Coastguard Worker
59*61c4878aSAndroid Build Coastguard Worker      See  `cc_common.create_cc_toolchain_config_info() <https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info>`_\.
60*61c4878aSAndroid Build Coastguard Worker
61*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: target_libc
62*61c4878aSAndroid Build Coastguard Worker      :type: str
63*61c4878aSAndroid Build Coastguard Worker
64*61c4878aSAndroid Build Coastguard Worker      See  `cc_common.create_cc_toolchain_config_info() <https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info>`_\.
65*61c4878aSAndroid Build Coastguard Worker
66*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: compiler
67*61c4878aSAndroid Build Coastguard Worker      :type: str
68*61c4878aSAndroid Build Coastguard Worker
69*61c4878aSAndroid Build Coastguard Worker      See  `cc_common.create_cc_toolchain_config_info() <https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info>`_\.
70*61c4878aSAndroid Build Coastguard Worker
71*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: abi_version
72*61c4878aSAndroid Build Coastguard Worker      :type: str
73*61c4878aSAndroid Build Coastguard Worker
74*61c4878aSAndroid Build Coastguard Worker      See  `cc_common.create_cc_toolchain_config_info() <https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info>`_\.
75*61c4878aSAndroid Build Coastguard Worker
76*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: abi_libc_version
77*61c4878aSAndroid Build Coastguard Worker      :type: str
78*61c4878aSAndroid Build Coastguard Worker
79*61c4878aSAndroid Build Coastguard Worker      See  `cc_common.create_cc_toolchain_config_info() <https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info>`_\.
80*61c4878aSAndroid Build Coastguard Worker
81*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: cc_target_os
82*61c4878aSAndroid Build Coastguard Worker      :type: str
83*61c4878aSAndroid Build Coastguard Worker
84*61c4878aSAndroid Build Coastguard Worker      See  `cc_common.create_cc_toolchain_config_info() <https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info>`_\.
85*61c4878aSAndroid Build Coastguard Worker
86*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: builtin_sysroot
87*61c4878aSAndroid Build Coastguard Worker      :type: str
88*61c4878aSAndroid Build Coastguard Worker
89*61c4878aSAndroid Build Coastguard Worker      See  `cc_common.create_cc_toolchain_config_info() <https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info>`_\.
90*61c4878aSAndroid Build Coastguard Worker
91*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: cxx_builtin_include_directories
92*61c4878aSAndroid Build Coastguard Worker      :type: List[str]
93*61c4878aSAndroid Build Coastguard Worker
94*61c4878aSAndroid Build Coastguard Worker      See  `cc_common.create_cc_toolchain_config_info() <https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info>`_\.
95*61c4878aSAndroid Build Coastguard Worker
96*61c4878aSAndroid Build Coastguard Worker.. py:class:: pw_cc_flag_set
97*61c4878aSAndroid Build Coastguard Worker
98*61c4878aSAndroid Build Coastguard Worker   Declares an ordered set of flags bound to a set of actions.
99*61c4878aSAndroid Build Coastguard Worker
100*61c4878aSAndroid Build Coastguard Worker   Flag sets can be attached to a :py:class:`pw_cc_toolchain` via
101*61c4878aSAndroid Build Coastguard Worker   :py:attr:`pw_cc_toolchain.flag_sets`\.
102*61c4878aSAndroid Build Coastguard Worker
103*61c4878aSAndroid Build Coastguard Worker   Examples:
104*61c4878aSAndroid Build Coastguard Worker
105*61c4878aSAndroid Build Coastguard Worker   .. code-block:: py
106*61c4878aSAndroid Build Coastguard Worker
107*61c4878aSAndroid Build Coastguard Worker      pw_cc_flag_set(
108*61c4878aSAndroid Build Coastguard Worker          name = "warnings_as_errors",
109*61c4878aSAndroid Build Coastguard Worker          flags = ["-Werror"],
110*61c4878aSAndroid Build Coastguard Worker      )
111*61c4878aSAndroid Build Coastguard Worker
112*61c4878aSAndroid Build Coastguard Worker      pw_cc_flag_set(
113*61c4878aSAndroid Build Coastguard Worker          name = "layering_check",
114*61c4878aSAndroid Build Coastguard Worker          flag_groups = [
115*61c4878aSAndroid Build Coastguard Worker              ":strict_module_headers",
116*61c4878aSAndroid Build Coastguard Worker              ":dependent_module_map_files",
117*61c4878aSAndroid Build Coastguard Worker          ],
118*61c4878aSAndroid Build Coastguard Worker      )
119*61c4878aSAndroid Build Coastguard Worker
120*61c4878aSAndroid Build Coastguard Worker   .. inclusive-language: disable
121*61c4878aSAndroid Build Coastguard Worker
122*61c4878aSAndroid Build Coastguard Worker   Note: In the vast majority of cases, alphabetical sorting is not desirable
123*61c4878aSAndroid Build Coastguard Worker   for the :py:attr:`pw_cc_flag_set.flags` and
124*61c4878aSAndroid Build Coastguard Worker   :py:attr:`pw_cc_flag_set.flag_groups` attributes.
125*61c4878aSAndroid Build Coastguard Worker   `Buildifier <https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md>`_
126*61c4878aSAndroid Build Coastguard Worker   shouldn't ever try to sort these, but in the off chance it starts to these
127*61c4878aSAndroid Build Coastguard Worker   members should be listed as exceptions in the ``SortableDenylist``.
128*61c4878aSAndroid Build Coastguard Worker
129*61c4878aSAndroid Build Coastguard Worker   .. inclusive-language: enable
130*61c4878aSAndroid Build Coastguard Worker
131*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: actions
132*61c4878aSAndroid Build Coastguard Worker      :type: List[str]
133*61c4878aSAndroid Build Coastguard Worker
134*61c4878aSAndroid Build Coastguard Worker      A list of action names that this flag set applies to.
135*61c4878aSAndroid Build Coastguard Worker
136*61c4878aSAndroid Build Coastguard Worker      .. inclusive-language: disable
137*61c4878aSAndroid Build Coastguard Worker
138*61c4878aSAndroid Build Coastguard Worker      Valid choices are listed at
139*61c4878aSAndroid Build Coastguard Worker      `@rules_cc//cc:action_names.bzl <https://github.com/bazelbuild/bazel/blob/master/tools/build_defs/cc/action_names.bzl>`_\.
140*61c4878aSAndroid Build Coastguard Worker
141*61c4878aSAndroid Build Coastguard Worker      .. inclusive-language: enable
142*61c4878aSAndroid Build Coastguard Worker
143*61c4878aSAndroid Build Coastguard Worker      It is possible for some needed action names to not be enumerated in this list,
144*61c4878aSAndroid Build Coastguard Worker      so there is not rigid validation for these strings. Prefer using constants
145*61c4878aSAndroid Build Coastguard Worker      rather than manually typing action names.
146*61c4878aSAndroid Build Coastguard Worker
147*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: flags
148*61c4878aSAndroid Build Coastguard Worker      :type: List[str]
149*61c4878aSAndroid Build Coastguard Worker
150*61c4878aSAndroid Build Coastguard Worker      Flags that should be applied to the specified actions.
151*61c4878aSAndroid Build Coastguard Worker
152*61c4878aSAndroid Build Coastguard Worker      These are evaluated in order, with earlier flags appearing earlier in the
153*61c4878aSAndroid Build Coastguard Worker      invocation of the underlying tool. If you need expansion logic, prefer
154*61c4878aSAndroid Build Coastguard Worker      enumerating flags in a :py:class:`pw_cc_flag_group` or create a custom
155*61c4878aSAndroid Build Coastguard Worker      rule that provides ``FlagGroupInfo``.
156*61c4878aSAndroid Build Coastguard Worker
157*61c4878aSAndroid Build Coastguard Worker      Note: :py:attr:`pw_cc_flag_set.flags` and
158*61c4878aSAndroid Build Coastguard Worker      :py:attr:`pw_cc_flag_set.flag_groups` are mutually exclusive.
159*61c4878aSAndroid Build Coastguard Worker
160*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: flag_groups
161*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
162*61c4878aSAndroid Build Coastguard Worker
163*61c4878aSAndroid Build Coastguard Worker      Labels pointing to :py:class:`pw_cc_flag_group` rules.
164*61c4878aSAndroid Build Coastguard Worker
165*61c4878aSAndroid Build Coastguard Worker      This is intended to be compatible with any other rules that provide
166*61c4878aSAndroid Build Coastguard Worker      ``FlagGroupInfo``. These are evaluated in order, with earlier flag groups
167*61c4878aSAndroid Build Coastguard Worker      appearing earlier in the invocation of the underlying tool.
168*61c4878aSAndroid Build Coastguard Worker
169*61c4878aSAndroid Build Coastguard Worker      Note: :py:attr:`pw_cc_flag_set.flag_groups` and
170*61c4878aSAndroid Build Coastguard Worker      :py:attr:`pw_cc_flag_set.flags` are mutually exclusive.
171*61c4878aSAndroid Build Coastguard Worker
172*61c4878aSAndroid Build Coastguard Worker.. py:class:: pw_cc_flag_group
173*61c4878aSAndroid Build Coastguard Worker
174*61c4878aSAndroid Build Coastguard Worker   Declares an (optionally parametric) ordered set of flags.
175*61c4878aSAndroid Build Coastguard Worker
176*61c4878aSAndroid Build Coastguard Worker   :py:class:`pw_cc_flag_group` rules are expected to be consumed exclusively by
177*61c4878aSAndroid Build Coastguard Worker   :py:class:`pw_cc_flag_set` rules. Though simple lists of flags can be
178*61c4878aSAndroid Build Coastguard Worker   expressed by populating ``flags`` on a :py:class:`pw_cc_flag_set`,
179*61c4878aSAndroid Build Coastguard Worker   :py:class:`pw_cc_flag_group` provides additional power in the following two
180*61c4878aSAndroid Build Coastguard Worker   ways:
181*61c4878aSAndroid Build Coastguard Worker
182*61c4878aSAndroid Build Coastguard Worker    1. Iteration and conditional expansion. Using
183*61c4878aSAndroid Build Coastguard Worker       :py:attr:`pw_cc_flag_group.iterate_over`,
184*61c4878aSAndroid Build Coastguard Worker       :py:attr:`pw_cc_flag_group.expand_if_available`\, and
185*61c4878aSAndroid Build Coastguard Worker       :py:attr:`pw_cc_flag_group.expand_if_not_available`\, more complex
186*61c4878aSAndroid Build Coastguard Worker       flag expressions can be made. This is critical for implementing things
187*61c4878aSAndroid Build Coastguard Worker       like the ``libraries_to_link`` feature, where library names are
188*61c4878aSAndroid Build Coastguard Worker       transformed into flags that end up in the final link invocation.
189*61c4878aSAndroid Build Coastguard Worker
190*61c4878aSAndroid Build Coastguard Worker       Note: ``expand_if_equal``, ``expand_if_true``, and ``expand_if_false``
191*61c4878aSAndroid Build Coastguard Worker       are not yet supported.
192*61c4878aSAndroid Build Coastguard Worker
193*61c4878aSAndroid Build Coastguard Worker    2. Flags are tool-independent. A :py:class:`pw_cc_flag_group` expresses
194*61c4878aSAndroid Build Coastguard Worker       ordered flags that may be reused across various
195*61c4878aSAndroid Build Coastguard Worker       :py:class:`pw_cc_flag_set` rules. This is useful for cases where multiple
196*61c4878aSAndroid Build Coastguard Worker       :py:class:`pw_cc_flag_set` rules must be created to implement a feature
197*61c4878aSAndroid Build Coastguard Worker       for which flags are slightly different depending on the action (e.g.
198*61c4878aSAndroid Build Coastguard Worker       compile vs link). Common flags can be expressed in a shared
199*61c4878aSAndroid Build Coastguard Worker       :py:class:`pw_cc_flag_group`, and the differences can be relegated to
200*61c4878aSAndroid Build Coastguard Worker       separate :py:class:`pw_cc_flag_group` instances.
201*61c4878aSAndroid Build Coastguard Worker
202*61c4878aSAndroid Build Coastguard Worker   Examples:
203*61c4878aSAndroid Build Coastguard Worker
204*61c4878aSAndroid Build Coastguard Worker   .. code-block:: py
205*61c4878aSAndroid Build Coastguard Worker
206*61c4878aSAndroid Build Coastguard Worker      pw_cc_flag_group(
207*61c4878aSAndroid Build Coastguard Worker          name = "user_compile_flag_expansion",
208*61c4878aSAndroid Build Coastguard Worker          flags = ["%{user_compile_flags}"],
209*61c4878aSAndroid Build Coastguard Worker          iterate_over = "user_compile_flags",
210*61c4878aSAndroid Build Coastguard Worker          expand_if_available = "user_compile_flags",
211*61c4878aSAndroid Build Coastguard Worker      )
212*61c4878aSAndroid Build Coastguard Worker
213*61c4878aSAndroid Build Coastguard Worker      # This flag_group might be referenced from various FDO-related
214*61c4878aSAndroid Build Coastguard Worker      # `pw_cc_flag_set` rules. More importantly, the flag sets pulling this in
215*61c4878aSAndroid Build Coastguard Worker      # may apply to different sets of actions.
216*61c4878aSAndroid Build Coastguard Worker      pw_cc_flag_group(
217*61c4878aSAndroid Build Coastguard Worker          name = "fdo_profile_correction",
218*61c4878aSAndroid Build Coastguard Worker          flags = ["-fprofile-correction"],
219*61c4878aSAndroid Build Coastguard Worker          expand_if_available = "fdo_profile_path",
220*61c4878aSAndroid Build Coastguard Worker      )
221*61c4878aSAndroid Build Coastguard Worker
222*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: flags
223*61c4878aSAndroid Build Coastguard Worker      :type: List[str]
224*61c4878aSAndroid Build Coastguard Worker
225*61c4878aSAndroid Build Coastguard Worker      List of flags provided by this rule.
226*61c4878aSAndroid Build Coastguard Worker
227*61c4878aSAndroid Build Coastguard Worker      For extremely complex expressions of flags that require nested flag groups
228*61c4878aSAndroid Build Coastguard Worker      with multiple layers of expansion, prefer creating a custom rule in
229*61c4878aSAndroid Build Coastguard Worker      `Starlark <https://bazel.build/rules/language>`_ that provides
230*61c4878aSAndroid Build Coastguard Worker      ``FlagGroupInfo`` or ``FlagSetInfo``.
231*61c4878aSAndroid Build Coastguard Worker
232*61c4878aSAndroid Build Coastguard Worker
233*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: iterate_over
234*61c4878aSAndroid Build Coastguard Worker      :type: str
235*61c4878aSAndroid Build Coastguard Worker
236*61c4878aSAndroid Build Coastguard Worker      Expands :py:attr:`pw_cc_flag_group.flags` for items in the named list.
237*61c4878aSAndroid Build Coastguard Worker
238*61c4878aSAndroid Build Coastguard Worker      Toolchain actions have various variables accessible as names that can be
239*61c4878aSAndroid Build Coastguard Worker      used to guide flag expansions. For variables that are lists,
240*61c4878aSAndroid Build Coastguard Worker      :py:attr:`pw_cc_flag_group.iterate_over` must be used to expand the list into a series of flags.
241*61c4878aSAndroid Build Coastguard Worker
242*61c4878aSAndroid Build Coastguard Worker      Note that :py:attr:`pw_cc_flag_group.iterate_over` is the string name of a
243*61c4878aSAndroid Build Coastguard Worker      build variable, and not an actual list. Valid options are listed in the
244*61c4878aSAndroid Build Coastguard Worker      `C++ Toolchain Configuration <https://bazel.build/docs/cc-toolchain-config-reference#cctoolchainconfiginfo-build-variables>`_
245*61c4878aSAndroid Build Coastguard Worker      reference.
246*61c4878aSAndroid Build Coastguard Worker
247*61c4878aSAndroid Build Coastguard Worker
248*61c4878aSAndroid Build Coastguard Worker
249*61c4878aSAndroid Build Coastguard Worker      Note that the flag expansion stamps out the entire list of flags in
250*61c4878aSAndroid Build Coastguard Worker      :py:attr:`pw_cc_flag_group.flags` once for each item in the list.
251*61c4878aSAndroid Build Coastguard Worker
252*61c4878aSAndroid Build Coastguard Worker      Example:
253*61c4878aSAndroid Build Coastguard Worker
254*61c4878aSAndroid Build Coastguard Worker      .. code-block:: py
255*61c4878aSAndroid Build Coastguard Worker
256*61c4878aSAndroid Build Coastguard Worker         # Expands each path in ``system_include_paths`` to a series of
257*61c4878aSAndroid Build Coastguard Worker         # ``-isystem`` includes.
258*61c4878aSAndroid Build Coastguard Worker         #
259*61c4878aSAndroid Build Coastguard Worker         # Example input:
260*61c4878aSAndroid Build Coastguard Worker         #     system_include_paths = ["/usr/local/include", "/usr/include"]
261*61c4878aSAndroid Build Coastguard Worker         #
262*61c4878aSAndroid Build Coastguard Worker         # Expected result:
263*61c4878aSAndroid Build Coastguard Worker         #     "-isystem /usr/local/include -isystem /usr/include"
264*61c4878aSAndroid Build Coastguard Worker         pw_cc_flag_group(
265*61c4878aSAndroid Build Coastguard Worker             name = "system_include_paths",
266*61c4878aSAndroid Build Coastguard Worker             flags = ["-isystem", "%{system_include_paths}"],
267*61c4878aSAndroid Build Coastguard Worker             iterate_over = "system_include_paths",
268*61c4878aSAndroid Build Coastguard Worker         )
269*61c4878aSAndroid Build Coastguard Worker
270*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: expand_if_available
271*61c4878aSAndroid Build Coastguard Worker      :type: str
272*61c4878aSAndroid Build Coastguard Worker
273*61c4878aSAndroid Build Coastguard Worker      Expands the expression in :py:attr:`pw_cc_flag_group.flags` if the
274*61c4878aSAndroid Build Coastguard Worker      specified build variable is set.
275*61c4878aSAndroid Build Coastguard Worker
276*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: expand_if_not_available
277*61c4878aSAndroid Build Coastguard Worker      :type: str
278*61c4878aSAndroid Build Coastguard Worker
279*61c4878aSAndroid Build Coastguard Worker      Expands the expression in :py:attr:`pw_cc_flag_group.flags` if the
280*61c4878aSAndroid Build Coastguard Worker      specified build variable is **NOT** set.
281*61c4878aSAndroid Build Coastguard Worker
282*61c4878aSAndroid Build Coastguard Worker.. py:class:: pw_cc_tool
283*61c4878aSAndroid Build Coastguard Worker
284*61c4878aSAndroid Build Coastguard Worker   Declares a singular tool that can be bound to action configs.
285*61c4878aSAndroid Build Coastguard Worker
286*61c4878aSAndroid Build Coastguard Worker   :py:class:`pw_cc_tool` rules are intended to be consumed exclusively by
287*61c4878aSAndroid Build Coastguard Worker   :py:class:`pw_cc_action_config` rules. These rules declare an underlying tool
288*61c4878aSAndroid Build Coastguard Worker   that can be used to fulfill various actions. Many actions may reuse a shared
289*61c4878aSAndroid Build Coastguard Worker   tool.
290*61c4878aSAndroid Build Coastguard Worker
291*61c4878aSAndroid Build Coastguard Worker   Examples:
292*61c4878aSAndroid Build Coastguard Worker
293*61c4878aSAndroid Build Coastguard Worker   .. code-block:: py
294*61c4878aSAndroid Build Coastguard Worker
295*61c4878aSAndroid Build Coastguard Worker      # A project-provided tool.
296*61c4878aSAndroid Build Coastguard Worker      pw_cc_tool(
297*61c4878aSAndroid Build Coastguard Worker          name = "clang_tool",
298*61c4878aSAndroid Build Coastguard Worker          tool = "@llvm_toolchain//:bin/clang",
299*61c4878aSAndroid Build Coastguard Worker      )
300*61c4878aSAndroid Build Coastguard Worker
301*61c4878aSAndroid Build Coastguard Worker      # A tool expected to be preinstalled on a user's machine.
302*61c4878aSAndroid Build Coastguard Worker      pw_cc_tool(
303*61c4878aSAndroid Build Coastguard Worker          name = "clang_tool",
304*61c4878aSAndroid Build Coastguard Worker          path = "/usr/bin/clang",
305*61c4878aSAndroid Build Coastguard Worker      )
306*61c4878aSAndroid Build Coastguard Worker
307*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: tool
308*61c4878aSAndroid Build Coastguard Worker      :type: label
309*61c4878aSAndroid Build Coastguard Worker
310*61c4878aSAndroid Build Coastguard Worker      The underlying tool that this rule represents.
311*61c4878aSAndroid Build Coastguard Worker
312*61c4878aSAndroid Build Coastguard Worker      This attribute is a label rather than a simple file path. This means that
313*61c4878aSAndroid Build Coastguard Worker      the file must be referenced relative to the BUILD file that exports it.
314*61c4878aSAndroid Build Coastguard Worker      For example:
315*61c4878aSAndroid Build Coastguard Worker
316*61c4878aSAndroid Build Coastguard Worker      .. code-block:: none
317*61c4878aSAndroid Build Coastguard Worker
318*61c4878aSAndroid Build Coastguard Worker         @llvm_toolchain//:bin/clang
319*61c4878aSAndroid Build Coastguard Worker         ^              ^  ^
320*61c4878aSAndroid Build Coastguard Worker
321*61c4878aSAndroid Build Coastguard Worker      Where:
322*61c4878aSAndroid Build Coastguard Worker
323*61c4878aSAndroid Build Coastguard Worker      * ``@llvm_toolchain`` is the repository.
324*61c4878aSAndroid Build Coastguard Worker      * ``//`` is the directory of the BUILD file that exports the file of
325*61c4878aSAndroid Build Coastguard Worker        interest.
326*61c4878aSAndroid Build Coastguard Worker      * ``bin/clang`` is the path of the actual binary relative to the BUILD
327*61c4878aSAndroid Build Coastguard Worker        file of interest.
328*61c4878aSAndroid Build Coastguard Worker
329*61c4878aSAndroid Build Coastguard Worker      Note: :py:attr:`pw_cc_tool.tool` and :py:attr:`pw_cc_tool.path` are
330*61c4878aSAndroid Build Coastguard Worker      mutually exclusive.
331*61c4878aSAndroid Build Coastguard Worker
332*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: path
333*61c4878aSAndroid Build Coastguard Worker      :type: Path
334*61c4878aSAndroid Build Coastguard Worker
335*61c4878aSAndroid Build Coastguard Worker      An absolute path to a binary to use for this tool.
336*61c4878aSAndroid Build Coastguard Worker
337*61c4878aSAndroid Build Coastguard Worker      Relative paths are also supported, but they are relative to the
338*61c4878aSAndroid Build Coastguard Worker      :py:class:`pw_cc_toolchain` that uses this tool rather than relative to
339*61c4878aSAndroid Build Coastguard Worker      this :py:class:`pw_cc_tool` rule.
340*61c4878aSAndroid Build Coastguard Worker
341*61c4878aSAndroid Build Coastguard Worker      Note: :py:attr:`pw_cc_tool.path` and :py:attr:`pw_cc_tool.tool` are
342*61c4878aSAndroid Build Coastguard Worker      mutually exclusive.
343*61c4878aSAndroid Build Coastguard Worker
344*61c4878aSAndroid Build Coastguard Worker      .. admonition:: Note
345*61c4878aSAndroid Build Coastguard Worker         :class: warning
346*61c4878aSAndroid Build Coastguard Worker
347*61c4878aSAndroid Build Coastguard Worker         This method of listing a tool is NOT recommended, and is provided as an
348*61c4878aSAndroid Build Coastguard Worker         escape hatch for edge cases. Prefer using :py:attr:`pw_cc_tool.tool`
349*61c4878aSAndroid Build Coastguard Worker         whenever possible.
350*61c4878aSAndroid Build Coastguard Worker
351*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: execution_requirements
352*61c4878aSAndroid Build Coastguard Worker      :type: List[str]
353*61c4878aSAndroid Build Coastguard Worker
354*61c4878aSAndroid Build Coastguard Worker      A list of strings that provide hints for execution environment
355*61c4878aSAndroid Build Coastguard Worker      compatibility (e.g. ``requires-darwin``).
356*61c4878aSAndroid Build Coastguard Worker
357*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: requires_any_of
358*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
359*61c4878aSAndroid Build Coastguard Worker
360*61c4878aSAndroid Build Coastguard Worker      This tool may only be enabled when at least one of the constraints are
361*61c4878aSAndroid Build Coastguard Worker      met.
362*61c4878aSAndroid Build Coastguard Worker
363*61c4878aSAndroid Build Coastguard Worker      If omitted, this tool will be enabled unconditionally.
364*61c4878aSAndroid Build Coastguard Worker
365*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: additional_files
366*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
367*61c4878aSAndroid Build Coastguard Worker
368*61c4878aSAndroid Build Coastguard Worker      Additional files that are required for this tool to correctly operate.
369*61c4878aSAndroid Build Coastguard Worker      These files are propagated up to the :py:class:`pw_cc_toolchain` so you
370*61c4878aSAndroid Build Coastguard Worker      typically won't need to explicitly specify the ``*_files`` attributes
371*61c4878aSAndroid Build Coastguard Worker      on a :py:class:`pw_cc_toolchain`.
372*61c4878aSAndroid Build Coastguard Worker
373*61c4878aSAndroid Build Coastguard Worker
374*61c4878aSAndroid Build Coastguard Worker.. py:class:: pw_cc_action_config
375*61c4878aSAndroid Build Coastguard Worker
376*61c4878aSAndroid Build Coastguard Worker   Declares the configuration and selection of `pw_cc_tool` rules.
377*61c4878aSAndroid Build Coastguard Worker
378*61c4878aSAndroid Build Coastguard Worker   Action configs are bound to a toolchain through `action_configs`, and are the
379*61c4878aSAndroid Build Coastguard Worker   driving mechanism for controlling toolchain tool invocation/behavior.
380*61c4878aSAndroid Build Coastguard Worker
381*61c4878aSAndroid Build Coastguard Worker   Action configs define three key things:
382*61c4878aSAndroid Build Coastguard Worker
383*61c4878aSAndroid Build Coastguard Worker   * Which tools to invoke for a given type of action.
384*61c4878aSAndroid Build Coastguard Worker   * Tool features and compatibility.
385*61c4878aSAndroid Build Coastguard Worker   * :py:class:`pw_cc_flag_set`\s that are unconditionally bound to a tool
386*61c4878aSAndroid Build Coastguard Worker     invocation.
387*61c4878aSAndroid Build Coastguard Worker
388*61c4878aSAndroid Build Coastguard Worker   Examples:
389*61c4878aSAndroid Build Coastguard Worker
390*61c4878aSAndroid Build Coastguard Worker   .. code-block:: py
391*61c4878aSAndroid Build Coastguard Worker
392*61c4878aSAndroid Build Coastguard Worker      pw_cc_action_config(
393*61c4878aSAndroid Build Coastguard Worker          name = "ar",
394*61c4878aSAndroid Build Coastguard Worker          action_names = ["@pw_toolchain//actions:all_ar_actions"],
395*61c4878aSAndroid Build Coastguard Worker          implies = [
396*61c4878aSAndroid Build Coastguard Worker              "@pw_toolchain//features/legacy:archiver_flags",
397*61c4878aSAndroid Build Coastguard Worker              "@pw_toolchain//features/legacy:linker_param_file",
398*61c4878aSAndroid Build Coastguard Worker          ],
399*61c4878aSAndroid Build Coastguard Worker          tools = [":ar_tool"],
400*61c4878aSAndroid Build Coastguard Worker      )
401*61c4878aSAndroid Build Coastguard Worker
402*61c4878aSAndroid Build Coastguard Worker      pw_cc_action_config(
403*61c4878aSAndroid Build Coastguard Worker          name = "clang",
404*61c4878aSAndroid Build Coastguard Worker          action_names = [
405*61c4878aSAndroid Build Coastguard Worker              "@pw_toolchain//actions:all_asm_actions",
406*61c4878aSAndroid Build Coastguard Worker              "@pw_toolchain//actions:all_c_compiler_actions",
407*61c4878aSAndroid Build Coastguard Worker          ]
408*61c4878aSAndroid Build Coastguard Worker          tools = [":clang_tool"],
409*61c4878aSAndroid Build Coastguard Worker      )
410*61c4878aSAndroid Build Coastguard Worker
411*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: action_names
412*61c4878aSAndroid Build Coastguard Worker      :type: List[str]
413*61c4878aSAndroid Build Coastguard Worker
414*61c4878aSAndroid Build Coastguard Worker      A list of action names to apply this action to.
415*61c4878aSAndroid Build Coastguard Worker
416*61c4878aSAndroid Build Coastguard Worker      .. inclusive-language: disable
417*61c4878aSAndroid Build Coastguard Worker
418*61c4878aSAndroid Build Coastguard Worker      Valid choices are listed at
419*61c4878aSAndroid Build Coastguard Worker      `@rules_cc//cc:action_names.bzl <https://github.com/bazelbuild/bazel/blob/master/tools/build_defs/cc/action_names.bzl>`_\.
420*61c4878aSAndroid Build Coastguard Worker
421*61c4878aSAndroid Build Coastguard Worker      .. inclusive-language: enable
422*61c4878aSAndroid Build Coastguard Worker
423*61c4878aSAndroid Build Coastguard Worker      It is possible for some needed action names to not be enumerated in this list,
424*61c4878aSAndroid Build Coastguard Worker      so there is not rigid validation for these strings. Prefer using constants
425*61c4878aSAndroid Build Coastguard Worker      rather than manually typing action names.
426*61c4878aSAndroid Build Coastguard Worker
427*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: enabled
428*61c4878aSAndroid Build Coastguard Worker      :type: bool
429*61c4878aSAndroid Build Coastguard Worker
430*61c4878aSAndroid Build Coastguard Worker      Whether or not this action config is enabled by default.
431*61c4878aSAndroid Build Coastguard Worker
432*61c4878aSAndroid Build Coastguard Worker      .. admonition:: Note
433*61c4878aSAndroid Build Coastguard Worker
434*61c4878aSAndroid Build Coastguard Worker         This defaults to ``True`` since it's assumed that most listed action
435*61c4878aSAndroid Build Coastguard Worker         configs will be enabled and used by default. This is the opposite of
436*61c4878aSAndroid Build Coastguard Worker         Bazel's native default.
437*61c4878aSAndroid Build Coastguard Worker
438*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: tools
439*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
440*61c4878aSAndroid Build Coastguard Worker
441*61c4878aSAndroid Build Coastguard Worker      The tool to use for the specified actions.
442*61c4878aSAndroid Build Coastguard Worker
443*61c4878aSAndroid Build Coastguard Worker      A tool can be a :py:class:`pw_cc_tool`, or a binary.
444*61c4878aSAndroid Build Coastguard Worker
445*61c4878aSAndroid Build Coastguard Worker      If multiple tools are specified, the first tool that has ``with_features``
446*61c4878aSAndroid Build Coastguard Worker      that satisfy the currently enabled feature set is used.
447*61c4878aSAndroid Build Coastguard Worker
448*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: flag_sets
449*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
450*61c4878aSAndroid Build Coastguard Worker
451*61c4878aSAndroid Build Coastguard Worker      Labels that point to :py:class:`pw_cc_flag_set`\s that are unconditionally
452*61c4878aSAndroid Build Coastguard Worker      bound to the specified actions.
453*61c4878aSAndroid Build Coastguard Worker
454*61c4878aSAndroid Build Coastguard Worker      .. admonition:: Note
455*61c4878aSAndroid Build Coastguard Worker
456*61c4878aSAndroid Build Coastguard Worker         The flags in the :py:class:`pw_cc_flag_set` are only bound to matching
457*61c4878aSAndroid Build Coastguard Worker         action names. If an action is listed in this rule's
458*61c4878aSAndroid Build Coastguard Worker         :py:attr:`pw_cc_action_config.action_names`,
459*61c4878aSAndroid Build Coastguard Worker         but is NOT listed in the :py:class:`pw_cc_flag_set`\'s
460*61c4878aSAndroid Build Coastguard Worker         :py:attr:`pw_cc_flag_set.actions`, the flag will not be applied to that
461*61c4878aSAndroid Build Coastguard Worker         action.
462*61c4878aSAndroid Build Coastguard Worker
463*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: implies
464*61c4878aSAndroid Build Coastguard Worker      :type: List[str]
465*61c4878aSAndroid Build Coastguard Worker
466*61c4878aSAndroid Build Coastguard Worker      Names of features that should be automatically enabled when this tool is
467*61c4878aSAndroid Build Coastguard Worker      used.
468*61c4878aSAndroid Build Coastguard Worker
469*61c4878aSAndroid Build Coastguard Worker      .. admonition:: Note
470*61c4878aSAndroid Build Coastguard Worker         :class: warning
471*61c4878aSAndroid Build Coastguard Worker
472*61c4878aSAndroid Build Coastguard Worker         If this action config implies an unknown feature, this action config
473*61c4878aSAndroid Build Coastguard Worker         will silently be disabled. This behavior is native to Bazel itself, and
474*61c4878aSAndroid Build Coastguard Worker         there's no way to detect this and emit an error instead. For this
475*61c4878aSAndroid Build Coastguard Worker         reason, be very cautious when listing implied features!
476*61c4878aSAndroid Build Coastguard Worker
477*61c4878aSAndroid Build Coastguard Worker.. py:class:: pw_cc_feature
478*61c4878aSAndroid Build Coastguard Worker
479*61c4878aSAndroid Build Coastguard Worker   Defines the implemented behavior of a C/C++ toolchain feature.
480*61c4878aSAndroid Build Coastguard Worker
481*61c4878aSAndroid Build Coastguard Worker
482*61c4878aSAndroid Build Coastguard Worker   This rule is effectively a wrapper for the ``feature`` constructor in
483*61c4878aSAndroid Build Coastguard Worker   `@rules_cc//cc:cc_toolchain_config_lib.bzl <https://github.com/bazelbuild/rules_cc/blob/main/cc/cc_toolchain_config_lib.bzl>`_.
484*61c4878aSAndroid Build Coastguard Worker
485*61c4878aSAndroid Build Coastguard Worker   A feature is basically a dynamic flag set. There are a variety of
486*61c4878aSAndroid Build Coastguard Worker   dependencies and compatibility requirements that must be satisfied for the
487*61c4878aSAndroid Build Coastguard Worker   listed flag sets to be applied.
488*61c4878aSAndroid Build Coastguard Worker
489*61c4878aSAndroid Build Coastguard Worker   A feature may be enabled or disabled through the following mechanisms:\
490*61c4878aSAndroid Build Coastguard Worker
491*61c4878aSAndroid Build Coastguard Worker   * Via command-line flags, or a
492*61c4878aSAndroid Build Coastguard Worker     `.bazelrc file <https://bazel.build/run/bazelrc>`_\.
493*61c4878aSAndroid Build Coastguard Worker   * Through inter-feature relationships (enabling one feature may implicitly
494*61c4878aSAndroid Build Coastguard Worker     enable another).
495*61c4878aSAndroid Build Coastguard Worker   * Individual rules may elect to manually enable or disable features through
496*61c4878aSAndroid Build Coastguard Worker     the
497*61c4878aSAndroid Build Coastguard Worker     `builtin features attribute <https://bazel.build/reference/be/common-definitions#common.features>`_\.
498*61c4878aSAndroid Build Coastguard Worker
499*61c4878aSAndroid Build Coastguard Worker   Because of the dynamic nature of toolchain features, it's generally best to
500*61c4878aSAndroid Build Coastguard Worker   avoid enumerating features as part of your toolchain with the following
501*61c4878aSAndroid Build Coastguard Worker   exceptions:
502*61c4878aSAndroid Build Coastguard Worker
503*61c4878aSAndroid Build Coastguard Worker   * You want the flags to be controllable via Bazel's CLI. For example, adding
504*61c4878aSAndroid Build Coastguard Worker     ``-v`` to a compiler invocation is often too verbose to be useful for most
505*61c4878aSAndroid Build Coastguard Worker     workflows, but can be instrumental when debugging obscure errors. By
506*61c4878aSAndroid Build Coastguard Worker     expressing compiler verbosity as a feature, users may opt-in when
507*61c4878aSAndroid Build Coastguard Worker     necessary.
508*61c4878aSAndroid Build Coastguard Worker   * You need to carry forward Starlark toolchain behaviors. If you're migrating
509*61c4878aSAndroid Build Coastguard Worker     a complex Starlark-based toolchain definition to these rules, many of the
510*61c4878aSAndroid Build Coastguard Worker     workflows and flags were likely based on features. This rule exists to
511*61c4878aSAndroid Build Coastguard Worker     support those existing structures.
512*61c4878aSAndroid Build Coastguard Worker
513*61c4878aSAndroid Build Coastguard Worker   For more details about how Bazel handles features, see the official Bazel
514*61c4878aSAndroid Build Coastguard Worker   documentation at
515*61c4878aSAndroid Build Coastguard Worker   https://bazel.build/docs/cc-toolchain-config-reference#features.
516*61c4878aSAndroid Build Coastguard Worker
517*61c4878aSAndroid Build Coastguard Worker   Note: ``env_sets`` are not yet supported.
518*61c4878aSAndroid Build Coastguard Worker
519*61c4878aSAndroid Build Coastguard Worker   Examples:
520*61c4878aSAndroid Build Coastguard Worker
521*61c4878aSAndroid Build Coastguard Worker   .. code-block:: py
522*61c4878aSAndroid Build Coastguard Worker
523*61c4878aSAndroid Build Coastguard Worker      # A feature that can be easily toggled to include extra compiler output to
524*61c4878aSAndroid Build Coastguard Worker      # help debug things like include search path ordering and showing all the
525*61c4878aSAndroid Build Coastguard Worker      # flags passed to the compiler.
526*61c4878aSAndroid Build Coastguard Worker      #
527*61c4878aSAndroid Build Coastguard Worker      # Add `--features=verbose_compiler_output` to your Bazel invocation to
528*61c4878aSAndroid Build Coastguard Worker      # enable.
529*61c4878aSAndroid Build Coastguard Worker      pw_cc_feature(
530*61c4878aSAndroid Build Coastguard Worker          name = "verbose_compiler_output",
531*61c4878aSAndroid Build Coastguard Worker          enabled = False,
532*61c4878aSAndroid Build Coastguard Worker          feature_name = "verbose_compiler_output",
533*61c4878aSAndroid Build Coastguard Worker          flag_sets = [":verbose_compiler_flags"],
534*61c4878aSAndroid Build Coastguard Worker      )
535*61c4878aSAndroid Build Coastguard Worker
536*61c4878aSAndroid Build Coastguard Worker      # This feature signals a capability, and doesn't have associated flags.
537*61c4878aSAndroid Build Coastguard Worker      #
538*61c4878aSAndroid Build Coastguard Worker      # For a list of well-known features, see:
539*61c4878aSAndroid Build Coastguard Worker      #    https://bazel.build/docs/cc-toolchain-config-reference#wellknown-features
540*61c4878aSAndroid Build Coastguard Worker      pw_cc_feature(
541*61c4878aSAndroid Build Coastguard Worker          name = "link_object_files",
542*61c4878aSAndroid Build Coastguard Worker          enabled = True,
543*61c4878aSAndroid Build Coastguard Worker          feature_name = "supports_start_end_lib",
544*61c4878aSAndroid Build Coastguard Worker      )
545*61c4878aSAndroid Build Coastguard Worker
546*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: feature_name
547*61c4878aSAndroid Build Coastguard Worker      :type: str
548*61c4878aSAndroid Build Coastguard Worker
549*61c4878aSAndroid Build Coastguard Worker      The name of the feature that this rule implements.
550*61c4878aSAndroid Build Coastguard Worker
551*61c4878aSAndroid Build Coastguard Worker      Feature names are used to express feature dependencies and compatibility.
552*61c4878aSAndroid Build Coastguard Worker      Because features are tracked by string names rather than labels, there's
553*61c4878aSAndroid Build Coastguard Worker      great flexibility in swapping out feature implementations or overriding
554*61c4878aSAndroid Build Coastguard Worker      the built-in legacy features that Bazel silently binds to every
555*61c4878aSAndroid Build Coastguard Worker      toolchain.
556*61c4878aSAndroid Build Coastguard Worker
557*61c4878aSAndroid Build Coastguard Worker      :py:attr:`pw_cc_feature.feature_name` is used rather than ``name`` to
558*61c4878aSAndroid Build Coastguard Worker      distinguish between the rule name, and the intended final feature name.
559*61c4878aSAndroid Build Coastguard Worker      This allows similar rules to exist in the same package, even if slight
560*61c4878aSAndroid Build Coastguard Worker      differences are required.
561*61c4878aSAndroid Build Coastguard Worker
562*61c4878aSAndroid Build Coastguard Worker      Example:
563*61c4878aSAndroid Build Coastguard Worker
564*61c4878aSAndroid Build Coastguard Worker      .. code-block:: py
565*61c4878aSAndroid Build Coastguard Worker
566*61c4878aSAndroid Build Coastguard Worker         pw_cc_feature(
567*61c4878aSAndroid Build Coastguard Worker             name = "sysroot_macos",
568*61c4878aSAndroid Build Coastguard Worker             feature_name = "sysroot",
569*61c4878aSAndroid Build Coastguard Worker             ...
570*61c4878aSAndroid Build Coastguard Worker         )
571*61c4878aSAndroid Build Coastguard Worker
572*61c4878aSAndroid Build Coastguard Worker         pw_cc_feature(
573*61c4878aSAndroid Build Coastguard Worker             name = "sysroot_linux",
574*61c4878aSAndroid Build Coastguard Worker             feature_name = "sysroot",
575*61c4878aSAndroid Build Coastguard Worker             ...
576*61c4878aSAndroid Build Coastguard Worker         )
577*61c4878aSAndroid Build Coastguard Worker
578*61c4878aSAndroid Build Coastguard Worker      While two features with the same :py:attr:`pw_cc_feature.feature_name` may
579*61c4878aSAndroid Build Coastguard Worker      not be bound to the same toolchain, they can happily live alongside each
580*61c4878aSAndroid Build Coastguard Worker      other in the same BUILD file.
581*61c4878aSAndroid Build Coastguard Worker
582*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: enabled
583*61c4878aSAndroid Build Coastguard Worker      :type: bool
584*61c4878aSAndroid Build Coastguard Worker
585*61c4878aSAndroid Build Coastguard Worker      Whether or not this feature is enabled by default.
586*61c4878aSAndroid Build Coastguard Worker
587*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: flag_sets
588*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
589*61c4878aSAndroid Build Coastguard Worker
590*61c4878aSAndroid Build Coastguard Worker      Flag sets that, when expanded, implement this feature.
591*61c4878aSAndroid Build Coastguard Worker
592*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: requires_any_of
593*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
594*61c4878aSAndroid Build Coastguard Worker
595*61c4878aSAndroid Build Coastguard Worker      A list of feature sets that define toolchain compatibility.
596*61c4878aSAndroid Build Coastguard Worker
597*61c4878aSAndroid Build Coastguard Worker      If **at least one** of the listed :py:class:`pw_cc_feature`\s or
598*61c4878aSAndroid Build Coastguard Worker      :py:class:`pw_cc_feature_set`\s are satisfied (all features exist in the
599*61c4878aSAndroid Build Coastguard Worker      toolchain AND are currently enabled), this feature is deemed compatible
600*61c4878aSAndroid Build Coastguard Worker      and may be enabled.
601*61c4878aSAndroid Build Coastguard Worker
602*61c4878aSAndroid Build Coastguard Worker      If this feature **cannot** be enabled (such as if, in the first example
603*61c4878aSAndroid Build Coastguard Worker      below, thin_lto didn't exist in the toolchain), it will throw an error.
604*61c4878aSAndroid Build Coastguard Worker
605*61c4878aSAndroid Build Coastguard Worker      .. code-block:: py
606*61c4878aSAndroid Build Coastguard Worker
607*61c4878aSAndroid Build Coastguard Worker         pw_cc_feature(
608*61c4878aSAndroid Build Coastguard Worker             name = "requires_thin_lto_and_opt",
609*61c4878aSAndroid Build Coastguard Worker             feature_name = "requires_thin_lto_and_opt",
610*61c4878aSAndroid Build Coastguard Worker             requires_any_of = [":thin_lto_requirements"]
611*61c4878aSAndroid Build Coastguard Worker         )
612*61c4878aSAndroid Build Coastguard Worker
613*61c4878aSAndroid Build Coastguard Worker         pw_cc_feature(
614*61c4878aSAndroid Build Coastguard Worker             name = "requires_thin_lto_or_opt",
615*61c4878aSAndroid Build Coastguard Worker             feature_name = "requires_thin_lto_or_opt",
616*61c4878aSAndroid Build Coastguard Worker             requires_any_of = [":thin_lto", ":opt"]
617*61c4878aSAndroid Build Coastguard Worker         )
618*61c4878aSAndroid Build Coastguard Worker
619*61c4878aSAndroid Build Coastguard Worker      .. admonition:: Note
620*61c4878aSAndroid Build Coastguard Worker
621*61c4878aSAndroid Build Coastguard Worker         Even if :py:attr:`pw_cc_feature.requires_any_of` is satisfied, a
622*61c4878aSAndroid Build Coastguard Worker         feature is not enabled unless another mechanism (e.g. command-line
623*61c4878aSAndroid Build Coastguard Worker         flags, :py:attr:`pw_cc_feature.implies`, or
624*61c4878aSAndroid Build Coastguard Worker         :py:attr:`pw_cc_feature.enabled`\) signals that the feature should
625*61c4878aSAndroid Build Coastguard Worker         actually be enabled.
626*61c4878aSAndroid Build Coastguard Worker
627*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: implies
628*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
629*61c4878aSAndroid Build Coastguard Worker
630*61c4878aSAndroid Build Coastguard Worker      List of features or action configs enabled along with this feature.
631*61c4878aSAndroid Build Coastguard Worker
632*61c4878aSAndroid Build Coastguard Worker      .. admonition:: Note
633*61c4878aSAndroid Build Coastguard Worker         :class: warning
634*61c4878aSAndroid Build Coastguard Worker
635*61c4878aSAndroid Build Coastguard Worker         If any of the named features cannot be enabled, this feature is
636*61c4878aSAndroid Build Coastguard Worker         silently disabled.
637*61c4878aSAndroid Build Coastguard Worker
638*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: mutually_exclusive
639*61c4878aSAndroid Build Coastguard Worker      :type: List[Label]
640*61c4878aSAndroid Build Coastguard Worker
641*61c4878aSAndroid Build Coastguard Worker      A list of feature or mutually exclusive categories that this feature is
642*61c4878aSAndroid Build Coastguard Worker      mutually exclusive with.
643*61c4878aSAndroid Build Coastguard Worker
644*61c4878aSAndroid Build Coastguard Worker      .. admonition:: Note
645*61c4878aSAndroid Build Coastguard Worker
646*61c4878aSAndroid Build Coastguard Worker         This feature cannot be enabled if another feature also provides the
647*61c4878aSAndroid Build Coastguard Worker         listed feature.
648*61c4878aSAndroid Build Coastguard Worker
649*61c4878aSAndroid Build Coastguard Worker
650*61c4878aSAndroid Build Coastguard Worker.. py:class:: pw_cc_feature_set
651*61c4878aSAndroid Build Coastguard Worker
652*61c4878aSAndroid Build Coastguard Worker   Defines a group of features.
653*61c4878aSAndroid Build Coastguard Worker
654*61c4878aSAndroid Build Coastguard Worker   Semantically equivalent to "all of the specified features", and may be used
655*61c4878aSAndroid Build Coastguard Worker   wherever you can provide multiple features.
656*61c4878aSAndroid Build Coastguard Worker
657*61c4878aSAndroid Build Coastguard Worker   Example:
658*61c4878aSAndroid Build Coastguard Worker
659*61c4878aSAndroid Build Coastguard Worker   .. code-block:: py
660*61c4878aSAndroid Build Coastguard Worker
661*61c4878aSAndroid Build Coastguard Worker      pw_cc_feature_set(
662*61c4878aSAndroid Build Coastguard Worker          name = "thin_lto_requirements",
663*61c4878aSAndroid Build Coastguard Worker          all_of = [
664*61c4878aSAndroid Build Coastguard Worker              ":thin_lto",
665*61c4878aSAndroid Build Coastguard Worker              ":opt",
666*61c4878aSAndroid Build Coastguard Worker          ],
667*61c4878aSAndroid Build Coastguard Worker      )
668*61c4878aSAndroid Build Coastguard Worker
669*61c4878aSAndroid Build Coastguard Worker   .. py:attribute:: features
670*61c4878aSAndroid Build Coastguard Worker      :type: List[label]
671*61c4878aSAndroid Build Coastguard Worker
672*61c4878aSAndroid Build Coastguard Worker      Features that must be enabled for this feature set to be deemed compatible
673*61c4878aSAndroid Build Coastguard Worker      with the current toolchain configuration.
674