Skip to content

Commit f56f5c2

Browse files
committed
Build rewatch in CI and add it to npm package
1 parent c9c3d06 commit f56f5c2

File tree

12 files changed

+142
-38
lines changed

12 files changed

+142
-38
lines changed

.github/workflows/ci.yml

Lines changed: 88 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,67 @@ env:
2020
OCAMLRUNPARAM: b
2121

2222
jobs:
23+
build-rewatch:
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
os: [
28+
macos-13, # x64
29+
macos-14, # ARM
30+
ubuntu-latest, # x64
31+
buildjet-2vcpu-ubuntu-2204-arm, # ARM
32+
windows-latest,
33+
]
34+
include:
35+
- os: macos-13
36+
rust-target: x86_64-apple-darwin
37+
- os: macos-14
38+
rust-target: aarch64-apple-darwin
39+
- os: ubuntu-latest
40+
rust-target: x86_64-unknown-linux-musl
41+
- os: buildjet-2vcpu-ubuntu-2204-arm
42+
rust-target: aarch64-unknown-linux-musl
43+
- os: windows-latest
44+
rust-target: x86_64-pc-windows-gnu
45+
46+
runs-on: ${{matrix.os}}
47+
48+
env:
49+
RUST_BACKTRACE: "1"
50+
SCCACHE_GHA_ENABLED: "true"
51+
RUSTC_WRAPPER: "sccache"
52+
53+
steps:
54+
- name: Checkout
55+
uses: actions/checkout@v4
56+
57+
- name: Install musl gcc
58+
if: runner.os == 'Linux'
59+
run: sudo apt-get install -y musl-tools
60+
61+
- name: Set up sccache
62+
uses: mozilla-actions/sccache-action@v0.0.4
63+
with:
64+
version: "v0.8.0"
65+
66+
- name: Install rust toolchain
67+
uses: dtolnay/rust-toolchain@master
68+
with:
69+
toolchain: stable
70+
targets: ${{matrix.rust-target}}
71+
72+
- name: Build rewatch
73+
run: cargo build --manifest-path rewatch/Cargo.toml --target ${{matrix.rust-target}} --release
74+
75+
- name: Get artifact dir name
76+
run: node .github/workflows/get_artifact_dir_name.js
77+
78+
- name: "Upload artifact: rewatch binary"
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: rewatch-${{env.artifact_dir_name}}
82+
path: rewatch/target/${{matrix.rust-target}}/release/rewatch${{ runner.os == 'Windows' && '.exe' || '' }}
83+
2384
# Build statically linked Linux binaries in an Alpine-based Docker container
2485
# See https://ocamlpro.com/blog/2021_09_02_generating_static_and_portable_executables_with_ocaml
2586
# for more info.
@@ -59,6 +120,7 @@ jobs:
59120
# Therefore, only upload the binaries from the static build
60121
upload-linux-arm64-binaries:
61122
needs:
123+
- build-rewatch
62124
- static-binaries-linux
63125

64126
runs-on: buildjet-2vcpu-ubuntu-2204-arm
@@ -73,31 +135,33 @@ jobs:
73135
with:
74136
name: static-binaries-linux-${{ runner.arch }}
75137

