1# Copyright 2023 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://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, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""All shared providers that act as an API between toolchain-related rules.""" 15 16load( 17 "@rules_cc//cc:cc_toolchain_config_lib.bzl", 18 "FlagGroupInfo", 19) 20load("//actions:providers.bzl", "ActionNameInfo", "ActionNameSetInfo") 21 22visibility(["//cc_toolchain", "//cc_toolchain/tests/..."]) 23 24# Note that throughout this file, we never use a list. This is because mutable 25# types cannot be stored in depsets. Thus, we type them as a sequence in the 26# provider, and convert them to a tuple in the constructor to ensure 27# immutability. 28 29PwActionNameInfo = ActionNameInfo 30PwActionNameSetInfo = ActionNameSetInfo 31 32PwFlagGroupInfo = FlagGroupInfo 33PwFlagSetInfo = provider( 34 doc = "A type-safe version of @bazel_tools's FlagSetInfo", 35 fields = { 36 "actions": "Sequence[str]: The set of actions this is associated with", 37 "env": "Mapping[str, str]: Environment variables to apply with the flags", 38 "env_expand_if_available": "Option[str]: The build variable that needs to be available in order to expand the env entry.", 39 "flag_groups": "Sequence[FlagGroupInfo]: Set of flag groups to include.", 40 "label": "Label: The label that defined this flag set. Put this in error messages for easy debugging", 41 "requires_any_of": "Sequence[FeatureConstraintInfo]: This will be enabled if any of the listed predicates are met. Equivalent to with_features", 42 }, 43) 44 45PwFeatureInfo = provider( 46 doc = "A type-safe version of @bazel_tools's FeatureInfo", 47 fields = { 48 "enabled": "bool: Whether this feature is enabled by default", 49 "flag_sets": "depset[FlagSetInfo]: Flag sets enabled by this feature", 50 "implies_action_configs": "depset[ActionConfigInfo]: Set of action configs enabled by this feature", 51 "implies_features": "depset[FeatureInfo]: Set of features implied by this feature", 52 "known": "bool: Whether the feature is a known feature. Known features are assumed to be defined elsewhere.", 53 "label": "Label: The label that defined this feature. Put this in error messages for easy debugging", 54 "name": "str: The name of the feature", 55 "overrides": "FeatureInfo | None: The feature that this overrides", 56 "provides": "Sequence[str]: Indicates that this feature is one of several mutually exclusive alternate features.", 57 "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", 58 }, 59) 60PwFeatureSetInfo = provider( 61 doc = "A type-safe version of @bazel_tools's FeatureSetInfo", 62 fields = { 63 "features": "depset[FeatureInfo]: The set of features this corresponds to", 64 }, 65) 66PwFeatureConstraintInfo = provider( 67 doc = "A type-safe version of @bazel_tools's WithFeatureSetInfo", 68 fields = { 69 "all_of": "depset[FeatureInfo]: A set of features which must be enabled", 70 "label": "Label: The label that defined this predicate. Put this in error messages for easy debugging", 71 "none_of": "depset[FeatureInfo]: A set of features, none of which can be enabled", 72 }, 73) 74PwBuiltinFeatureInfo = provider( 75 doc = "A tag marking something as a known feature. The only use of this is to ensure that pw_cc_feature disallows override = <non known feature>.", 76 fields = {}, 77) 78PwMutuallyExclusiveCategoryInfo = provider( 79 doc = "Multiple features with the category will be mutally exclusive", 80 fields = { 81 "name": "str: The name of the provider", 82 }, 83) 84 85PwActionConfigInfo = provider( 86 doc = "A type-safe version of @bazel_tools's ActionConfigInfo", 87 fields = { 88 "action_name": "str: The name of the action", 89 "enabled": "bool: If True, this action is enabled unless a rule type explicitly marks it as unsupported", 90 "files": "depset[File]: The files required to run these actions", 91 "flag_sets": "Sequence[FlagSetInfo]: Set of flag sets the action sets", 92 "implies_action_configs": "depset[ActionConfigInfo]: Set of action configs enabled by this action config", 93 "implies_features": "depset[FeatureInfo]: Set of features implied by this action config", 94 "label": "Label: The label that defined this action config. Put this in error messages for easy debugging", 95 "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", 96 }, 97) 98 99PwActionConfigSetInfo = provider( 100 doc = "A set of action configs", 101 fields = { 102 "action_configs": "depset[ActionConfigInfo]: A set of action configs", 103 "label": "Label: The label that defined this action config set. Put this in error messages for easy debugging", 104 }, 105) 106 107PwToolInfo = provider( 108 doc = "A type-safe version of @bazel_tool's ToolInfo", 109 fields = { 110 "exe": "File | None: The file corresponding to the tool", 111 "execution_requirements": "Sequence[str]: A set of execution requirements of the tool", 112 "files": "Depset[File]: The files associated with the tool", 113 "label": "Label: The label that defined this tool", 114 "path": "str | None: The path to the tool. Prefer tool (mutually exclusive with tool).", 115 "requires_any_of": "Sequence[PwFeatureConstraintInfo]: A set of constraints required to enable the tool. Equivalent to with_features", 116 }, 117) 118 119PwExtraActionFilesInfo = provider( 120 doc = "Extra files to provide to an action", 121 fields = { 122 "action": "str: The action to associate with", 123 "files": "depset[File]: Files to add to this action", 124 }, 125) 126PwExtraActionFilesSetInfo = provider( 127 doc = "Set of PwExtraActionFilesInfo", 128 fields = { 129 "srcs": "depset[PwExtraActionFilesInfo]: Sets of action files", 130 }, 131) 132 133PwToolchainConfigInfo = provider( 134 doc = "Additional metadata about the config of the pigweed toolchain.", 135 fields = { 136 "action_to_files": "dict[str, depset[File]]: A set of files required to execute a given action", 137 }, 138) 139