Allow `resource_set`'s callback to return custom resources
#27.950 aberto em 11 de dez. de 2025
Métricas do repositório
- Stars
- (25.384 stars)
- Métricas de merge de PR
- (Mesclagem média 22d 20h) (77 fundiu PRs em 30d)
Description
Description of the feature request:
We would like to allow resource_set arguments to return any kind of resources. In particular, those defined by --local_resources.
Currently, the resource_set attribute of ctx.actions.run (an similar) can only be set to a function returning a dictionary with a limited set of keys/resources (mem, cpu, and local_test). As such, attempting to use any kind of custom resource:
def _some_resources(os, actions):
return {
"potatoes": 3,
}
def _some_rule_imp(ctx):
...
ctx.actions.run_shell(
...
mnemonic = "SomeAction",
resource_set = _some_resources,
)
Leads to an error (last_green 2025/12/11):
$ bazel build //test:build_1
...
ERROR: .../test/BUILD:3:11: SomeAction test/build_1_out.txt failed: Could not build resources for SomeAction. Illegal resource keys: (potatoes)
This limitations seems arbitrary since ResourceManager.java seems more than capable to handle custom resources. Interestingly, if one fiddles with StarlarkActionFactory.java and removes the limitation in StarlarkActionFactory.buildResourceSetit all appears to work fine 🎉
Which category does this issue belong to?
Local Execution
What underlying problem are you trying to solve with this feature?
We would like to limit the concurrency of arbitrary build actions using resource_set and --local_resources. In our particular case we are trying to stay below the number of concurrent invocations a tool's license allows. However, this can be useful in other contexts (i.e., bazelbuild/rules_rust#3101 and #10443)