Current status
Execution groups for certain natively declared actions, likeCppLink, can be
used inside exec_properties to set per-action, per-target execution
requirements. For more details, see the
Default execution groups section.
Background
Execution groups allow the rule author to define sets of actions, each with a potentially different execution platform. Multiple execution platforms can allow actions to execution differently, for example compiling an iOS app on a remote (linux) worker and then linking/code signing on a local mac worker. Being able to define groups of actions also helps alleviate the usage of action mnemonics as a proxy for specifying actions. Mnemonics are not guaranteed to be unique and can only reference a single action. This is especially helpful in allocating extra resources to specific memory and processing intensive actions like linking in C++ builds without over-allocating to less demanding tasks.Defining execution groups
During rule definition, rule authors can declare a set of execution groups. On each execution group, the rule author can specify everything needed to select an execution platform for that execution group, namely any constraints viaexec_compatible_with and toolchain types via
toolchain.
cfg
attribute param and the
config
module. The module exposes an exec function which takes a single string
parameter which is the name of the exec group for which the dependency should be
built.
As on native rules, the test execution group is present by default on Starlark
test rules.
Accessing execution groups
In the rule implementation, you can declare that actions should be run on the execution platform of an execution group. You can do this by using theexec_group
param of action generating methods, specifically [ctx.actions.run]
(/rules/lib/builtins/actions#run) and
ctx.actions.run_shell.
Default execution groups
The following execution groups are predefined:test: Test runner actions (for more details, see the execution platform section of the Test Encylopedia).cpp_link: C++ linking actions.
Using execution groups to set execution properties
Execution groups are integrated with theexec_properties
attribute that exists on every rule and allows the target writer to specify a
string dict of properties that is then passed to the execution machinery. For
example, if you wanted to set some property, say memory, for the target and give
certain actions a higher memory allocation, you would write an exec_properties
entry with an execution-group-augmented key, such as:
exec_group = "link" would see the exec properties
dictionary as {"mem": "16g"}. As you see here, execution-group-level
settings override target-level settings.
Using execution groups to set platform constraints
Execution groups are also integrated with theexec_compatible_with and
exec_group_compatible_with
attributes that exist on every rule and allow the target writer to specify
additional constraints that must be satisfied by the execution platforms
selected for the target’s actions.
For example, if the rule my_test defines the link execution group in
addition to the default and the test execution group, then the following
usage of these attributes would run actions in the default execution group on
a platform with a high number of CPUs, the test action on Linux, and the link
action on the default execution platform:
Execution groups for native rules
The following execution groups are available for actions defined by native rules:test: Test runner actions.cpp_link: C++ linking actions.
Execution groups and platform execution properties
It is possible to defineexec_properties for arbitrary execution groups on
platform targets (unlike exec_properties set directly on a target, where
properties for unknown execution groups are rejected). Targets then inherit the
execution platform’s exec_properties that affect the default execution group
and any other relevant execution groups.
For example, suppose running tests on the exec platform requires some resource
to be available, but it isn’t required for compiling and linking; this can be
modelled as follows:
exec_properties defined directly on targets take precedence over those that
are inherited from the execution platform.