Skip to content

Add rewatch sources and build rewatch in CI #6762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 88 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,67 @@ env:
OCAMLRUNPARAM: b

jobs:
build-rewatch:
strategy:
fail-fast: false
matrix:
os: [
macos-13, # x64
macos-14, # ARM
ubuntu-latest, # x64
buildjet-2vcpu-ubuntu-2204-arm, # ARM
windows-latest,
]
include:
- os: macos-13
rust-target: x86_64-apple-darwin
- os: macos-14
rust-target: aarch64-apple-darwin
- os: ubuntu-latest
rust-target: x86_64-unknown-linux-musl
- os: buildjet-2vcpu-ubuntu-2204-arm
rust-target: aarch64-unknown-linux-musl
- os: windows-latest
rust-target: x86_64-pc-windows-gnu

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

env:
RUST_BACKTRACE: "1"
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install musl gcc
if: runner.os == 'Linux'
run: sudo apt-get install -y musl-tools

- name: Set up sccache
uses: mozilla-actions/sccache-action@v0.0.4
with:
version: "v0.8.0"

- name: Install rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: ${{matrix.rust-target}}

- name: Build rewatch
run: cargo build --manifest-path rewatch/Cargo.toml --target ${{matrix.rust-target}} --release

- name: Get artifact dir name
run: node .github/workflows/get_artifact_dir_name.js

- name: "Upload artifact: rewatch binary"
uses: actions/upload-artifact@v4
with:
name: rewatch-${{env.artifact_dir_name}}
path: rewatch/target/${{matrix.rust-target}}/release/rewatch${{ runner.os == 'Windows' && '.exe' || '' }}

# Build statically linked Linux binaries in an Alpine-based Docker container
# See https://ocamlpro.com/blog/2021_09_02_generating_static_and_portable_executables_with_ocaml
# for more info.
Expand Down Expand Up @@ -59,6 +120,7 @@ jobs:
# Therefore, only upload the binaries from the static build
upload-linux-arm64-binaries:
needs:
- build-rewatch
- static-binaries-linux

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

- name: Make static linux binaries executable
if: runner.os == 'Linux'
run: |
chmod +x ninja/ninja
chmod +x _build/install/default/bin/*

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Get artifact dir name
run: node .github/workflows/get_artifact_dir_name.js

- name: Download rewatch binary
uses: actions/download-artifact@v4
with:
name: rewatch-${{ env.artifact_dir_name }}
path: rewatch

- name: Copy exes to platform bin dirs
run: node ./scripts/copyExes.js

- name: Prepare artifact upload
run: node .github/workflows/get_artifact_info.js

- name: "Upload artifacts: binaries"
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact_name }}
path: ${{ env.artifact_path }}
name: binaries-${{ env.artifact_dir_name }}
path: ${{ env.artifact_dir_name }}

build:
needs: static-binaries-linux
needs:
- build-rewatch
- static-binaries-linux

strategy:
fail-fast: false
Expand Down Expand Up @@ -133,10 +197,20 @@ jobs:
with:
name: static-binaries-linux-${{ runner.arch }}

- name: Get artifact dir name
run: node .github/workflows/get_artifact_dir_name.js

- name: Download rewatch binary
uses: actions/download-artifact@v4
with:
name: rewatch-${{ env.artifact_dir_name }}
path: rewatch

- name: Make static linux binaries executable
if: runner.os == 'Linux'
run: |
chmod +x ninja/ninja
chmod +x rewatch/rewatch
chmod +x _build/install/default/bin/*

- name: Use OCaml ${{matrix.ocaml_compiler}}
Expand Down Expand Up @@ -252,14 +326,11 @@ jobs:
KEYCDN_PASSWORD: ${{ secrets.KEYCDN_PASSWORD }}
run: bash playground/upload_bundle.sh

- name: Prepare artifact upload
run: node .github/workflows/get_artifact_info.js

- name: "Upload artifacts: binaries"
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact_name }}
path: ${{ env.artifact_path }}
name: binaries-${{ env.artifact_dir_name }}
path: ${{ env.artifact_dir_name }}

- name: "Upload artifacts: lib/ocaml"
if: runner.os == 'Linux'
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/get_artifact_dir_name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const fs = require("fs");
const os = require("os");

const artifactDirName = require("../../scripts/bin_path").dirName;

// Pass artifactDirName to subsequent GitHub actions
fs.appendFileSync(
process.env.GITHUB_ENV,
`artifact_dir_name=${artifactDirName}${os.EOL}`
);
13 changes: 0 additions & 13 deletions .github/workflows/get_artifact_info.js

This file was deleted.

1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Happy hacking!

- [NodeJS v18](https://nodejs.org/)
- C compiler toolchain (usually installed with `xcode` on Mac)
- Rust toolchain (required to build rewatch; follow the instructions at https://www.rust-lang.org/tools/install)
- `opam` (OCaml Package Manager)
- VSCode (+ [OCaml Platform Extension](https://marketplace.visualstudio.com/items?itemName=ocamllabs.ocaml-platform))

Expand Down
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL = /bin/bash

DUNE_BIN_DIR = ./_build/install/default/bin

build: ninja
build: ninja rewatch
dune build
./scripts/copyExes.js

Expand All @@ -15,6 +15,10 @@ bench:
dce:
reanalyze.exe -dce-cmt _build/default/jscomp

rewatch:
cargo build --manifest-path rewatch/Cargo.toml
cp rewatch/target/debug/rewatch rewatch

ninja/ninja:
./scripts/buildNinjaBinary.js

Expand Down Expand Up @@ -78,10 +82,11 @@ clean-gentype:

clean:
dune clean
./scripts/ninja.js clean
cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch
./scripts/ninja.js clean && rm -f ninja/ninja

clean-all: clean clean-gentype

.DEFAULT_GOAL := build

.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
.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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"bin": {
"bsc": "bsc",
"bstracing": "lib/bstracing",
"rescript": "rescript"
"rescript": "rescript",
"rewatch": "scripts/rewatch"
},
"scripts": {
"test": "node scripts/ciTest.js -all",
Expand Down
8 changes: 7 additions & 1 deletion packages/artifacts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ darwin/bsb_helper.exe
darwin/bsc.exe
darwin/ninja.exe
darwin/rescript.exe
darwin/rewatch.exe
darwinarm64/bsb_helper.exe
darwinarm64/bsc.exe
darwinarm64/ninja.exe
darwinarm64/rescript.exe
darwinarm64/rewatch.exe
docs/docson/build-schema.json
lib/bstracing
lib/es6/arg.js
Expand Down Expand Up @@ -1056,10 +1058,12 @@ linux/bsb_helper.exe
linux/bsc.exe
linux/ninja.exe
linux/rescript.exe
linux/rewatch.exe
linuxarm64/bsb_helper.exe
linuxarm64/bsc.exe
linuxarm64/ninja.exe
linuxarm64/rescript.exe
linuxarm64/rewatch.exe
ninja.COPYING
package.json
rescript
Expand All @@ -1070,7 +1074,9 @@ scripts/rescript_convert.js
scripts/rescript_dump.js
scripts/rescript_format.js
scripts/rescript_postinstall.js
scripts/rewatch
win32/bsb_helper.exe
win32/bsc.exe
win32/ninja.exe
win32/rescript.exe
win32/rescript.exe
win32/rewatch.exe
2 changes: 2 additions & 0 deletions rewatch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
rewatch
Loading
Loading