Skip to content

Conversation

@novas0x2a
Copy link
Contributor

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. 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.

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.

@aspect-workflows
Copy link

aspect-workflows bot commented Jan 16, 2026

Bazel 8 (Test)

2 test targets passed

Targets
//lib/tests/copy_to_directory:case_22_test [k8-fastbuild]                    185ms
//lib/tests/copy_to_directory_bin_action:test [k8-fastbuild]                 73ms

Total test execution time was 258ms. 134 tests (98.5%) were fully cached saving 42s.


Bazel 9 (Test)

2 test targets passed

Targets
//lib/tests/copy_to_directory:case_22_test [k8-fastbuild]                    156ms
//lib/tests/copy_to_directory_bin_action:test [k8-fastbuild]                 235ms

Total test execution time was 391ms. 134 tests (98.5%) were fully cached saving 55s.


Bazel 7 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 23ms.


Bazel 8 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 23ms.


Bazel 9 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 24ms.


Bazel 7 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 20ms.


Bazel 8 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 21ms.


Bazel 9 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 37ms.


Bazel 7 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 309ms.


Bazel 8 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 295ms.


Bazel 9 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 349ms.


Bazel 7 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 204ms.


Bazel 8 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 260ms.


Bazel 9 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 191ms.


Bazel 7 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 20ms.


Bazel 8 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 21ms.


Bazel 9 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 37ms.


Bazel 7 (Test)

e2e/smoke

All tests were cache hits

4 tests (100.0%) were fully cached saving 415ms.


Bazel 8 (Test)

e2e/smoke

All tests were cache hits

4 tests (100.0%) were fully cached saving 636ms.


Bazel 9 (Test)

e2e/smoke

All tests were cache hits

4 tests (100.0%) were fully cached saving 872ms.


Bazel 7 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 30ms.


Bazel 8 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 28ms.


Bazel 9 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 33ms.

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. 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)

This implementation is ugly, but it's made slightly less bad 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.
@novas0x2a
Copy link
Contributor Author

novas0x2a commented Jan 21, 2026

As a follow-up, here are some of the other things I was looking at doing:

  1. making resource_set respond to tags as well as the attribute, as in: cpu:<small|medium|large|enormous>, cpu:<cores:int>, mem:<small|medium|large|enormous>, mem:<num:int><m|g> (i could be convinced to drop cpu:<int> and mem:<int> in favor of just having the symbolic sizes, though that'd represent a compat break if i did that for the attr, too)
  2. provide some sort of tuning mechanism to allow end users to configure what the sizes mean (as in: all "larges" are given 8 cores: e.g. //setting:cpu_large=8; this is important to give users an out for projects overtuning for large ci machines)
  3. finally, I plan to integrate this into rules_foreign_cc and sync it with the underlying build systems, defaulting (e.g.) CMAKE_BUILD_PARALLEL_LEVEL to the resource_set's cpu request.

I'm interested in helping achieve cross-consistency for these behaviors, which means I'd like (at least) 1 to be handled in bazel-lib, and maybe 2 if there's consensus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant