Skip to content

Commit 9601585

Browse files
committed
ci(ENG:21467): Throw more threads at cmake CI
1 parent 6b70b71 commit 9601585

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

scripts/build.mjs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { spawn as nodeSpawn } from "node:child_process";
22
import { existsSync, readFileSync } from "node:fs";
3+
import { cpus } from "node:os";
34
import { basename, join, relative, resolve } from "node:path";
45
import {
56
formatAnnotationToHtml,
@@ -14,6 +15,15 @@ import {
1415
startGroup,
1516
} from "./utils.mjs";
1617

18+
/**
19+
* Control how many parallel jobs are run per CPU core in CI C++ builds.
20+
*
21+
* Note that this number may be large for C++ builds because those builds are
22+
* heavily cached and we want to send out as many requests as possible to
23+
* saturate the network.
24+
*/
25+
const CPP_JOBS_PER_CORE = 1;
26+
1727
if (globalThis.Bun) {
1828
await import("./glob-sources.mjs");
1929
}
@@ -63,10 +73,26 @@ async function build(args) {
6373

6474
const generateOptions = parseOptions(args, generateFlags);
6575
const buildOptions = parseOptions(args, buildFlags);
76+
const ciCppBuild = isCI && !!process.env.BUN_CPP_ONLY;
6677

6778
const buildPath = resolve(generateOptions["-B"] || buildOptions["--build"] || "build");
6879
generateOptions["-B"] = buildPath;
6980
buildOptions["--build"] = buildPath;
81+
if (ciCppBuild) {
82+
// cpp-builds are more-often-than-not extremely highly cached. The cache
83+
// lives in an S3 bucket so querying the cache is mostly an IO-bound
84+
// operation. To combat this, we run the cpp-build with a very large number
85+
// of parallel jobs.
86+
//
87+
// Unfortunately, we cannot offer this performance boost to non-CI builds,
88+
// since those are very likely not going to be cached due to the fact that
89+
// sccache expects absolute paths to cache properly, and local builds are
90+
// extremely likely not to have the same absolute path as the CI builds.
91+
//
92+
// Since CMake has no way of knowing that it's likely going to be IO-bound,
93+
// we just crank up the number of parallel jobs to a very high number.
94+
buildOptions["--parallel"] = `${cpus().length * CPP_JOBS_PER_CORE}`;
95+
}
7096

7197
if (!generateOptions["-S"]) {
7298
generateOptions["-S"] = process.cwd();
@@ -103,8 +129,7 @@ async function build(args) {
103129

104130
await startGroup("CMake Build", () => spawn("cmake", buildArgs, { env }));
105131

106-
const target = buildOptions["--target"] || buildOptions["-t"];
107-
if (isCI && target === "build-cpp") {
132+
if (ciCppBuild) {
108133
await startGroup("sccache stats", () => {
109134
spawn("sccache", ["--show-stats"], { env });
110135
});

0 commit comments

Comments
 (0)