Skip to content

The native runtime for three.js: three.js, down to the metal. 45× smaller than Electron, on a Sony PS3, and path-traced at 60 fps on ray-tracing GPUs.

CI on GitHub's own actions: a local cargo cache action, wasm-bindgen's CLI by cargo install (#35)

Yujia38eea328553d
diff --git a/.github/actions/cargo-cache/action.yml b/.github/actions/cargo-cache/action.yml
new file mode 100644
index 0000000..677356b
--- /dev/null
+++ b/.github/actions/cargo-cache/action.yml
@@ -0,0 +1,39 @@
+# Cargo's downloads and the target directories of the given workspaces, kept between runs with GitHub's own cache
+# action. (The organization's policy allows GitHub's actions and verified creators' only, so CI uses no other.)
+#
+# The key: the runner's OS, the compiler, the job, `key` (what else the build depends on), and the lock files of the
+# workspaces. A run whose lock files changed starts from the newest cache of the same job, compiler and `key`, and
+# saves its own; a run with the same lock files saves nothing. Cargo rebuilds the checkout's own crates each run (their
+# sources are newer than the cached build), so what the cache saves is the dependencies.
+name: cargo cache
+description: Keeps Cargo's registry and the workspaces' target directories between runs (actions/cache).
+inputs:
+ workspaces:
+ description: Directories with a Cargo.lock and a target directory, one a line.
+ required: true
+ key:
+ description: More for the key (a hash of sources the cached build depends on).
+ default: ""
+runs:
+ using: composite
+ steps:
+ - id: k
+ shell: bash
+ env:
+ WORKSPACES: ${{ inputs.workspaces }}
+ run: |
+ paths=$'~/.cargo/registry/index\n~/.cargo/registry/cache\n~/.cargo/git/db'
+ locks=()
+ for w in $WORKSPACES; do
+ paths+=$'\n'"$w/target"
+ locks+=("$w/Cargo.lock")
+ done
+ { echo 'paths<<END_OF_PATHS'; echo "$paths"; echo END_OF_PATHS; } >> "$GITHUB_OUTPUT"
+ echo "rustc=$(rustc -vV | sed -n 's/^commit-hash: //p' | cut -c1-12)" >> "$GITHUB_OUTPUT"
+ echo "locks=$(cat "${locks[@]}" | sha256sum | cut -c1-16)" >> "$GITHUB_OUTPUT"
+ - uses: actions/cache@v6
+ with:
+ path: ${{ steps.k.outputs.paths }}
+ key: cargo-${{ runner.os }}-${{ steps.k.outputs.rustc }}-${{ github.job }}-${{ inputs.key }}-${{ steps.k.outputs.locks }}
+ restore-keys: |
+ cargo-${{ runner.os }}-${{ steps.k.outputs.rustc }}-${{ github.job }}-${{ inputs.key }}-
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 46139d2..7c45d4c 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -90,7 +90,7 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
- - uses: Swatinem/rust-cache@v2
+ - uses: ./.github/actions/cargo-cache
with:
workspaces: renderer
- run: cd renderer && cargo build --release --locked
@@ -115,7 +115,7 @@ jobs:
with:
node-version: 24
- run: rustup target add wasm32-unknown-unknown
- - uses: Swatinem/rust-cache@v2
+ - uses: ./.github/actions/cargo-cache
with:
workspaces: renderer/voxel-core
# The voxel engine's core builds for the browser (wasm32: players run the game there) and passes its tests.
@@ -142,8 +142,8 @@ jobs:
# the build of glamx it keeps is of these sources (a change to them starts from no cache).
- run: find renderer/third_party -exec touch -d 2000-01-01T00:00:00Z {} +
# physics-core's own target directory, and the renderer's (the determinism check builds the renderer's crate graph
- # for wasm32 there; rust-cache leaves out of that one the crates under renderer/, glamx among them).
- - uses: Swatinem/rust-cache@v2
+ # for wasm32 there).
+ - uses: ./.github/actions/cargo-cache
with:
key: third-party-${{ hashFiles('renderer/third_party/**') }}
workspaces: |
@@ -163,7 +163,7 @@ jobs:
steps:
- uses: actions/checkout@v7
- run: rustup target add wasm32-unknown-unknown
- - uses: Swatinem/rust-cache@v2
+ - uses: ./.github/actions/cargo-cache
with:
workspaces: renderer
# The engine's library builds for the browser (wasm32; docs/RUNTIME.md "The engine's library in a browser").
@@ -183,19 +183,26 @@ jobs:
cache: npm
- run: npm ci
- run: rustup target add wasm32-unknown-unknown
- - uses: Swatinem/rust-cache@v2
+ - uses: ./.github/actions/cargo-cache
with:
workspaces: renderer/web
# The module a page loads: the engine's exports for the browser's JavaScript (renderer/web; docs/RUNTIME.md
# "The engine in a browser"). Running it needs a browser with a GPU: tools/web-hello.ts, on a developer's machine.
- run: cd renderer/web && cargo build --release --locked --target wasm32-unknown-unknown
- # wasm-bindgen's CLI writes the module's JavaScript; its version is the crate's (renderer/web/Cargo.toml). The
- # release's prebuilt binary, checksummed by the action (it falls back to cargo-binstall for a version it lacks).
+ # wasm-bindgen's CLI writes the module's JavaScript; its version is the crate's (renderer/web/Cargo.toml). Built
+ # from crates.io with its own lock file (`cargo install --locked`) the first time a version is asked for, and
+ # the binary kept for the runs after.
- id: bindgen
run: echo "version=$(grep -o 'wasm-bindgen = "=[0-9.]*"' renderer/web/Cargo.toml | grep -o '[0-9][0-9.]*')" >> "$GITHUB_OUTPUT"
- - uses: taiki-e/install-action@v2
+ - id: bindgen-cli
+ uses: actions/cache@v6
with:
- tool: wasm-bindgen@${{ steps.bindgen.outputs.version }}
+ path: ~/.cargo/bin/wasm-bindgen
+ key: wasm-bindgen-${{ runner.os }}-${{ steps.bindgen.outputs.version }}
+ - if: steps.bindgen-cli.outputs.cache-hit != 'true'
+ env:
+ VERSION: ${{ steps.bindgen.outputs.version }}
+ run: cargo install wasm-bindgen-cli --version "$VERSION" --locked
# The browser's side of it without a browser or a GPU: the module in Node, the page's `__engine` over its exports,
# the game bundle the native runtime loads, the physics hello world's script and its checks (tools/web-engine.ts).
- run: node tools/web-engine.ts
diff --git a/docs/WORKFLOW.md b/docs/WORKFLOW.md
index a634faa..5bb840e 100644
--- a/docs/WORKFLOW.md
+++ b/docs/WORKFLOW.md
@@ -236,7 +236,8 @@ The supervisor never sits in `gh run watch` or `gh pr checks --watch`. Instead:
- A background wait is allowed only when the next step depends on it within the same check. It needs a hard timeout
of at most 10 minutes and is stopped as soon as it is not needed. Long-running "watchers" are never left behind.
-**CI cost.** The checks run as parallel jobs, each with its own `Swatinem/rust-cache`. With warm caches a run of every
+**CI cost.** The checks run as parallel jobs, each with its own cache (`.github/actions/cargo-cache`, on GitHub's
+`actions/cache`: the organization allows GitHub's actions and verified creators' only). With warm caches a run of every
job takes about 3 minutes (the renderer's release build and the browser module's are the longest); with none, about 8
and a half (the physics job's five builds of Rapier). A PR runs only the jobs whose inputs it changes (a docs-only PR
runs `ts` alone, in about a minute), and the `threert` job sums them up: it is the check to read before merging. A