feat: add a helper for rules to work with resource_sets#792
Merged
Conversation
This API is poorly designed and needs some help to let rule users pick a value in cases that they aren't also the rule author
jbedard
reviewed
Mar 15, 2024
jbedard
approved these changes
Mar 18, 2024
| return {"cpu": 2} | ||
|
|
||
| def _resource_set_cpu_4(_, __): | ||
| return {"cpu": 4} |
There was a problem hiding this comment.
if you're using 4 cores it's Likely you are using more than 250mB as well. So maybe you want a cross-product? This bazel API is silly
alexeagle
pushed a commit
that referenced
this pull request
Jan 23, 2026
This adds a new public function, `resource_set_for`, which takes a cpu and memory value and returns an appropriate `resource_set` function for those values, adding some support for the cross-product [mentioned in the previous pass](#792 (comment)). The bazel resource_set API isn't very easy to work with, and this hides the ugliness here, rather than expecting every module to implement something like [rules_rust did](https://github.com/bazelbuild/rules_rust/blob/f29a63cb3c473bd0158c8c9d3e0793a33187d505/rust/private/rustc_resource_set.bzl). The ugliness of the implementation is mitigated slightly by using a helper script to generate it, and I reason that people attempting to use the `resource_set` API would be better off with additional abstraction, so if/when this gets fixed in bazel, most people don't need to notice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This API is poorly designed and needs some help to let rule users pick a value in cases that they aren't also the rule author
Workaround for bazelbuild/bazel#15187
Type of change
For changes visible to end-users
Test plan
I'm using it downstream in rules_ts.