feat: integrate bazel resource_sets into the build actions#1465
Merged
feat: integrate bazel resource_sets into the build actions#1465
Conversation
Collaborator
Author
|
Note: depends on #1464, which should be merged first. |
c5c833d to
c2737dc
Compare
Contributor
|
This LGTM. The fact it needed a ninja wrapper, in cpp no less, is a bit crazy. |
This is an attempt to make parallelization of builds safer by telling bazel what resources an action will consume. By default, Bazel allocates 1 CPU and 250M of RAM, and this makes the current methods of parallelization (i.e. --action_env=CMAKE_BUILD_PARALLEL_LEVEL=16) pretty unpleasant, since bazel won't know and will happily schedule 160 cores worth of actions on a 10-core machine. I have added resource_size declarations to several of the base requirement tools (make|cmake|ninja|pkgconfig)_tool, which drastically speeds up the CI environment and build iteration speed. This also adds a wrapper binary for ninja, because ninja doesn't support environment variables. It's c++ instead of bash or python because it needs to be invoked after changing the working directory, and the shim scripts that are used to launch bash or python on windows rely on runfiles, which don't work if you change the wd.
c2737dc to
f934eb1
Compare
rdesgroppes
added a commit
to DataDog/datadog-agent
that referenced
this pull request
Mar 12, 2026
Switch rules_foreign_cc from single_version_override on 0.15.1 to a git_override on main (e4068330) to pick up three upstream fixes: - bazel-contrib/rules_foreign_cc#1451: out_data_dirs in output groups (our patch 0001 verbatim — drop it) - bazel-contrib/rules_foreign_cc#1465: resource_set integration, which lets Bazel's scheduler respect CPU/RAM budgets and avoids build action overcommitting - bazel-contrib/rules_foreign_cc#1470: forward -isystem flags to configure scripts Patch 0002 (LD_LIBRARY_PATH propagation) is kept locally as bazel-contrib/rules_foreign_cc#1452 is still open. bazel-contrib/rules_foreign_cc#1462 bumps bazel_lib to 3.2.0; follow up to 3.2.2 to get path-mapping compatibility with Bazel 9.
gh-worker-dd-mergequeue-cf854d bot
pushed a commit
to DataDog/datadog-agent
that referenced
this pull request
Mar 13, 2026
### What does this PR do? Switch `rules_foreign_cc` from `single_version_override` on 0.15.1 to a `git_override` on `main`. Implies to bump `bazel_lib` to 3.2+ (see bazel-contrib/rules_foreign_cc#1462). ### Motivation Pick up three upstream fixes: 1. bazel-contrib/rules_foreign_cc#1451 (allows to **drop our corresponding patch**), 2. bazel-contrib/rules_foreign_cc#1465 (avoids build action **over-committing**), 3. bazel-contrib/rules_foreign_cc#1470. ### Additional Notes Patch 0002 (LD_LIBRARY_PATH propagation) is kept locally as bazel-contrib/rules_foreign_cc#1452 is still open. Co-authored-by: regis.desgroppes <regis.desgroppes@datadoghq.com>
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.
summary
This is an attempt to make parallelization of builds safer by telling bazel what resources an action will consume. By default, Bazel allocates 1 CPU and 250M of RAM, and this makes the current methods of parallelization (i.e.
--action_env=CMAKE_BUILD_PARALLEL_LEVEL=16) pretty unpleasant, since bazel won't know and will happily schedule 160 cores worth of actions on a 10-core machine. Although it doesn't solve the whole parallelization problem (see #329) it helps a lot; it reduces the length of our internal build by 30% (by allowing us to fine-tune threads on a per-action basis).core design
resource_sizeattribute, which can be set to a logical size similar to bazel's other sizing parameters (default,tiny,small,medium,large,enormous).bazel run @rules_foreign_cc//foreign_cc/settingswill list all the settings in.bazelrcformat, along with their default values.CMAKE_BUILD_PARALLEL_LEVEL,GNUMAKEFLAGS,MESON_NUM_PROCESSES,NINJA_JOBS. All vars are passed to all build systems, since they can delegate to each other (for example, cmake calling ninja or make).resource_size="default"(the default) does the same thing as what rfcc/bazel does today (no resource_set, no env var overrides)action_env(e.g.--action_env=CMAKE_BUILD_PARALLEL_LEVEL=4) or similar:@rules_foreign_cc//foreign_cc/settings:size_default) will override the action_env vars.other notes
(make|cmake|ninja|pkgconfig)_tool, which drastically speeds up the CI environment and build iteration speed. (This knocks at least 10 minutes off thecmake_toolbuild time).NINJA_JOBSis implemented. It's c++ instead of bash or python because it needs to be invoked after changing the working directory, and the shim scripts that are used to launch bash or python on windows rely on runfiles, which don't work if you change the wd the way rfcc must.--local_resourcesto determine the limit; see that for defaultsCMAKE_BUILD_PARALLEL_LEVEL=12. This is probably implementable as a setting if someone feels so inclined.