Skip to main content

context type

The type used for defining rules, usually bound as ctx. Usually the sole argument to the impl argument of the rule function.

def _impl_my_rule(ctx: AnalysisContext) -> ["provider"]:
return [DefaultInfo()]
my_rule = rule(impl = _impl_my_rule, attrs = {})


context.actions: actions

Returns an actions value containing functions to define actual actions that are run. See the actions type for the operations that are available.


context.attrs: struct(..)

Returns the attributes of the target as a Starlark struct with a field for each attribute, which varies per rule. As an example, given a rule with the attrs argument of {"foo": attrs.string()}, this field will be a struct containing a field foo of type string.


context.label: None | label

Returns a label representing the target, or None if being invoked from a dynamic_output in Bxl.


context.plugins: AnalysisPlugins

An opaque value that can be indexed with a plugin kind to get a list of the available plugin deps of that kind. The rule must set an appropriate value on uses_plugins in its declaration.