Use dynamic CPU count for cmake --build -j in docs and test scripts (#20436)
### Summary
Several build docs and `test/` scripts hardcode the `cmake --build -j`
parallelism (`-j9`, `-j10`), which assumes a fixed machine. This
replaces
them with a portable expression that derives "core count + 1" at runtime
—
`nproc` on Linux, `sysctl -n hw.ncpu` on macOS:
-j$(( $(nproc 2>/dev/null || sysctl -n hw.ncpu) + 1 ))
"core count + 1" matches the guidance already documented in
`docs/source/using-executorch-building-from-source.md`. The `nproc →
sysctl`
fallback keeps the commands working on both Linux and macOS, and the
arithmetic degrades gracefully to `-j1` if neither tool is available.
Partial fix for #10887. Scope is limited to general (non-vendor) docs
and
contributor-facing `test/` build scripts (9 files). Vendor-backend
scripts
(cadence, vulkan, coreml, qualcomm, mediatek, samsung, mps, nxp), CI
scripts
under `.ci/`, and non-cmake `-j` flags are intentionally left for
follow-ups.
### Test plan
- `lintrunner` passes on all changed files.
- `bash -n` passes on the three modified shell scripts.
- Verified the expression evaluates to a valid integer on Linux, e.g.
`17`
on a 16-core machine.
cc @GregoryComer @digantdesai @cbilgin @JakeStevens @larryliu0820 S
Shamsudeen Saleem committed
7f86746e08a12d4305e4eaf2cbe2a1505a513b95
Parent: 7628aa6
Committed by GitHub <noreply@github.com>
on 7/22/2026, 3:43:18 PM