Skip to content

Commit 161dedb

Browse files
authored
ci: improve wasm build caching
Squashed from chore/ci-cache after CI passed.
1 parent 05364e9 commit 161dedb

10 files changed

Lines changed: 251 additions & 50 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Setup pinned Rust
2+
description: Install the Rust toolchain pinned by rust-toolchain.toml.
3+
4+
inputs:
5+
components:
6+
description: Comma-separated Rust components to install.
7+
required: false
8+
default: ""
9+
targets:
10+
description: Comma-separated Rust targets to install.
11+
required: false
12+
default: ""
13+
14+
outputs:
15+
toolchain:
16+
description: Rust toolchain channel installed by this action.
17+
value: ${{ steps.toolchain.outputs.toolchain }}
18+
19+
runs:
20+
using: composite
21+
steps:
22+
- name: Read pinned toolchain
23+
id: toolchain
24+
shell: bash
25+
run: |
26+
set -euo pipefail
27+
toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' "${GITHUB_WORKSPACE}/rust-toolchain.toml")"
28+
if [ -z "${toolchain}" ]; then
29+
echo "rust-toolchain.toml does not define a toolchain channel." >&2
30+
exit 1
31+
fi
32+
echo "toolchain=${toolchain}" >> "${GITHUB_OUTPUT}"
33+
34+
- name: Install Rust
35+
uses: dtolnay/rust-toolchain@master
36+
with:
37+
toolchain: ${{ steps.toolchain.outputs.toolchain }}
38+
components: ${{ inputs.components }}
39+
targets: ${{ inputs.targets }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Setup sccache
2+
description: Configure sccache for Rust and optional CMake builds.
3+
4+
inputs:
5+
cmake-launcher:
6+
description: Also let crates that drive CMake use sccache as the C/C++ compiler launcher.
7+
required: false
8+
default: "false"
9+
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Install sccache
14+
uses: mozilla-actions/sccache-action@v0.0.10
15+
16+
- name: Configure sccache
17+
shell: bash
18+
run: |
19+
set -euo pipefail
20+
echo "SCCACHE_GHA_ENABLED=true" >> "${GITHUB_ENV}"
21+
echo "SCCACHE_BASEDIRS=${GITHUB_WORKSPACE}" >> "${GITHUB_ENV}"
22+
echo "RUSTC_WRAPPER=sccache" >> "${GITHUB_ENV}"
23+
echo "CARGO_INCREMENTAL=0" >> "${GITHUB_ENV}"
24+
if [ "${{ inputs.cmake-launcher }}" = "true" ]; then
25+
echo "VIDE_USE_SCCACHE_CMAKE=1" >> "${GITHUB_ENV}"
26+
fi

.github/workflows/ci.yml

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,23 @@ name: CI
33
on:
44
push:
55
branches: [master]
6+
paths-ignore:
7+
- "docs/**"
8+
- "playground/**"
9+
- "crates/vide-lsp-wasm/**"
10+
- ".github/actions/setup-emscripten/**"
11+
- ".github/workflows/docs-preview.yml"
12+
- ".github/workflows/deploy-docs.yml"
613
pull_request:
714
types: [opened, synchronize, reopened]
815
branches: ["**"]
16+
paths-ignore:
17+
- "docs/**"
18+
- "playground/**"
19+
- "crates/vide-lsp-wasm/**"
20+
- ".github/actions/setup-emscripten/**"
21+
- ".github/workflows/docs-preview.yml"
22+
- ".github/workflows/deploy-docs.yml"
923
workflow_dispatch:
1024

1125
concurrency:
@@ -18,16 +32,20 @@ jobs:
1832
runs-on: ubuntu-latest
1933
steps:
2034
- uses: actions/checkout@v4
21-
with:
22-
submodules: recursive
2335
- name: Install Rust
24-
uses: dtolnay/rust-toolchain@nightly
36+
uses: ./.github/actions/setup-rust
2537
with:
2638
components: clippy, rustfmt
39+
- name: Setup sccache
40+
uses: ./.github/actions/setup-sccache
41+
with:
42+
cmake-launcher: "true"
2743
- name: Rust Cache
2844
uses: Swatinem/rust-cache@v2
2945
continue-on-error: true
3046
with:
47+
shared-key: rust-${{ runner.os }}
48+
key: workspace-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', 'src/**', 'crates/**', 'xtask/**') }}
3149
cache-workspace-crates: true
3250
cache-on-failure: true
3351
- name: Format Check
@@ -43,20 +61,24 @@ jobs:
4361
os: [ubuntu-latest, windows-latest, macos-latest]
4462
steps:
4563
- uses: actions/checkout@v4
46-
with:
47-
submodules: recursive
4864
- name: Install Rust
49-
uses: dtolnay/rust-toolchain@nightly
65+
uses: ./.github/actions/setup-rust
5066
with:
5167
components: rustfmt
68+
- name: Setup sccache
69+
uses: ./.github/actions/setup-sccache
70+
with:
71+
cmake-launcher: "true"
5272
- name: Rust Cache
5373
uses: Swatinem/rust-cache@v2
5474
continue-on-error: true
5575
with:
76+
shared-key: rust-${{ runner.os }}
77+
key: workspace-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', 'src/**', 'crates/**', 'xtask/**') }}
5678
cache-workspace-crates: true
5779
cache-on-failure: true
5880
- name: Test
59-
run: rustup run nightly cargo test --workspace
81+
run: cargo test --workspace
6082

6183
vscode-extension:
6284
name: VS Code Checks
@@ -66,18 +88,6 @@ jobs:
6688
working-directory: editors/vscode
6789
steps:
6890
- uses: actions/checkout@v4
69-
with:
70-
submodules: recursive
71-
- name: Install Rust
72-
uses: dtolnay/rust-toolchain@nightly
73-
with:
74-
components: rustfmt
75-
- name: Rust Cache
76-
uses: Swatinem/rust-cache@v2
77-
continue-on-error: true
78-
with:
79-
cache-workspace-crates: true
80-
cache-on-failure: true
8191
- name: Setup Node
8292
uses: actions/setup-node@v4
8393
with:
@@ -111,16 +121,20 @@ jobs:
111121
working-directory: editors/vscode
112122
steps:
113123
- uses: actions/checkout@v4
114-
with:
115-
submodules: recursive
116124
- name: Install Rust
117-
uses: dtolnay/rust-toolchain@nightly
125+
uses: ./.github/actions/setup-rust
118126
with:
119127
components: rustfmt
128+
- name: Setup sccache
129+
uses: ./.github/actions/setup-sccache
130+
with:
131+
cmake-launcher: "true"
120132
- name: Rust Cache
121133
uses: Swatinem/rust-cache@v2
122134
continue-on-error: true
123135
with:
136+
shared-key: rust-${{ runner.os }}
137+
key: package-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', 'src/**', 'crates/**', 'editors/vscode/scripts/**') }}
124138
cache-workspace-crates: true
125139
cache-on-failure: true
126140
- name: Setup Node
@@ -160,8 +174,10 @@ jobs:
160174
include:
161175
- target: alpine-x64
162176
image: ghcr.io/blackdex/rust-musl:x86_64-musl-nightly
177+
rust-target: x86_64-unknown-linux-musl
163178
- target: alpine-arm64
164179
image: ghcr.io/blackdex/rust-musl:aarch64-musl-nightly
180+
rust-target: aarch64-unknown-linux-musl
165181
defaults:
166182
run:
167183
working-directory: editors/vscode
@@ -172,19 +188,32 @@ jobs:
172188
apt-get update
173189
apt-get install -y --no-install-recommends ca-certificates cmake git python3
174190
175-
- name: Install Rust components
176-
working-directory: .
177-
run: rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt
178-
179191
- uses: actions/checkout@v4
180-
with:
181-
submodules: recursive
182192

183193
- name: Trust checkout directories
184194
working-directory: .
185195
run: |
186196
git config --global --add safe.directory "$GITHUB_WORKSPACE"
187-
git config --global --add safe.directory "$GITHUB_WORKSPACE/crates/slang"
197+
198+
- name: Install Rust
199+
uses: ./.github/actions/setup-rust
200+
with:
201+
components: rustfmt
202+
targets: ${{ matrix.rust-target }}
203+
204+
- name: Setup sccache
205+
uses: ./.github/actions/setup-sccache
206+
with:
207+
cmake-launcher: "true"
208+
209+
- name: Rust Cache
210+
uses: Swatinem/rust-cache@v2
211+
continue-on-error: true
212+
with:
213+
shared-key: rust-${{ runner.os }}-${{ matrix.target }}
214+
key: package-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', 'src/**', 'crates/**', 'editors/vscode/scripts/**') }}
215+
cache-workspace-crates: true
216+
cache-on-failure: true
188217

189218
- name: Setup Node
190219
uses: actions/setup-node@v4

.github/workflows/deploy-docs.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,45 @@ jobs:
252252
steps:
253253
- name: Checkout
254254
uses: actions/checkout@v4
255+
256+
- name: Restore playground WASM cache
257+
id: playground-wasm-cache
258+
uses: actions/cache/restore@v4
255259
with:
256-
submodules: recursive
260+
path: playground/public/wasm
261+
key: playground-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', 'src/**', 'crates/**', 'playground/scripts/build-vide-wasm.mjs', 'playground/scripts/script-utils.mjs', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }}
262+
263+
- name: Verify cached playground WASM
264+
if: steps.playground-wasm-cache.outputs.cache-hit == 'true'
265+
run: |
266+
test -s playground/public/wasm/vide-lsp.js
267+
test -s playground/public/wasm/vide-core.js
268+
test -s playground/public/wasm/vide-core.wasm
257269
258270
- name: Install Rust
259-
uses: dtolnay/rust-toolchain@nightly
271+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
272+
uses: ./.github/actions/setup-rust
260273
with:
261274
components: rustfmt
262275

276+
- name: Setup sccache
277+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
278+
uses: ./.github/actions/setup-sccache
279+
with:
280+
cmake-launcher: "true"
281+
263282
- name: Rust Cache
283+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
264284
uses: Swatinem/rust-cache@v2
265285
continue-on-error: true
266286
with:
267287
shared-key: docs-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}
288+
key: wasm-src-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', 'src/**', 'crates/**', 'playground/scripts/build-vide-wasm.mjs', 'playground/scripts/script-utils.mjs', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }}
268289
cache-workspace-crates: true
269290
cache-on-failure: true
270291

271292
- name: Install Emscripten SDK
293+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
272294
uses: ./.github/actions/setup-emscripten
273295
with:
274296
version: ${{ env.EMSDK_VERSION }}
@@ -287,11 +309,20 @@ jobs:
287309
working-directory: playground
288310

289311
- name: Build playground WASM
312+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
290313
run: |
291314
source "${EMSDK}/emsdk_env.sh"
292315
npm run build:wasm
293316
working-directory: playground
294317

318+
- name: Save playground WASM cache
319+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
320+
uses: actions/cache/save@v4
321+
continue-on-error: true
322+
with:
323+
path: playground/public/wasm
324+
key: ${{ steps.playground-wasm-cache.outputs.cache-primary-key }}
325+
295326
- name: Install dependencies
296327
run: npm ci
297328
working-directory: docs

0 commit comments

Comments
 (0)