ci: size parallel compiles to the job's memory, not its CPUs (#2425)

Build tests on the untrusted runners (fork PRs, gVisor on shared boxes) fail intermittently with
rustc killed mid-crate ("exit status: 2", no diagnostic) on the biggest crates: solidcraft-engine,
ui-egui. Nothing limits Cargo's parallelism, so it starts one rustc per core the sandbox reports.
scripts/ci/build-jobs.sh sets CARGO_BUILD_JOBS from the memory available (and the cgroup limit,
where lower) at 3 GB per job, capped at nproc, and logs the numbers it saw.


Claude-Session: https://claude.ai/code/session_01QWhMwdqJYQKQq8RCLSL1LT

Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Irakli Kourtis
2026-10-18 07:26:23 -04:00
committed by GitHub
parent 4e0601611c
commit 69b73af490
2 changed files with 31 additions and 0 deletions
+6
View File
@@ -259,6 +259,8 @@ jobs:
SCCACHE_IGNORE_SERVER_IO_ERROR: "1"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Size parallel compiles to the job's memory
run: scripts/ci/build-jobs.sh
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
@@ -450,6 +452,8 @@ jobs:
SCCACHE_IGNORE_SERVER_IO_ERROR: "1"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Size parallel compiles to the job's memory
run: scripts/ci/build-jobs.sh
- name: Warm build directory (self-hosted runner)
if: runner.environment == 'self-hosted' && !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
run: scripts/ci/warm-target.sh doc-tests
@@ -501,6 +505,8 @@ jobs:
SCCACHE_IGNORE_SERVER_IO_ERROR: "1"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Size parallel compiles to the job's memory
run: scripts/ci/build-jobs.sh
- name: Warm build directory (self-hosted runner)
if: runner.environment == 'self-hosted' && !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
run: scripts/ci/warm-target.sh oracle
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Size Cargo's parallel compiles to the memory the job may use, not to the CPUs it sees: inside a
# sandbox (gVisor on the shared untrusted boxes) nproc reports the host's cores while the memory
# limit is the sandbox's, and one rustc per core on the big crates runs out of memory (rustc
# killed, "exit status: 2" with no diagnostic). Sets CARGO_BUILD_JOBS for the rest of the job.
# Usage: build-jobs.sh [GB_PER_JOB] (default 3)
set -euo pipefail
per_job=${1:-3}
kb=$(awk '/MemAvailable/{print $2}' /proc/meminfo)
# A cgroup limit, where there is one, can be lower than what /proc/meminfo reports.
for f in /sys/fs/cgroup/memory.max /sys/fs/cgroup/memory/memory.limit_in_bytes; do
if [ -r "$f" ]; then
limit=$(cat "$f")
if [ "$limit" != max ] && [ "$((limit / 1024))" -lt "$kb" ]; then
kb=$((limit / 1024))
fi
break
fi
done
cpus=$(nproc)
jobs=$((kb / 1048576 / per_job))
[ "$jobs" -lt 1 ] && jobs=1
[ "$jobs" -gt "$cpus" ] && jobs=$cpus
echo "build-jobs: $((kb / 1048576)) GB available, $cpus CPUs -> CARGO_BUILD_JOBS=$jobs"
echo "CARGO_BUILD_JOBS=$jobs" >> "$GITHUB_ENV"