implementation | function; required the Starlark function implementing this rule, must have exactly one parameter: ctx. The function is called during the analysis phase for each instance of the rule. It can access the attributes provided by the user. It must create actions to generate all the declared outputs. |
test | bool; default is unbound Whether this rule is a test rule, that is, whether it may be the subject of a bazel test command. All test rules are automatically considered executable; it is unnecessary (and discouraged) to explicitly set executable = True for a test rule. The value defaults to False. See the Rules page for more information. |
attrs | dict; default is {} A dictionary to declare all the attributes of the rule. It maps from an attribute name to an attribute object (see attr module). Attributes starting with _ are private, and can be used to add an implicit dependency on a label. The attribute name is implicitly added and must not be specified. Attributes visibility, deprecation, tags, testonly, and features are implicitly added and cannot be overridden. Most rules need only a handful of attributes. To limit memory usage, there is a cap on the number of attributes that may be declared. Declared attributes will convert None to the default value. |
outputs | dict; or None; or function; default is None Deprecated. This parameter is deprecated and will be removed soon. Please do not depend on it. It is disabled with --incompatible_no_rule_outputs_param. Use this flag to verify your code is compatible with its imminent removal. This parameter has been deprecated. Migrate rules to use OutputGroupInfo or attr.output instead. A schema for defining predeclared outputs. Unlike output and output_list attributes, the user does not specify the labels for these files. See the Rules page for more on predeclared outputs. The value of this argument is either a dictionary or a callback function that produces a dictionary. The callback works similar to computed dependency attributes: The function’s parameter names are matched against the rule’s attributes, so for example if you pass outputs = _my_func with the definition def _my_func(srcs, deps): ..., the function has access to the attributes srcs and deps. Whether the dictionary is specified directly or via a function, it is interpreted as follows. Each entry in the dictionary creates a predeclared output where the key is an identifier and the value is a string template that determines the output’s label. In the rule’s implementation function, the identifier becomes the field name used to access the output’s File in ctx.outputs. The output’s label has the same package as the rule, and the part after the package is produced by substituting each placeholder of the form "%{ATTR}" with a string formed from the value of the attribute ATTR: * String-typed attributes are substituted verbatim.* Label-typed attributes become the part of the label after the package, minus the file extension. For example, the label "//pkg:a/b.c" becomes "a/b".* Output-typed attributes become the part of the label after the package, including the file extension (for the above example, "a/b.c").* All list-typed attributes (for example, attr.label_list) used in placeholders are required to have exactly one element. Their conversion is the same as their non-list version (attr.label).* Other attribute types may not appear in placeholders.* The special non-attribute placeholders %{dirname} and %{basename} expand to those parts of the rule’s label, excluding its package. For example, in "//pkg:a/b.c", the dirname is a and the basename is b.c. In practice, the most common substitution placeholder is "%{name}". For example, for a target named “foo”, the outputs dict {"bin": "%{name}.exe"} predeclares an output named foo.exe that is accessible in the implementation function as ctx.outputs.bin. |
executable | bool; default is unbound |
output_to_genfiles | bool; default is False If true, the files will be generated in the genfiles directory instead of the bin directory. Unless you need it for compatibility with existing rules (e.g. when generating header files for C++), do not set this flag. |
fragments | sequence of strings; default is [] List of names of configuration fragments that the rule requires in target configuration. |
host_fragments | sequence of strings; default is [] List of names of configuration fragments that the rule requires in host configuration. |
_skylark_testable | bool; default is False (Experimental) If true, this rule will expose its actions for inspection by rules that depend on it via an Actions provider. The provider is also available to the rule itself by calling ctx.created_actions(). This should only be used for testing the analysis-time behavior of Starlark rules. This flag may be removed in the future. |
toolchains | sequence; default is [] If set, the set of toolchains this rule requires. The list can contain String, Label, or StarlarkToolchainTypeApi objects, in any combination. Toolchains will be found by checking the current platform, and provided to the rule implementation via ctx.toolchain. |
doc | string; or None; default is None A description of the rule that can be extracted by documentation generating tools. |
provides | sequence; default is [] A list of providers that the implementation function must return. It is an error if the implementation function omits any of the types of providers listed here from its return value. However, the implementation function may return additional providers not listed here. Each element of the list is an *Info object returned by provider(). When a target of the rule is used as a dependency for a target that declares a required provider, it is not necessary to specify that provider here. It is enough that the implementation function returns it. However, it is considered best practice to specify it, even though this is not required. The required_providers field of an aspect does, however, require that providers are specified here. |
dependency_resolution_rule | bool; default is False If set, the rule can be a dependency through attributes also marked as available in materializers. Every attribute of rules with this flag set must be marked as available in materializers also. This is so that rules so marked cannot depend on rules that are not so marked. |
exec_compatible_with | sequence of strings; default is [] A list of constraints on the execution platform that apply to all targets of this rule type. |
analysis_test | bool; default is False If true, then this rule is treated as an analysis test. Note: Analysis test rules are primarily defined using infrastructure provided in core Starlark libraries. See Testing for guidance. If a rule is defined as an analysis test rule, it becomes allowed to use configuration transitions defined using analysis_test_transition on its attributes, but opts into some restrictions: * Targets of this rule are limited in the number of transitive dependencies they may have.* The rule is considered a test rule (as if test=True were set). This supersedes the value of test * The rule implementation function may not register actions. Instead, it must register a pass/fail result via providing AnalysisTestResultInfo. |
build_setting | BuildSetting; or None; default is None If set, describes what kind of build setting this rule is. See the config module. If this is set, a mandatory attribute named “build_setting_default” is automatically added to this rule, with a type corresponding to the value passed in here. |
cfg | default is None If set, points to the configuration transition the rule will apply to its own configuration before analysis. |
exec_groups | dict; or None; default is None Dict of execution group name (string) to exec_groups. If set, allows rules to run actions on multiple execution platforms within a single target. See execution groups documentation for more info. |
initializer | default is None Experimental: the Stalark function initializing the attributes of the rule. The function is called at load time for each instance of the rule. It’s called with name and the values of public attributes defined by the rule (not with generic attributes, for example tags). It has to return a dictionary from the attribute names to the desired values. The attributes that are not returned are unaffected. Returning None as value results in using the default value specified in the attribute definition. Initializers are evaluated before the default values specified in an attribute definition. Consequently, if a parameter in the initializer’s signature contains a default values, it overwrites the default from the attribute definition (except if returning None). Similarly, if a parameter in the initializer’s signature doesn’t have a default, the parameter will become mandatory. It’s a good practice to omit default/mandatory settings on an attribute definition in such cases. It’s a good practice to use **kwargs for attributes that are not handled. In case of extended rules, all initializers are called proceeding from child to ancestors. Each initializer is passed only the public attributes it knows about. |
parent | default is None Experimental: the Stalark rule that is extended. When set the public attributes are merged as well as advertised providers. The rule matches executable and test from the parent. Values of fragments, toolchains, exec_compatible_with, and exec_groups are merged. Legacy or deprecated parameters may not be set. Incoming configuration transition cfg of parent is applied after this rule’s incoming configuration. |
extendable | bool; or Label; or string; or None; default is None Experimental: A label of an allowlist defining which rules can extending this rule. It can be set also to True/False to always allow/disallow extending. Bazel defaults to always allowing extensions. |
subrules | sequence of Subrules; default is [] Experimental: List of subrules used by this rule. |