Allow `resource_set`'s callback to return custom resources
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
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](https://bazel.build/reference/command-line-reference#build-flag--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:
```starlark
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](src/main/java/com/google/devtools/build/lib/actions/ResourceManager.java) seems more than capable to handle custom resources. Interestingly, if one fiddles with [StarlarkActionFactory.java](src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java) and removes the limitation in `StarlarkActionFactory.buildResourceSet`it 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](https://bazel.build/reference/command-line-reference#build-flag--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)
Contributor guide
Research direction
Start in src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java, especially buildResourceSet, and read how src/main/java/com/google/devtools/build/lib/actions/ResourceManager.java handles custom resources. Reproduce the reported case with bazel build //test:build_1 and a potatoes resource. Done means resource_set accepts arbitrary keys supported by --local_resources without the illegal-resource-keys error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100