fix(cmake): Explicitly use the logical CPU count when JOBS is unset.#116
Closed
jackluo923 wants to merge 7 commits into
Closed
fix(cmake): Explicitly use the logical CPU count when JOBS is unset.#116jackluo923 wants to merge 7 commits into
JOBS is unset.#116jackluo923 wants to merge 7 commits into
Conversation
`cmake:build` always emitted `--parallel "{{.JOBS}}"`, so an empty/unset
`JOBS` rendered `cmake --build <dir> --parallel ""`, which cmake turns into
bare `gmake -f Makefile -j` — GNU make's bare `-j` means *unlimited*
parallelism (no cap on concurrent jobs). For a large dependency this can
spawn hundreds of compiler processes and risk OOM.
This made the documented behavior ("If omitted, the native build tool's
default number is used") untrue. `boost.yaml` already guards its `-j` with
`{{- if .JOBS}}`; apply the same conditional to `cmake:build` so an empty
`JOBS` omits `--parallel` entirely and the native build tool's default
applies. `install-remote-tar` delegates to `build`, so it is covered too.
Consumers that pass a `JOBS` value are unaffected.
Contributor
WalkthroughThe CMake taskfile now sets a default ChangesCMake JOBS default handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
`cmake:build` always emitted `--parallel "{{.JOBS}}"` with `JOBS` defaulting to
the empty string, so an unset `JOBS` rendered `cmake --build <dir> --parallel ""`.
cmake turns that into bare `gmake -f Makefile -j`, i.e. unbounded parallelism —
a single build could spawn far more compiler processes than there are cores,
oversubscribing the machine and risking OOM on large dependencies.
Bound the default to the number of logical CPUs (`nproc`/`sysctl`, falling back
to `1`), so `--parallel` always receives a finite, right-sized value and a
single build no longer oversubscribes. Callers can still override via `JOBS`
(or `CMAKE_JOBS`, which flows through `install-remote-tar` -> `build`).
This matches `boost:build-and-install` (b2 defaults to the core count for
boost >= 1.76.0). Cross-build scheduling — running several `cmake:build`
invocations concurrently — remains the caller's responsibility; set `JOBS`
lower to avoid oversubscribing across builds.
Cross-platform: `nproc` (Linux) -> `sysctl -n hw.logicalcpu` (macOS) -> `echo 1`.
The `JOBS` doc said the nproc default "matches the `boost:build-and-install` default", but that coupling is only conditionally true (b2 defaults to the core count for boost >= 1.76.0, via a different mechanism — omitting `-j` vs passing `--parallel`), and it makes `cmake.yaml`'s param doc depend on another module's behaviour. Drop the cross-reference so the comment is self-contained.
Bill-hbrhbr
requested changes
Jun 30, 2026
Co-authored-by: Bingran Hu <bingran.hu@yscope.com>
Co-authored-by: Bingran Hu <bingran.hu@yscope.com>
Co-authored-by: Bingran Hu <bingran.hu@yscope.com>
Bill-hbrhbr
previously approved these changes
Jun 30, 2026
Bill-hbrhbr
reviewed
Jun 30, 2026
Bill-hbrhbr
approved these changes
Jun 30, 2026
JOBS is unset.
Member
Author
|
After chatting with @davidlion offline, we've decided on a more comprehensive fix. |
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.
Description
cmake:buildalways emitted--parallel "{{.JOBS}}"withJOBSdefaulting to the empty string, so an unsetJOBSrenderedcmake --build <dir> --parallel "". cmake turns that into baregmake -f Makefile -j, i.e. unbounded parallelism — a single build could spawn far more compiler processes than there are cores, oversubscribing the machine and risking OOM on large dependencies like folly.Bound the default to the number of logical CPUs (
nproc/sysctl, falling back to1), so--parallelalways receives a finite, right-sized value and a single build no longer oversubscribes. Callers can still override viaJOBS(orCMAKE_JOBS, which flows throughinstall-remote-tar->build).This matches
boost:build-and-install(b2 defaults to the core count for boost >= 1.76.0). Cross-build scheduling — running severalcmake:buildinvocations concurrently — remains the caller's responsibility; setJOBSlower to avoid oversubscribing across builds.Cross-platform:
nproc(Linux) ->sysctl -n hw.logicalcpu(macOS) ->echo 1.Validation performed
task lint:checkandtask testpass.Scratch
Taskfile.ymlincludingutils/utils.yaml, wrappingutils:cmake:build(host has 12 logical CPUs):JOBScmake --build "build" --parallel "12"JOBS=(explicit empty)cmake --build "build" --parallel "12"JOBS=5cmake --build "build" --parallel "5"(override respected)For reference, the pre-fix empty case rendered
--parallel ""-> baregmake -f Makefile -j(unlimited).Summary by CodeRabbit