Skip to content

Commit 0e718c5

Browse files
jfrolichcknitt
andauthored
Compile runtime with rewatch and add rewatch tests to the compiler repo (#7422)
* change config * still need -make-runtime * add make lib-rewatch * update rewatch * test rewatch in Makefile * test * add install state * upstream new version of rewatch * make it work! * make rewatch default for building the runtime * run rewatch tests * see error * install packages as part of the ci test suite * cat the changes * empty commit * immutable install * remove install state * install state ignore * run on mac os due to subtle diffs * fix * use ci version of rescript * fix diff * trigger * fix * show rescript version * update snapshots * end to end tests * fix * fix * fix * propagate bsc path * fix * empty commit * don't run unit tests if we don't build a new rewatch binary * other instance * empty commit * find correct bsc * if the lockfile is deleted, stop running the watcher * fix lock tests * More informative test * fix watch * make tests work correctly * fix * upstream changes * test * fix * commit * fix js * fix diff * remove deps * add core dep * fix lockfile * Build runtime with rewatch in CI * Fix CI, move rewatch build steps into main compiler build job * Revert "Build runtime with rewatch in CI" This reverts commit 64f84ea. * Build runtime with rewatch unless on Windows * Clean up integration test running * Rewatch integration tests don't work on Windows and macOS x64 * CHANGELOG * Run rewatch integration tests on Linux only --------- Co-authored-by: Christoph Knittel <[email protected]>
1 parent 870906d commit 0e718c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+3206
-792
lines changed

.github/workflows/ci.yml

+72-88
Original file line numberDiff line numberDiff line change
@@ -20,76 +20,6 @@ env:
2020
OCAMLRUNPARAM: b
2121

2222
jobs:
23-
build-rewatch:
24-
strategy:
25-
fail-fast: false
26-
matrix:
27-
include:
28-
- os: macos-13 # x64
29-
rust-target: x86_64-apple-darwin
30-
node-target: darwin-x64
31-
- os: macos-14 # ARM
32-
rust-target: aarch64-apple-darwin
33-
node-target: darwin-arm64
34-
- os: ubuntu-24.04 # x64
35-
rust-target: x86_64-unknown-linux-musl
36-
node-target: linux-x64
37-
- os: ubuntu-24.04-arm # ARM
38-
rust-target: aarch64-unknown-linux-musl
39-
node-target: linux-arm64
40-
- os: windows-latest
41-
rust-target: x86_64-pc-windows-gnu
42-
node-target: win32-x64
43-
44-
runs-on: ${{matrix.os}}
45-
46-
env:
47-
RUST_BACKTRACE: "1"
48-
49-
steps:
50-
- name: Checkout
51-
uses: actions/checkout@v4
52-
53-
- name: Use Node.js
54-
uses: actions/setup-node@v4
55-
with:
56-
node-version-file: .nvmrc
57-
58-
- name: Restore build cache
59-
id: build-cache
60-
uses: actions/cache@v4
61-
with:
62-
path: rewatch/target
63-
key: rewatch-build-v2-${{ matrix.rust-target }}-${{ hashFiles('rewatch/src/**', 'rewatch/Cargo.lock') }}
64-
65-
- name: Install musl gcc
66-
if: steps.build-cache.outputs.cache-hit != 'true' && runner.os == 'Linux'
67-
run: sudo apt-get install -y --no-install-recommends musl-tools
68-
69-
- name: Install rust toolchain
70-
if: steps.build-cache.outputs.cache-hit != 'true'
71-
uses: dtolnay/rust-toolchain@master
72-
with:
73-
toolchain: stable
74-
targets: ${{ matrix.rust-target }}
75-
76-
- name: Build rewatch
77-
if: steps.build-cache.outputs.cache-hit != 'true'
78-
run: |
79-
cargo build --manifest-path rewatch/Cargo.toml --target ${{ matrix.rust-target }} --release
80-
81-
- name: Copy rewatch binary
82-
run: |
83-
cp rewatch/target/${{ matrix.rust-target }}/release/rewatch${{ runner.os == 'Windows' && '.exe' || '' }} rewatch.exe
84-
shell: bash
85-
86-
- name: "Upload artifact: rewatch binary"
87-
uses: actions/upload-artifact@v4
88-
with:
89-
name: rewatch-${{ matrix.node-target }}
90-
path: rewatch.exe
91-
if-no-files-found: error
92-
9323
build-compiler:
9424
strategy:
9525
fail-fast: false
@@ -100,33 +30,44 @@ jobs:
10030
upload_binaries: true
10131
upload_libs: true
10232
node-target: linux-x64
33+
rust-target: x86_64-unknown-linux-musl
10334
- os: ubuntu-24.04-arm # ARM
10435
ocaml_compiler: ocaml-variants.5.3.0+options,ocaml-option-static
10536
upload_binaries: true
10637
# Build the playground compiler and run the benchmarks on the fastest runner
10738
build_playground: true
10839
benchmarks: true
10940
node-target: linux-arm64
41+
rust-target: aarch64-unknown-linux-musl
11042
- os: macos-13 # x64
11143
ocaml_compiler: 5.3.0
11244
upload_binaries: true
11345
node-target: darwin-x64
46+
rust-target: x86_64-apple-darwin
11447
- os: macos-14 # ARM
11548
ocaml_compiler: 5.3.0
11649
upload_binaries: true
11750
node-target: darwin-arm64
51+
rust-target: aarch64-apple-darwin
11852
- os: windows-latest
11953
ocaml_compiler: 5.3.0
12054
upload_binaries: true
12155
node-target: win32-x64
56+
rust-target: x86_64-pc-windows-gnu
12257

12358
# Verify that the compiler still builds with older OCaml versions
12459
- os: ubuntu-24.04
12560
ocaml_compiler: ocaml-variants.5.2.1+options,ocaml-option-static
61+
node-target: linux-x64
62+
rust-target: x86_64-unknown-linux-musl
12663
- os: ubuntu-24.04
12764
ocaml_compiler: ocaml-variants.5.0.0+options,ocaml-option-static
65+
node-target: linux-x64
66+
rust-target: x86_64-unknown-linux-musl
12867
- os: ubuntu-24.04
12968
ocaml_compiler: ocaml-variants.4.14.2+options,ocaml-option-static
69+
node-target: linux-x64
70+
rust-target: x86_64-unknown-linux-musl
13071

13172
runs-on: ${{matrix.os}}
13273

@@ -135,6 +76,7 @@ jobs:
13576
# we do track its version manually
13677
OPAM_VERSION: 2.3.0
13778
DUNE_PROFILE: release
79+
RUST_BACKTRACE: "1"
13880

13981
steps:
14082
- name: "Windows: Set git config"
@@ -153,6 +95,9 @@ jobs:
15395
cache: yarn
15496
node-version-file: .nvmrc
15597

98+
- name: Install npm packages
99+
run: yarn install
100+
156101
- name: Install dependencies (Linux)
157102
if: runner.os == 'Linux'
158103
uses: awalsh128/[email protected]
@@ -161,6 +106,36 @@ jobs:
161106
packages: bubblewrap darcs g++-multilib gcc-multilib mercurial musl-tools rsync
162107
version: v3
163108

109+
- name: Restore rewatch build cache
110+
id: rewatch-build-cache
111+
uses: actions/cache@v4
112+
with:
113+
path: rewatch/target
114+
key: rewatch-build-v2-${{ matrix.rust-target }}-${{ hashFiles('rewatch/src/**', 'rewatch/Cargo.lock') }}
115+
116+
- name: Install rust toolchain
117+
if: steps.rewatch-build-cache.outputs.cache-hit != 'true'
118+
uses: dtolnay/rust-toolchain@master
119+
with:
120+
toolchain: stable
121+
targets: ${{ matrix.rust-target }}
122+
123+
- name: Build rewatch
124+
if: steps.rewatch-build-cache.outputs.cache-hit != 'true'
125+
run: |
126+
cargo build --manifest-path rewatch/Cargo.toml --target ${{ matrix.rust-target }} --release
127+
128+
- name: Run rewatch unit tests
129+
if: steps.rewatch-build-cache.outputs.cache-hit != 'true'
130+
run: |
131+
cargo test --manifest-path rewatch/Cargo.toml
132+
133+
- name: Copy rewatch binary
134+
run: |
135+
cp rewatch/target/${{ matrix.rust-target }}/release/rewatch${{ runner.os == 'Windows' && '.exe' || '' }} rewatch
136+
./scripts/copyExes.js --rewatch
137+
shell: bash
138+
164139
# matrix.ocaml_compiler may contain commas
165140
- name: Get OPAM cache key
166141
shell: bash
@@ -305,9 +280,6 @@ jobs:
305280
_build
306281
key: ${{ steps.compiler-build-state-key.outputs.value }}
307282

308-
- name: Install npm packages
309-
run: yarn install
310-
311283
- name: Copy compiler exes to platform bin dir
312284
run: node scripts/copyExes.js --compiler
313285

@@ -352,7 +324,13 @@ jobs:
352324
if: ${{ runner.os == 'Windows' }}
353325
run: opam exec -- make test-syntax
354326

355-
- name: Build runtime/stdlib
327+
- name: Build runtime/stdlib with rewatch
328+
if: ${{ runner.os != 'Windows' }}
329+
run: ./scripts/buildRuntimeRewatch.sh
330+
shell: bash
331+
332+
- name: Build runtime/stdlib with bsb (Windows)
333+
if: ${{ runner.os == 'Windows' }}
356334
run: ./scripts/buildRuntime.sh
357335
shell: bash
358336

@@ -440,8 +418,7 @@ jobs:
440418
path: lib/ocaml
441419

442420
pkg-pr-new:
443-
needs:
444-
- build-rewatch
421+
needs:
445422
- build-compiler
446423
runs-on: ubuntu-24.04-arm
447424
steps:
@@ -457,7 +434,7 @@ jobs:
457434
- name: Download artifacts
458435
uses: actions/download-artifact@v4
459436
with:
460-
pattern: "@(binaries-*|rewatch-*|lib-ocaml)"
437+
pattern: "@(binaries-*|lib-ocaml)"
461438

462439
- name: Move artifacts into packages
463440
run: .github/workflows/moveArtifacts.sh
@@ -467,27 +444,23 @@ jobs:
467444
run: |
468445
yarn dlx pkg-pr-new publish "." "./packages/@rescript/*"
469446
470-
installationTest:
447+
test-integration:
471448
needs:
472449
- pkg-pr-new
473450
strategy:
474451
fail-fast: false
475452
matrix:
476453
include:
477454
- os: macos-13
478-
node-target: darwin-x64
479455
- os: macos-14
480-
node-target: darwin-arm64
481456
- os: ubuntu-24.04
482-
node-target: linux-x64
483457
- os: ubuntu-24.04-arm
484-
node-target: linux-arm64
485458
- os: windows-latest
486-
node-target: win32-x64
487459
runs-on: ${{ matrix.os }}
460+
env:
461+
RUST_BACKTRACE: "1"
488462
steps:
489463
- name: Checkout
490-
id: checkout
491464
uses: actions/checkout@v4
492465

493466
- name: Use Node.js
@@ -521,11 +494,22 @@ jobs:
521494
shell: bash
522495
working-directory: ${{ steps.tmp-dir.outputs.path }}
523496

497+
- name: Install ReScript package in rewatch/testrepo
498+
if: runner.os == 'Linux'
499+
run: |
500+
COMMIT_SHA="${{ github.event.pull_request.head.sha || github.sha }}"
501+
yarn add "rescript@https://pkg.pr.new/rescript-lang/rescript@${COMMIT_SHA::7}"
502+
shell: bash
503+
working-directory: rewatch/testrepo
504+
505+
- name: Run rewatch integration tests
506+
# Currently failing on Windows and intermittently on macOS
507+
if: runner.os == 'Linux'
508+
run: make test-rewatch-ci
509+
524510
publish:
525511
needs:
526-
- build-rewatch
527-
- build-compiler
528-
- installationTest
512+
- test-integration
529513
if: startsWith(github.ref, 'refs/tags/v')
530514
runs-on: ubuntu-24.04-arm
531515
steps:
@@ -542,7 +526,7 @@ jobs:
542526
- name: Download artifacts
543527
uses: actions/download-artifact@v4
544528
with:
545-
pattern: "@(binaries-*|rewatch-*|lib-ocaml)"
529+
pattern: "@(binaries-*|lib-ocaml)"
546530

547531
- name: Move artifacts into packages
548532
run: .github/workflows/moveArtifacts.sh

.github/workflows/moveArtifacts.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ check_statically_linked() {
2929
mv lib-ocaml lib/ocaml
3030

3131
# @rescript/{target}
32-
chmod +x binaries-*/*.exe rewatch-*/*.exe
33-
mv -f binaries-darwin-x64/* rewatch-darwin-x64/* "packages/@rescript/darwin-x64/bin"
34-
mv -f binaries-darwin-arm64/* rewatch-darwin-arm64/* "packages/@rescript/darwin-arm64/bin"
35-
mv -f binaries-linux-x64/* rewatch-linux-x64/* "packages/@rescript/linux-x64/bin"
36-
mv -f binaries-linux-arm64/* rewatch-linux-arm64/* "packages/@rescript/linux-arm64/bin"
37-
mv -f binaries-win32-x64/* rewatch-win32-x64/* "packages/@rescript/win32-x64/bin"
32+
chmod +x binaries-*/*.exe
33+
mv -f binaries-darwin-x64/* "packages/@rescript/darwin-x64/bin"
34+
mv -f binaries-darwin-arm64/* "packages/@rescript/darwin-arm64/bin"
35+
mv -f binaries-linux-x64/* "packages/@rescript/linux-x64/bin"
36+
mv -f binaries-linux-arm64/* "packages/@rescript/linux-arm64/bin"
37+
mv -f binaries-win32-x64/* "packages/@rescript/win32-x64/bin"
3838
check_statically_linked "packages/@rescript/linux-x64/bin"
3939
check_statically_linked "packages/@rescript/linux-arm64/bin"
4040

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
- AST: Add bar location to `case`. https://github.com/rescript-lang/rescript/pull/7407
4646
- Clean up lazy from ASTs and back-end. https://github.com/rescript-lang/rescript/pull/7474
47+
- Compile runtime with rewatch and add rewatch tests to the compiler repo. https://github.com/rescript-lang/rescript/pull/7422/files
4748

4849
#### :nail_care: Polish
4950

Makefile

+14-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ dce:
1616
reanalyze.exe -dce-cmt _build/default/compiler
1717

1818
rewatch:
19-
cargo build --manifest-path rewatch/Cargo.toml
20-
cp rewatch/target/debug/rewatch rewatch
19+
cargo build --manifest-path rewatch/Cargo.toml --release
20+
cp rewatch/target/release/rewatch rewatch
2121
./scripts/copyExes.js --rewatch
2222

2323
ninja/ninja:
@@ -46,15 +46,25 @@ test-syntax-roundtrip:
4646
test-gentype:
4747
make -C tests/gentype_tests/typescript-react-example clean test
4848

49-
test-all: test test-gentype test-analysis test-tools
49+
test-rewatch:
50+
bash ./rewatch/tests/suite-ci.sh
51+
52+
test-rewatch-ci:
53+
bash ./rewatch/tests/suite-ci.sh node_modules/.bin/rewatch
54+
55+
test-all: test test-gentype test-analysis test-tools test-rewatch
5056

5157
reanalyze:
5258
reanalyze.exe -set-exit-code -all-cmt _build/default/compiler _build/default/tests -exclude-paths compiler/outcome_printer,compiler/ml,compiler/frontend,compiler/ext,compiler/depends,compiler/core,compiler/common,compiler/cmij,compiler/bsb_helper,compiler/bsb
5359

54-
lib:
60+
lib-bsb:
5561
./scripts/buildRuntime.sh
5662
./scripts/prebuilt.js
5763

64+
lib:
65+
./scripts/buildRuntimeRewatch.sh
66+
./scripts/prebuilt.js
67+
5868
artifacts: lib
5969
./scripts/npmPack.js --updateArtifactList
6070

cli/rewatch.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
// @ts-check
44

55
import * as child_process from "node:child_process";
6-
import { rewatch_exe } from "./common/bins.js";
6+
import { rewatch_exe, bsc_exe } from "./common/bins.js";
77

88
const args = process.argv.slice(2);
99

10-
child_process.spawnSync(rewatch_exe, args, { stdio: "inherit" });
10+
child_process.spawnSync(rewatch_exe, [...args, "--bsc-path", bsc_exe], {
11+
stdio: "inherit",
12+
});

rewatch/.cargo/config.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[alias]
2+
build-m1-release = "RUSTFLAGS=\"-C target-cpu=apple-m1\" cargo build --release"
3+
build-docs = "cargo doc --no-deps --document-private-items --target-dir ./docs"
4+

rewatch/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
.DS_Store
3+
/docs

0 commit comments

Comments
 (0)