Skip to main content
This is a top-level module for defining the attribute schemas of a rule or aspect. Each function returns an object representing the schema of a single attribute. These objects are used as the values of the attrs dictionary argument of rule(), aspect(), repository_rule() and tag_class(). See the Rules page for more on defining and using attributes.

Members

bool

Creates a schema for a boolean attribute. The corresponding ctx.attr attribute will be of type bool.

Parameters

int

Creates a schema for an integer attribute. The value must be in the signed 32-bit range. The corresponding ctx.attr attribute will be of type int.

Parameters

int_list

Creates a schema for a list-of-integers attribute. Each element must be in the signed 32-bit range.

Parameters

label

Creates a schema for a label attribute. This is a dependency attribute. This attribute contains unique Label values. If a string is supplied in place of a Label, it will be converted using the label constructor. The relative parts of the label path, including the (possibly renamed) repository, are resolved with respect to the instantiated target’s package. At analysis time (within the rule’s implementation function), when retrieving the attribute value from ctx.attr, labels are replaced by the corresponding Targets. This allows you to access the providers of the current target’s dependencies. In addition to ordinary source files, this kind of attribute is often used to refer to a tool — for example, a compiler. Such tools are considered to be dependencies, just like source files. To avoid requiring users to specify the tool’s label every time they use the rule in their BUILD files, you can hard-code the label of a canonical tool as the default value of this attribute. If you also want to prevent users from overriding this default, you can make the attribute private by giving it a name that starts with an underscore. See the Rules page for more information.

Parameters

label_keyed_string_dict

Creates a schema for an attribute holding a dictionary, where the keys are labels and the values are strings. This is a dependency attribute. This attribute contains unique Label values. If a string is supplied in place of a Label, it will be converted using the label constructor. The relative parts of the label path, including the (possibly renamed) repository, are resolved with respect to the instantiated target’s package. At analysis time (within the rule’s implementation function), when retrieving the attribute value from ctx.attr, labels are replaced by the corresponding Targets. This allows you to access the providers of the current target’s dependencies.

Parameters

label_list

Creates a schema for a list-of-labels attribute. This is a dependency attribute. The corresponding ctx.attr attribute will be of type list of Targets. This attribute contains unique Label values. If a string is supplied in place of a Label, it will be converted using the label constructor. The relative parts of the label path, including the (possibly renamed) repository, are resolved with respect to the instantiated target’s package. At analysis time (within the rule’s implementation function), when retrieving the attribute value from ctx.attr, labels are replaced by the corresponding Targets. This allows you to access the providers of the current target’s dependencies.

Parameters

output

Creates a schema for an output (label) attribute. This attribute contains unique Label values. If a string is supplied in place of a Label, it will be converted using the label constructor. The relative parts of the label path, including the (possibly renamed) repository, are resolved with respect to the instantiated target’s package. At analysis time, the corresponding File can be retrieved using ctx.outputs.

Parameters

output_list

Creates a schema for a list-of-outputs attribute. This attribute contains unique Label values. If a string is supplied in place of a Label, it will be converted using the label constructor. The relative parts of the label path, including the (possibly renamed) repository, are resolved with respect to the instantiated target’s package. At analysis time, the corresponding File can be retrieved using ctx.outputs.

Parameters

string

Creates a schema for a string attribute.

Parameters

string_dict

Creates a schema for an attribute holding a dictionary, where the keys and values are strings.

Parameters

string_keyed_label_dict

Creates a schema for an attribute whose value is a dictionary where the keys are strings and the values are labels. This is a dependency attribute. This attribute contains unique Label values. If a string is supplied in place of a Label, it will be converted using the label constructor. The relative parts of the label path, including the (possibly renamed) repository, are resolved with respect to the instantiated target’s package. At analysis time (within the rule’s implementation function), when retrieving the attribute value from ctx.attr, labels are replaced by the corresponding Targets. This allows you to access the providers of the current target’s dependencies.

Parameters

string_list

Creates a schema for a list-of-strings attribute.

Parameters

string_list_dict

Creates a schema for an attribute holding a dictionary, where the keys are strings and the values are lists of strings.

Parameters