Skip to content

Commit c0052a4

Browse files
committed
Build ninja binary in CI
1 parent 9b1eb5b commit c0052a4

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ jobs:
4545
with:
4646
node-version: 16
4747

48+
# Required for ninja build
49+
- name: "Windows: Use MSVC"
50+
if: runner.os == 'Windows'
51+
uses: TheMrMilchmann/setup-msvc-dev@v2
52+
with:
53+
arch: x64
54+
55+
- name: Build ninja
56+
run: node scripts/buildNinjaBinary.js
57+
4858
- name: NPM install
4959
run: opam exec -- npm ci
5060
env:

scripts/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ format.js
44
local_br_clean.sh
55
setVersion.js
66
makeArtifactList.js
7+
buildNinjaBinary.js

scripts/buildNinjaBinary.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env node
2+
3+
const child_process = require("child_process");
4+
const fs = require("fs");
5+
const path = require("path");
6+
7+
const platform = process.platform;
8+
const ninjaDir = path.join(__dirname, "..", "ninja");
9+
const buildCommand = "python configure.py --bootstrap --verbose";
10+
11+
if (platform === "win32") {
12+
// On Windows, the build uses the MSVC compiler which needs to be on the path.
13+
child_process.execSync(buildCommand, { cwd: ninjaDir });
14+
} else {
15+
if (process.platform === "darwin") {
16+
process.env["CXXFLAGS"] = "-flto";
17+
}
18+
child_process.execSync(buildCommand, { stdio: [0, 1, 2], cwd: ninjaDir });
19+
child_process.execSync(`strip ninja`, { stdio: [0, 1, 2], cwd: ninjaDir });
20+
}
21+
22+
const src = path.join(ninjaDir, `ninja${platform === "win32" ? ".exe" : ""}`);
23+
24+
const dst =
25+
platform === "darwin" && process.arch === "arm64"
26+
? path.join(__dirname, "..", process.platform + process.arch, `ninja.exe`)
27+
: path.join(__dirname, "..", platform, `ninja.exe`);
28+
29+
fs.copyFileSync(src, dst);

0 commit comments

Comments
 (0)