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 }, 91) 92ArgsListInfo = provider( 93 doc = "A ordered list of arguments", 94 # @unsorted-dict-items 95 fields = { 96 "label": "(Label) The label defining this provider. Place in error messages to simplify debugging", 97 "args": "(Sequence[ArgsInfo]) The flag sets contained within", 98 "files": "(depset[File]) The files required for all of the arguments", 99 "by_action": "(Sequence[struct(action=ActionTypeInfo, args=List[ArgsInfo], files=depset[Files])]) Relevant information about the args keyed by the action type.", 100 }, 101) 102 103FeatureInfo = provider( 104 doc = "Contains all flag specifications for one feature.", 105 # @unsorted-dict-items 106 fields = { 107 "label": "(Label) The label defining this provider. Place in error messages to simplify debugging", 108 "name": "(str) The name of the feature", 109 "enabled": "(bool) Whether this feature is enabled by default", 110 "args": "(ArgsListInfo) Args enabled by this feature", 111 "implies": "(depset[FeatureInfo]) Set of features implied by this feature", 112 "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", 113 "mutually_exclusive": "(Sequence[MutuallyExclusiveCategoryInfo]) Indicates that this feature is one of several mutually exclusive alternate features.", 114 "external": "(bool) Whether a feature is defined elsewhere.", 115 "overridable": "(bool) Whether the feature is an overridable feature.", 116 "overrides": "(Optional[FeatureInfo]) The feature that this overrides. Must be a known feature", 117 }, 118) 119FeatureSetInfo = provider( 120 doc = "A set of features", 121 # @unsorted-dict-items 122 fields = { 123 "label": "(Label) The label defining this provider. Place in error messages to simplify debugging", 124 "features": "(depset[FeatureInfo]) The set of features this corresponds to", 125 }, 126) 127 128FeatureConstraintInfo = provider( 129 doc = "A predicate checking that certain features are enabled and others disabled.", 130 # @unsorted-dict-items 131 fields = { 132 "label": "(Label) The label defining this provider. Place in error messages to simplify debugging", 133 "all_of": "(depset[FeatureInfo]) A set of features which must be enabled", 134 "none_of": "(depset[FeatureInfo]) A set of features, none of which can be enabled", 135 }, 136) 137 138MutuallyExclusiveCategoryInfo = provider( 139 doc = "Multiple features with the category will be mutally exclusive", 140 # @unsorted-dict-items 141 fields = { 142 "label": "(Label) The label defining this provider. Place in error messages to simplify debugging", 143 "name": "(str) The name of the category", 144 }, 145) 146 147ToolInfo = provider( 148 doc = "A binary, with additional metadata to make it useful for action configs.", 149 # @unsorted-dict-items 150 fields = { 151 "label": "(Label) The label defining this provider. Place in error messages to simplify debugging", 152 "exe": "(File) The file corresponding to the tool", 153 "runfiles": "(depset[File]) The files required to run the tool", 154 "requires_any_of": "(Sequence[FeatureConstraintInfo]) A set of constraints, one of which is required to enable the tool. Equivalent to with_features", 155 "execution_requirements": "(Sequence[str]) A set of execution requirements of the tool", 156 }, 157) 158 159ActionTypeConfigInfo = provider( 160 doc = "Configuration of a Bazel action.", 161 # @unsorted-dict-items 162 fields = { 163 "label": "(Label) The label defining this provider. Place in error messages to simplify debugging", 164 "action_type": "(ActionTypeInfo) The type of the action", 165 "tools": "(Sequence[ToolInfo]) The tool applied to the action will be the first tool in the sequence with a feature set that matches the feature configuration", 166 "args": "(Sequence[ArgsInfo]) Set of flag sets the action sets", 167 "implies": "(depset[FeatureInfo]) Set of features implied by this action config", 168 "files": "(runfiles) The files required to run these actions", 169 }, 170) 171 172ActionTypeConfigSetInfo = provider( 173 doc = "A set of action configs", 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, ActionTypeConfigInfo]) A set of action configs", 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 "action_type_configs": "(dict[ActionTypeInfo, ActionTypeConfigInfo]) The configuration of action configs for the toolchain.", 188 "args": "(Sequence[ArgsInfo]) A list of arguments to be unconditionally applied to the toolchain.", 189 "files": "(dict[ActionTypeInfo, depset[File]]) Files required for the toolchain, keyed by the action type.", 190 }, 191) 192