76-
- name: Make static linux binaries executable
77-
if: runner.os == 'Linux'
78-
run: |
79-
chmod +x ninja/ninja
80-
chmod +x _build/install/default/bin/*
81-
82138
- name: Use Node.js
83139
uses: actions/setup-node@v4
84140
with:
85141
node-version: 18
86142

143+
- name: Get artifact dir name
144+
run: node .github/workflows/get_artifact_dir_name.js
145+
146+
- name: Download rewatch binary
147+
uses: actions/download-artifact@v4
148+
with:
149+
name: rewatch-${{ env.artifact_dir_name }}
150+
path: rewatch
151+
87152
- name: Copy exes to platform bin dirs
88153
run: node ./scripts/copyExes.js
89154

90-
- name: Prepare artifact upload
91-
run: node .github/workflows/get_artifact_info.js
92-
93155
- name: "Upload artifacts: binaries"
94156
uses: actions/upload-artifact@v4
95157
with:
96-
name: ${{ env.artifact_name }}
97-
path: ${{ env.artifact_path }}
158+
name: binaries-${{ env.artifact_dir_name }}
159+
path: ${{ env.artifact_dir_name }}
98160

99161
build:
100-
needs: static-binaries-linux
162+
needs:
163+
- build-rewatch
164+
- static-binaries-linux
101165

102166
strategy:
103167
fail-fast: false
@@ -133,10 +197,20 @@ jobs:
133197
with:
134198
name: static-binaries-linux-${{ runner.arch }}
135199

200+
- name: Get artifact dir name
201+
run: node .github/workflows/get_artifact_dir_name.js
202+
203+
- name: Download rewatch binary
204+
uses: actions/download-artifact@v4
205+
with:
206+
name: rewatch-${{ env.artifact_dir_name }}
207+
path: rewatch
208+
136209
- name: Make static linux binaries executable
137210
if: runner.os == 'Linux'
138211
run: |
139212
chmod +x ninja/ninja
213+
chmod +x rewatch/rewatch
140214
chmod +x _build/install/default/bin/*
141215
142216
- name: Use OCaml ${{matrix.ocaml_compiler}}
@@ -252,14 +326,11 @@ jobs:
252326
KEYCDN_PASSWORD: ${{ secrets.KEYCDN_PASSWORD }}
253327
run: bash playground/upload_bundle.sh
254328

255-
- name: Prepare artifact upload
256-
run: node .github/workflows/get_artifact_info.js
257-
258329
- name: "Upload artifacts: binaries"
259330
uses: actions/upload-artifact@v4
260331
with:
261-
name: ${{ env.artifact_name }}
262-
path: ${{ env.artifact_path }}
332+
name: binaries-${{ env.artifact_dir_name }}
333+
path: ${{ env.artifact_dir_name }}
263334

264335
- name: "Upload artifacts: lib/ocaml"
265336
if: runner.os == 'Linux'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const fs = require("fs");
2+
const os = require("os");
3+
4+
const artifactDirName = require("../../scripts/bin_path").dirName;
5+
6+
// Pass artifactDirName to subsequent GitHub actions
7+
fs.appendFileSync(
8+
process.env.GITHUB_ENV,
9+
`artifact_dir_name=${artifactDirName}${os.EOL}`
10+
);

.github/workflows/get_artifact_info.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Happy hacking!
1616
1717
- [NodeJS v18](https://nodejs.org/)
1818
- C compiler toolchain (usually installed with `xcode` on Mac)
19+
- Rust toolchain (required to build rewatch; follow the instructions at https://www.rust-lang.org/tools/install)
1920
- `opam` (OCaml Package Manager)
2021
- VSCode (+ [OCaml Platform Extension](https://marketplace.visualstudio.com/items?itemName=ocamllabs.ocaml-platform))
2122

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SHELL = /bin/bash
22

33
DUNE_BIN_DIR = ./_build/install/default/bin
44

5-
build: ninja
5+
build: ninja rewatch
66
dune build
77
./scripts/copyExes.js
88

@@ -15,6 +15,10 @@ bench:
1515
dce:
1616
reanalyze.exe -dce-cmt _build/default/jscomp
1717

18+
rewatch:
19+
cargo build --manifest-path rewatch/Cargo.toml
20+
cp rewatch/target/debug/rewatch rewatch
21+
1822
ninja/ninja:
1923
./scripts/buildNinjaBinary.js
2024

@@ -78,10 +82,11 @@ clean-gentype:
7882

7983
clean:
8084
dune clean
81-
./scripts/ninja.js clean
85+
cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch
86+
./scripts/ninja.js clean && rm -f ninja/ninja
8287

8388
clean-all: clean clean-gentype
8489

8590
.DEFAULT_GOAL := build
8691

87-
.PHONY: build watch ninja bench dce test test-syntax test-syntax-roundtrip test-gentype test-all lib playground playground-cmijs playground-release artifacts format checkformat clean-gentype clean clean-all
92+
.PHONY: build watch rewatch ninja bench dce test test-syntax test-syntax-roundtrip test-gentype test-all lib playground playground-cmijs playground-release artifacts format checkformat clean-gentype clean clean-all

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"bin": {
1313
"bsc": "bsc",
1414
"bstracing": "lib/bstracing",
15-
"rescript": "rescript"
15+
"rescript": "rescript",
16+
"rewatch": "scripts/rewatch"
1617
},
1718
"scripts": {
1819
"test": "node scripts/ciTest.js -all",

packages/artifacts.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ darwin/bsb_helper.exe
99
darwin/bsc.exe
1010
darwin/ninja.exe
1111
darwin/rescript.exe
12+
darwin/rewatch.exe
1213
darwinarm64/bsb_helper.exe
1314
darwinarm64/bsc.exe
1415
darwinarm64/ninja.exe
1516
darwinarm64/rescript.exe
17+
darwinarm64/rewatch.exe
1618
docs/docson/build-schema.json
1719
lib/bstracing
1820
lib/es6/arg.js
@@ -1056,10 +1058,12 @@ linux/bsb_helper.exe
10561058
linux/bsc.exe
10571059
linux/ninja.exe
10581060
linux/rescript.exe
1061+
linux/rewatch.exe
10591062
linuxarm64/bsb_helper.exe
10601063
linuxarm64/bsc.exe
10611064
linuxarm64/ninja.exe
10621065
linuxarm64/rescript.exe
1066+
linuxarm64/rewatch.exe
10631067
ninja.COPYING
10641068
package.json
10651069
rescript
@@ -1070,7 +1074,9 @@ scripts/rescript_convert.js
10701074
scripts/rescript_dump.js
10711075
scripts/rescript_format.js
10721076
scripts/rescript_postinstall.js
1077+
scripts/rewatch
10731078
win32/bsb_helper.exe
10741079
win32/bsc.exe
10751080
win32/ninja.exe
1076-
win32/rescript.exe
1081+
win32/rescript.exe
1082+
win32/rewatch.exe

rewatch/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
target
1+
target/
2+
rewatch

scripts/.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
# keep only those actually needed in the npm package.
33
*
44
!bin_path.js
5-
!rescript_*.js
5+
!rescript_*.js
6+
!rewatch

scripts/copyExes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { duneBinDir } = require("./dune");
88
const { absolutePath: platformBinDir } = require("./bin_path");
99

1010
const ninjaDir = path.join(__dirname, "..", "ninja");
11+
const rewatchDir = path.join(__dirname, "..", "rewatch");
1112

1213
if (!fs.existsSync(platformBinDir)) {
1314
fs.mkdirSync(platformBinDir);
@@ -34,3 +35,4 @@ copyExe(duneBinDir, "rescript");
3435
copyExe(duneBinDir, "bsc");
3536
copyExe(duneBinDir, "bsb_helper");
3637
copyExe(ninjaDir, "ninja");
38+
copyExe(rewatchDir, "rewatch");

scripts/makeArtifactList.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ if (isCheckMode) {
4747

4848
function getFilesAddedByCI() {
4949
const platforms = ["darwin", "darwinarm64", "linux", "linuxarm64", "win32"];
50-
const exes = ["bsb_helper.exe", "bsc.exe", "ninja.exe", "rescript.exe"];
50+
const exes = [
51+
"bsb_helper.exe",
52+
"bsc.exe",
53+
"ninja.exe",
54+
"rescript.exe",
55+
"rewatch.exe",
56+
];
5157

5258
const files = ["ninja.COPYING"];
5359

scripts/rewatch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
//@ts-check
3+
"use strict";
4+
5+
const path = require("path");
6+
const child_process = require("child_process");
7+
8+
const binAbsolutePath = require("./bin_path").absolutePath;
9+
const rewatchExe = path.join(binAbsolutePath, "rewatch.exe");
10+
11+
const args = process.argv.slice(2);
12+
13+
child_process.spawnSync(rewatchExe, args, { stdio: "inherit" });

0 commit comments

Comments
 (0)