attrs
any
def any(
*,
doc: str = "",
default = ...,
) -> Attr
Takes most builtin literals and passes them to the rule as a string. Discouraged, as it provides little type safety and destroys the structure.
arg
def arg(
*,
json: bool = False,
default = ...,
doc: str = "",
anon_target_compatible: bool = False,
exec_group: ExecGroup | None = None,
) -> Attr
Takes a command line argument from the user and supplies a cmd_args compatible value to the rule. The argument may contain special macros such as $(location :my_target) or $(exe :my_target) which will be replaced with references to those values in the rule. Takes in an optional anon_target_compatible flag, which indicates whether the args can be passed into anon targets. Note that there is a slight memory hit when using this flag.
With exec_group, the dependencies of $(exe), $(location_exec) and
$(location_toolchain) macros are configured for the execution platform of that group
instead, and constrain only that group's execution platform resolution. The rule must
declare the group in rule(exec_groups = ...). In a rule that declares named execution
groups, an arg without exec_group may hold flags but not tools: a target whose value
refers to a tool through these macros is an error. Pass exec_group, with
DefaultExecGroup for the default group, for args that refer to tools.
bool
def bool(
*,
default = ...,
doc: str = "",
) -> Attr
Takes a boolean and passes it to the rule as a boolean.
configuration_label
def configuration_label(
*,
doc: str = "",
) -> Attr
configured_dep
def configured_dep(
*,
providers: list | tuple = [],
default = ...,
doc: str = "",
) -> Attr
default_only
def default_only(
inner: Attr,
/,
*,
doc: str = "",
) -> Attr
Rejects all values and uses the default for the inner argument. Often used to resolve dependencies, which otherwise can't be resolved inside a rule.
attrs.default_only(attrs.dep(default = "foo//my_package:my_target"))
dep
def dep(
*,
providers: list | tuple = [],
pulls_plugins: list[PluginKind] | tuple[PluginKind, ...] = [],
pulls_and_pushes_plugins: AllPlugins | list[PluginKind] | tuple[PluginKind, ...] = ...,
default = ...,
doc: str = "",
) -> Attr
Takes a target from the user, as a string, and supplies a dependency to the rule. A target can be specified as an absolute dependency foo//bar:baz, omitting the cell (//bar:baz) or omitting the package name (:baz).
If supplied the providers argument ensures that specific providers will be present
on the dependency.
The pulls_plugins and pulls_and_pushes_plugins parameters control plugin propagation.
See the plugins namespace documentation for a full explanation.
dict
def dict(
key: Attr,
value: Attr,
*,
sorted: bool = False,
default = ...,
doc: str = "",
) -> Attr
Takes a dict from the user, supplies a dict to the rule.
enum
def enum(
variants: list[str] | tuple[str, ...],
/,
*,
default: Select | str = ...,
doc: str = "",
) -> Attr
Takes a string from one of the variants given, and gives that string to the rule. Strings are matched case-insensitively, and always passed to the rule lowercase.
exec_compatible_with
def exec_compatible_with(
*,
exec_group: ExecGroup,
default = ...,
doc: str = "",
) -> Attr
Takes a list of constraints from the user that the execution platform of exec_group must satisfy, in addition to the target's exec_compatible_with, which applies to every group. With DefaultExecGroup, the constraints apply to the default group only. A rule may have at most one such attribute per group, and must declare the group in rule(exec_groups = ...) (DefaultExecGroup is declared implicitly by rules without named groups). Supplies the constraint labels as strings to the rule.
exec_dep
def exec_dep(
*,
providers: list | tuple = [],
default = ...,
doc: str = "",
exec_group: ExecGroup | None = None,
) -> Attr
Takes a target from the user, as a string, and supplies a dependency to the rule. The dependency will transition to the execution platform. Use exec_dep if you plan to execute things from this dependency as part of the compilation.
With exec_group, the dependency is configured for the execution platform of that
group instead, and constrains only that group's execution platform resolution. The rule
must declare the group in rule(exec_groups = ...). A rule that declares named execution
groups must pass exec_group, with DefaultExecGroup for the default group.
int
def int(
*,
default = ...,
doc: str = "",
) -> Attr
Takes an int from the user, supplies an int to the rule.
label
def label(
*,
default = ...,
doc: str = "",
) -> Attr
Takes a target (as per deps) and passes a label to the rule. Validates that the target exists, but does not introduce a dependency on it.
list
def list(
inner: Attr,
/,
*,
default = ...,
doc: str = "",
) -> Attr
Takes a list from the user, supplies a list to the rule.
named_set
def named_set(
value_type: Attr,
/,
*,
sorted: bool = False,
default = ...,
doc: str = "",
) -> Attr
one_of
def one_of(
*args: Attr,
default = ...,
doc: str = "",
) -> Attr
Given a list of alternative attributes, selects the first that matches and gives that to the rule.
option
def option(
inner: Attr,
/,
*,
default = ...,
doc: str = "",
) -> Attr
Takes a value that may be None or some inner type, and passes either None or the value corresponding to the inner to the rule. Often used to make a rule optional:
attrs.option(attr.string(), default = None)
plugin_dep
def plugin_dep(
*,
kind: PluginKind,
default = ...,
doc: str = "",
) -> Attr
Takes a target label from the user and registers it as a plugin dependency.
Plugin dependencies are propagated as unconfigured target labels up the build graph,
then configured as exec deps when used by a rule with uses_plugins. This is useful
for dependencies like Rust proc macros that need to be accessible to transitive dependents.
See the plugins namespace documentation for a full explanation and examples.
query
def query(
*,
doc: str = "",
) -> Attr
regex
def regex(
*,
default = ...,
doc: str = "",
) -> Attr
Currently an alias for attrs.string.
set
def set(
value_type: Attr,
/,
*,
sorted: bool = False,
default = ...,
doc: str = "",
) -> Attr
source
def source(
*,
allow_directory: bool = False,
default = ...,
doc: str = "",
) -> Attr
Takes a source file from the user, supplies an artifact to the rule. The source file may be specified as a literal string (representing the path within this package), or a target (which must have a DefaultInfo with a default_outputs value).
split_transition_dep
def split_transition_dep(
*,
providers: list | tuple = [],
cfg,
default = ...,
doc: str = "",
) -> Attr
string
def string(
*,
default = ...,
validate = ...,
doc: str = "",
) -> Attr
Takes a string from the user, supplies a string to the rule.
toolchain_dep
def toolchain_dep(
*,
providers: list | tuple = [],
default = ...,
doc: str = "",
exec_group: ExecGroup | None = None,
) -> Attr
Takes a target from the user, as a string, and supplies a dependency to the rule. The dependency will be a toolchain dependency, meaning that its execution platform dependencies will be used to select the execution platform for this rule.
With exec_group, the toolchain's execution platform dependencies select the
execution platform of that group instead, and the toolchain is configured with that
group's execution platform. The rule must declare the group in
rule(exec_groups = ...). A rule that declares named execution groups must pass
exec_group, with DefaultExecGroup for the default group.
transition_dep
def transition_dep(
*,
providers: list | tuple = [],
cfg = ...,
default = ...,
doc: str = "",
) -> Attr
tuple
def tuple(
*args: Attr,
default = ...,
doc: str = "",
) -> Attr
Takes a tuple of values and gives a tuple to the rule.
versioned
def versioned(
value_type: Attr,
*,
doc: str = "",
) -> Attr