• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16# Until the providers are stabilized, ensure that rules_cc is the only place
17# that can access the providers directly.
18# Once it's stabilized, we *may* consider opening up parts of the API, or we may
19# decide to just require users to use the public user-facing rules.
20visibility([
21    "//cc/toolchains/...",
22    "//tests/rule_based_toolchain/...",
23])
24
25# Note that throughout this file, we never use a list. This is because mutable
26# types cannot be stored in depsets. Thus, we type them as a sequence in the
27# provider, and convert them to a tuple in the constructor to ensure
28# immutability.
29
30ActionTypeInfo = provider(
31    doc = "A type of action (eg. c-compile, c++-link-executable)",
32    # @unsorted-dict-items
33    fields = {
34        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
35        "name": "(str) The action name, as defined by action_names.bzl",
36    },
37)
38
39ActionTypeSetInfo = provider(
40    doc = "A set of types of actions",
41    # @unsorted-dict-items
42    fields = {
43        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
44        "actions": "(depset[ActionTypeInfo]) Set of action types",
45    },
46)
47
48VariableInfo = provider(
49    """A variable defined by the toolchain""",
50    # @unsorted-dict-items
51    fields = {
52        "name": "(str) The variable name",
53        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
54        "actions": "(Optional[depset[ActionTypeInfo]]) The actions this variable is available for",
55        "type": "A type constructed using variables.types.*",
56    },
57)
58
59BuiltinVariablesInfo = provider(
60    doc = "The builtin variables",
61    fields = {
62        "variables": "(dict[str, VariableInfo]) A mapping from variable name to variable metadata.",
63    },
64)
65
66NestedArgsInfo = provider(
67    doc = "A provider representation of Args.add/add_all/add_joined parameters",
68    # @unsorted-dict-items
69    fields = {
70        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
71        "nested": "(Sequence[NestedArgsInfo]) The nested arg expansion. Mutually exclusive with args",
72        "iterate_over": "(Optional[str]) The variable to iterate over",
73        "files": "(depset[File]) The files required to use this variable",
74        "requires_types": "(dict[str, str]) A mapping from variables to their expected type name (not type). This means that we can require the generic type Option, rather than an Option[T]",
75        "legacy_flag_group": "(flag_group) The flag_group this corresponds to",
76        "unwrap_options": "(List[str]) A list of variables for which we should unwrap the option. For example, if a user writes `requires_not_none = \":foo\"`, then we change the type of foo from Option[str] to str",
77    },
78)
79
80ArgsInfo = provider(
81    doc = "A set of arguments to be added to the command line for specific actions",
82    # @unsorted-dict-items
83    fields = {
84        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
85        "actions": "(depset[ActionTypeInfo]) The set of actions this is associated with",
86        "requires_any_of": "(Sequence[FeatureConstraintInfo]) This will be enabled if any of the listed predicates are met. Equivalent to with_features",
87        "nested": "(Optional[NestedArgsInfo]) The args expand. Equivalent to a flag group.",
88        "files": "(depset[File]) Files required for the args",
89        "env": "(dict[str, str]) Environment variables to apply",
90        "allowlist_include_directories": "(depset[DirectoryInfo]) Include directories implied by these arguments that should be allowlisted in Bazel's include checker",
91    },
92)
93ArgsListInfo = provider(
94    doc = "A ordered list of arguments",
95    # @unsorted-dict-items
96    fields = {
97        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
98        "args": "(Sequence[ArgsInfo]) The flag sets contained within",
99        "files": "(depset[File]) The files required for all of the arguments",
100        "by_action": "(Sequence[struct(action=ActionTypeInfo, args=List[ArgsInfo], files=depset[Files])]) Relevant information about the args keyed by the action type.",
101        "allowlist_include_directories": "(depset[DirectoryInfo]) Include directories implied by these arguments that should be allowlisted in Bazel's include checker",
102    },
103)
104
105FeatureInfo = provider(
106    doc = "Contains all flag specifications for one feature.",
107    # @unsorted-dict-items
108    fields = {
109        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
110        "name": "(str) The name of the feature",
111        "enabled": "(bool) Whether this feature is enabled by default",
112        "args": "(ArgsListInfo) Args enabled by this feature",
113        "implies": "(depset[FeatureInfo]) Set of features implied by this feature",
114        "requires_any_of": "(Sequence[FeatureSetInfo]) A list of feature sets, at least one of which is required to enable this feature. This is semantically equivalent to the requires attribute of rules_cc's FeatureInfo",
115        "mutually_exclusive": "(Sequence[MutuallyExclusiveCategoryInfo]) Indicates that this feature is one of several mutually exclusive alternate features.",
116        "external": "(bool) Whether a feature is defined elsewhere.",
117        "overridable": "(bool) Whether the feature is an overridable feature.",
118        "overrides": "(Optional[FeatureInfo]) The feature that this overrides. Must be a known feature",
119        "allowlist_include_directories": "(depset[DirectoryInfo]) Include directories implied by this feature that should be allowlisted in Bazel's include checker",
120    },
121)
122FeatureSetInfo = provider(
123    doc = "A set of features",
124    # @unsorted-dict-items
125    fields = {
126        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
127        "features": "(depset[FeatureInfo]) The set of features this corresponds to",
128    },
129)
130
131FeatureConstraintInfo = provider(
132    doc = "A predicate checking that certain features are enabled and others disabled.",
133    # @unsorted-dict-items
134    fields = {
135        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
136        "all_of": "(depset[FeatureInfo]) A set of features which must be enabled",
137        "none_of": "(depset[FeatureInfo]) A set of features, none of which can be enabled",
138    },
139)
140
141MutuallyExclusiveCategoryInfo = provider(
142    doc = "Multiple features with the category will be mutally exclusive",
143    # @unsorted-dict-items
144    fields = {
145        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
146        "name": "(str) The name of the category",
147    },
148)
149
150ToolInfo = provider(
151    doc = "A binary, with additional metadata to make it useful for action configs.",
152    # @unsorted-dict-items
153    fields = {
154        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
155        "exe": "(File) The file corresponding to the tool",
156        "runfiles": "(runfiles) The files required to run the tool",
157        "execution_requirements": "(Sequence[str]) A set of execution requirements of the tool",
158        "allowlist_include_directories": "(depset[DirectoryInfo]) Built-in include directories implied by this tool that should be allowlisted in Bazel's include checker",
159        "capabilities": "(Sequence[ToolCapabilityInfo]) Capabilities supported by the tool.",
160    },
161)
162
163ToolCapabilityInfo = provider(
164    doc = "A capability associated with a tool (eg. supports_pic).",
165    # @unsorted-dict-items
166    fields = {
167        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
168        "feature": "(FeatureInfo) The feature this capability defines",
169    },
170)
171
172ToolConfigInfo = provider(
173    doc = "A mapping from action to tool",
174    # @unsorted-dict-items
175    fields = {
176        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
177        "configs": "(dict[ActionTypeInfo, ToolInfo]) A mapping from action to tool.",
178    },
179)
180
181ToolchainConfigInfo = provider(
182    doc = "The configuration for a toolchain",
183    # @unsorted-dict-items
184    fields = {
185        "label": "(Label) The label defining this provider. Place in error messages to simplify debugging",
186        "features": "(Sequence[FeatureInfo]) The features available for this toolchain",
187        "enabled_features": "(Sequence[FeatureInfo]) The features That are enabled by default for this toolchain",
188        "tool_map": "(ToolConfigInfo) A provider mapping toolchain action types to tools.",
189        "args": "(Sequence[ArgsInfo]) A list of arguments to be unconditionally applied to the toolchain.",
190        "files": "(dict[ActionTypeInfo, depset[File]]) Files required for the toolchain, keyed by the action type.",
191        "allowlist_include_directories": "(depset[DirectoryInfo]) Built-in include directories implied by this toolchain's args and tools that should be allowlisted in Bazel's include checker",
192    },
193)
194