Skip to content

Commit 2d1da3a

Browse files
committed
ci: improve wasm build caching
1 parent 2a8b20f commit 2d1da3a

9 files changed

Lines changed: 241 additions & 23 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: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ jobs:
3333
steps:
3434
- uses: actions/checkout@v4
3535
- name: Install Rust
36-
uses: dtolnay/rust-toolchain@nightly
36+
uses: ./.github/actions/setup-rust
3737
with:
3838
components: clippy, rustfmt
39+
- name: Setup sccache
40+
uses: ./.github/actions/setup-sccache
41+
with:
42+
cmake-launcher: "true"
3943
- name: Rust Cache
4044
uses: Swatinem/rust-cache@v2
4145
continue-on-error: true
4246
with:
43-
shared-key: rust-${{ runner.os }}-nightly
47+
shared-key: rust-${{ runner.os }}
48+
key: workspace-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', 'src/**', 'crates/**', 'xtask/**') }}
4449
cache-workspace-crates: true
4550
cache-on-failure: true
4651
- name: Format Check
@@ -57,18 +62,23 @@ jobs:
5762
steps:
5863
- uses: actions/checkout@v4
5964
- name: Install Rust
60-
uses: dtolnay/rust-toolchain@nightly
65+
uses: ./.github/actions/setup-rust
6166
with:
6267
components: rustfmt
68+
- name: Setup sccache
69+
uses: ./.github/actions/setup-sccache
70+
with:
71+
cmake-launcher: "true"
6372
- name: Rust Cache
6473
uses: Swatinem/rust-cache@v2
6574
continue-on-error: true
6675
with:
67-
shared-key: rust-${{ runner.os }}-nightly
76+
shared-key: rust-${{ runner.os }}
77+
key: workspace-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', 'src/**', 'crates/**', 'xtask/**') }}
6878
cache-workspace-crates: true
6979
cache-on-failure: true
7080
- name: Test
71-
run: rustup run nightly cargo test --workspace
81+
run: cargo test --workspace
7282

7383
vscode-extension:
7484
name: VS Code Checks
@@ -112,14 +122,19 @@ jobs:
112122
steps:
113123
- uses: actions/checkout@v4
114124
- name: Install Rust
115-
uses: dtolnay/rust-toolchain@nightly
125+
uses: ./.github/actions/setup-rust
116126
with:
117127
components: rustfmt
128+
- name: Setup sccache
129+
uses: ./.github/actions/setup-sccache
130+
with:
131+
cmake-launcher: "true"
118132
- name: Rust Cache
119133
uses: Swatinem/rust-cache@v2
120134
continue-on-error: true
121135
with:
122-
shared-key: rust-${{ runner.os }}-nightly
136+
shared-key: rust-${{ runner.os }}
137+
key: package-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', 'src/**', 'crates/**', 'editors/vscode/scripts/**') }}
123138
cache-workspace-crates: true
124139
cache-on-failure: true
125140
- name: Setup Node
@@ -159,8 +174,10 @@ jobs:
159174
include:
160175
- target: alpine-x64
161176
image: ghcr.io/blackdex/rust-musl:x86_64-musl-nightly
177+
rust-target: x86_64-unknown-linux-musl
162178
- target: alpine-arm64
163179
image: ghcr.io/blackdex/rust-musl:aarch64-musl-nightly
180+
rust-target: aarch64-unknown-linux-musl
164181
defaults:
165182
run:
166183
working-directory: editors/vscode
@@ -171,17 +188,33 @@ jobs:
171188
apt-get update
172189
apt-get install -y --no-install-recommends ca-certificates cmake git python3
173190
174-
- name: Install Rust components
175-
working-directory: .
176-
run: rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt
177-
178191
- uses: actions/checkout@v4
179192

180193
- name: Trust checkout directories
181194
working-directory: .
182195
run: |
183196
git config --global --add safe.directory "$GITHUB_WORKSPACE"
184197
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
217+
185218
- name: Setup Node
186219
uses: actions/setup-node@v4
187220
with:

.github/workflows/deploy-docs.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,20 +253,44 @@ jobs:
253253
- name: Checkout
254254
uses: actions/checkout@v4
255255

256+
- name: Restore playground WASM cache
257+
id: playground-wasm-cache
258+
uses: actions/cache/restore@v4
259+
with:
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
269+
256270
- name: Install Rust
257-
uses: dtolnay/rust-toolchain@nightly
271+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
272+
uses: ./.github/actions/setup-rust
258273
with:
259274
components: rustfmt
260275

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+
261282
- name: Rust Cache
283+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
262284
uses: Swatinem/rust-cache@v2
263285
continue-on-error: true
264286
with:
265287
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/**') }}
266289
cache-workspace-crates: true
267290
cache-on-failure: true
268291

269292
- name: Install Emscripten SDK
293+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
270294
uses: ./.github/actions/setup-emscripten
271295
with:
272296
version: ${{ env.EMSDK_VERSION }}
@@ -285,11 +309,20 @@ jobs:
285309
working-directory: playground
286310

287311
- name: Build playground WASM
312+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
288313
run: |
289314
source "${EMSDK}/emsdk_env.sh"
290315
npm run build:wasm
291316
working-directory: playground
292317

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+
293326
- name: Install dependencies
294327
run: npm ci
295328
working-directory: docs

.github/workflows/docs-preview.yml

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,29 @@ on:
66
paths:
77
- "docs/**"
88
- "playground/**"
9-
- "crates/vide-lsp-wasm/**"
9+
- "src/**"
10+
- "crates/**"
11+
- "Cargo.toml"
12+
- "Cargo.lock"
13+
- "rust-toolchain.toml"
1014
- ".github/actions/setup-emscripten/**"
15+
- ".github/actions/setup-rust/**"
16+
- ".github/actions/setup-sccache/**"
1117
- ".github/workflows/docs-preview.yml"
1218
- ".github/workflows/deploy-docs.yml"
1319
pull_request:
1420
types: [opened, synchronize, reopened, closed]
1521
paths:
1622
- "docs/**"
1723
- "playground/**"
18-
- "crates/vide-lsp-wasm/**"
24+
- "src/**"
25+
- "crates/**"
26+
- "Cargo.toml"
27+
- "Cargo.lock"
28+
- "rust-toolchain.toml"
1929
- ".github/actions/setup-emscripten/**"
30+
- ".github/actions/setup-rust/**"
31+
- ".github/actions/setup-sccache/**"
2032
- ".github/workflows/docs-preview.yml"
2133
- ".github/workflows/deploy-docs.yml"
2234

@@ -72,20 +84,44 @@ jobs:
7284
- name: Checkout
7385
uses: actions/checkout@v4
7486

87+
- name: Restore playground WASM cache
88+
id: playground-wasm-cache
89+
uses: actions/cache/restore@v4
90+
with:
91+
path: playground/public/wasm
92+
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/**') }}
93+
94+
- name: Verify cached playground WASM
95+
if: steps.playground-wasm-cache.outputs.cache-hit == 'true'
96+
run: |
97+
test -s playground/public/wasm/vide-lsp.js
98+
test -s playground/public/wasm/vide-core.js
99+
test -s playground/public/wasm/vide-core.wasm
100+
75101
- name: Install Rust
76-
uses: dtolnay/rust-toolchain@nightly
102+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
103+
uses: ./.github/actions/setup-rust
77104
with:
78105
components: rustfmt
79106

107+
- name: Setup sccache
108+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
109+
uses: ./.github/actions/setup-sccache
110+
with:
111+
cmake-launcher: "true"
112+
80113
- name: Rust Cache
114+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
81115
uses: Swatinem/rust-cache@v2
82116
continue-on-error: true
83117
with:
84118
shared-key: docs-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}
119+
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/**') }}
85120
cache-workspace-crates: true
86121
cache-on-failure: true
87122

88123
- name: Install Emscripten SDK
124+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
89125
uses: ./.github/actions/setup-emscripten
90126
with:
91127
version: ${{ env.EMSDK_VERSION }}
@@ -104,11 +140,20 @@ jobs:
104140
working-directory: playground
105141

106142
- name: Build playground WASM
143+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
107144
run: |
108145
source "${EMSDK}/emsdk_env.sh"
109146
npm run build:wasm
110147
working-directory: playground
111148

149+
- name: Save playground WASM cache
150+
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
151+
uses: actions/cache/save@v4
152+
continue-on-error: true
153+
with:
154+
path: playground/public/wasm
155+
key: ${{ steps.playground-wasm-cache.outputs.cache-primary-key }}
156+
112157
- name: Install dependencies
113158
run: npm ci
114159
working-directory: docs

0 commit comments

Comments
 (0)