Skip to content

Commit 93182ea

Browse files
ematipicodyc3
andauthored
ci: bundle WASM manually (#8271)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: dyc3 <[email protected]>
1 parent 9d3ef10 commit 93182ea

14 files changed

Lines changed: 174 additions & 53 deletions

File tree

.github/workflows/beta.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,22 @@ jobs:
171171
- name: Checkout repository
172172
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
173173

174-
- name: Install wasm-pack
175-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
174+
- name: Install just
175+
uses: extractions/setup-just@v2
176+
177+
- name: Install toolchain
178+
uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2
179+
with:
180+
bins: [email protected], wasm-opt
181+
env:
182+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176183

177184
- name: Build WASM module for bundlers
178-
run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-bundler --target bundler --release --scope biomejs crates/biome_wasm
185+
run: just build-wasm-bundler
179186
- name: Build WASM module for node.js
180-
run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-nodejs --target nodejs --release --scope biomejs crates/biome_wasm
187+
run: just build-wasm-node
181188
- name: Build WASM module for the web
182-
run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-web --target web --release --scope biomejs crates/biome_wasm
189+
run: just build-wasm-web
183190

184191
- name: Upload WASM artifact
185192
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0

.github/workflows/beta_js_api.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ jobs:
4242
with:
4343
node-version: 24.11.1
4444

45-
- name: Install wasm-pack
46-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
45+
- name: Install just
46+
uses: extractions/setup-just@v2
47+
48+
- name: Install wasm-bindgen-cli
49+
run: cargo install wasm-bindgen-cli --version 0.2.105
50+
51+
- name: Install wasm-tools
52+
run: cargo install wasm-tools
4753

4854
- name: Cache pnpm modules
4955
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0

.github/workflows/preview.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,27 @@ jobs:
158158
matrix:
159159
include:
160160
- target: wasm-bundler
161-
wasm-pack-target: bundler
161+
just-recipe: build-wasm-bundler
162162
- target: wasm-nodejs
163-
wasm-pack-target: nodejs
163+
just-recipe: build-wasm-node
164164
- target: wasm-web
165-
wasm-pack-target: web
165+
just-recipe: build-wasm-web
166166
steps:
167167
- name: Checkout repository
168168
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
169169

170-
- name: Install wasm-pack
171-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
170+
- name: Install just
171+
uses: extractions/setup-just@v2
172+
173+
- name: Install toolchain
174+
uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2
175+
with:
176+
bins: [email protected], wasm-opt
177+
env:
178+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
172179

173180
- name: Build WASM module ${{ matrix.target }}
174-
run: wasm-pack build --out-dir ../../packages/@biomejs/${{ matrix.target }} --target ${{ matrix.wasm-pack-target }} --release --scope biomejs crates/biome_wasm
181+
run: just ${{ matrix.just-recipe }}
175182

176183
- name: Upload WASM artifact
177184
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0

.github/workflows/pull_request_node.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
with:
3737
cache-target: release
3838
cache-base: main
39+
bins: [email protected], wasm-opt
3940
env:
4041
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4142
- name: Build main binary
@@ -52,8 +53,9 @@ jobs:
5253
restore-keys: |
5354
${{ runner.os }}-
5455
- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
55-
- name: Install wasm-pack
56-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
56+
57+
- name: Install just
58+
uses: extractions/setup-just@v2
5759

5860
- name: Build TypeScript code
5961
# We use the `*-dev` builds below because release builds take very long.

.github/workflows/release.yml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,31 @@ jobs:
243243
runs-on: depot-ubuntu-24.04-arm-16
244244
needs: version
245245
if: needs.version.outputs.cli-version
246+
strategy:
247+
matrix:
248+
include:
249+
- target: wasm-bundler
250+
just-recipe: build-wasm-bundler
251+
- target: wasm-nodejs
252+
just-recipe: build-wasm-node
253+
- target: wasm-web
254+
just-recipe: build-wasm-web
246255
steps:
247256
- name: Checkout repository
248257
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
249258

250-
- name: Install wasm-pack
251-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
259+
- name: Install just
260+
uses: extractions/setup-just@v2
261+
262+
- name: Install toolchain
263+
uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2
264+
with:
265+
bins: [email protected], wasm-opt
266+
env:
267+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
252268

253-
- name: Build WASM module for bundlers
254-
run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-bundler --target bundler --release --scope biomejs crates/biome_wasm
255-
- name: Build WASM module for node.js
256-
run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-nodejs --target nodejs --release --scope biomejs crates/biome_wasm
257-
- name: Build WASM module for the web
258-
run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-web --target web --release --scope biomejs crates/biome_wasm
269+
- name: Build WASM module ${{ matrix.target }}
270+
run: just ${{ matrix.just-recipe }}
259271

260272
- name: Upload WASM artifact
261273
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
@@ -283,8 +295,15 @@ jobs:
283295
with:
284296
node-version: 24.11.1
285297

286-
- name: Install wasm-pack
287-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
298+
- name: Install just
299+
uses: extractions/setup-just@v2
300+
301+
- name: Install toolchain
302+
uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2
303+
with:
304+
bins: [email protected], wasm-opt
305+
env:
306+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
288307

289308
- name: Cache pnpm modules
290309
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
@@ -358,13 +377,6 @@ jobs:
358377
- name: Install dependencies
359378
run: pnpm install --frozen-lockfile
360379

361-
# The WASM job updates the package.json file, because of wasm-pack, which we need to restore
362-
- name: Restore packages changes
363-
run: |
364-
git restore packages/@biomejs/wasm-bundler/package.json
365-
git restore packages/@biomejs/wasm-nodejs/package.json
366-
git restore packages/@biomejs/wasm-web/package.json
367-
368380
- name: Generate npm packages
369381
run: node packages/@biomejs/biome/scripts/generate-packages.mjs
370382

.github/workflows/repository_dispatch.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ permissions:
1313
env:
1414
BIOME_WEBSITE_REPO: biomejs/website
1515
BIOME_PUSH_ON_MAIN_EVENT_TYPE: biome-push-on-main-event
16-
WASM_PACK_CACHE_KEY: wasm-pack-cache
16+
WASM_CACHE_KEY: wasm-cache
1717

1818
concurrency:
1919
group: ${{ github.workflow }}-${{ github.ref }}
@@ -27,38 +27,45 @@ jobs:
2727
- name: Checkout repository
2828
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
2929

30-
- name: Warm up wasm-pack cache
30+
- name: Warm up wasm cache
3131
id: cache-restore
3232
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
3333
with:
3434
path: |
3535
./target
3636
./packages/@biomejs/wasm-web
37-
key: ${{ env.WASM_PACK_CACHE_KEY }}
37+
key: ${{ env.WASM_CACHE_KEY }}
3838

39-
- name: Install wasm-pack
40-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
39+
- name: Install just
40+
uses: extractions/setup-just@v2
41+
42+
- name: Install toolchain
43+
uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2
44+
with:
45+
bins: [email protected], wasm-opt
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4148

4249
- name: Build WASM module for the web
43-
run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-web --target web --profiling --scope biomejs crates/biome_wasm
50+
run: just build-wasm-web
4451

4552
# https://github.com/actions/cache/issues/342
46-
- name: Clear old wasm-pack cache
53+
- name: Clear old wasm cache
4754
if: ${{ steps.cache-restore.outputs.cache-hit }}
4855
run: |
4956
gh extension install actions/gh-actions-cache
50-
gh actions-cache delete ${{ env.WASM_PACK_CACHE_KEY }} --confirm
57+
gh actions-cache delete ${{ env.WASM_CACHE_KEY }} --confirm
5158
env:
5259
GH_TOKEN: ${{ github.token }}
5360
continue-on-error: true
5461

55-
- name: Save new wasm-pack cache
62+
- name: Save new wasm cache
5663
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
5764
with:
5865
path: |
5966
./target
6067
./packages/@biomejs/wasm-web
61-
key: ${{ env.WASM_PACK_CACHE_KEY }}
68+
key: ${{ env.WASM_CACHE_KEY }}
6269

6370
- name: Install pnpm
6471
# workaround for the issue https://github.com/actions/setup-node/issues/1222

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ This command will install:
131131
- `cargo-binstall`, to install binary extensions for `cargo`.
132132
- `cargo-insta`, a `cargo` extension to manage snapshot testing inside the repository.
133133
- `taplo-cli`, a small tool for formatting TOML files.
134-
- `wasm-pack` and `wasm-tools` for managing the WASM build of Biome.
134+
- `wasm-bindgen-cli` and `wasm-opt` for managing the WASM build of Biome.
135135

136136
You'll also need to have `pnpm` installed on your machine, and run `pnpm install` from the root of the repository. `pnpm` is needed to [create changesets](#create-a-changeset)
137137

@@ -343,7 +343,7 @@ The npm module `packages/@biomejs/biome` contains Biome's Node.js API that suppo
343343
For testing and developing, you need to build these packages, following the steps:
344344

345345
1. install pnpm via [corepack](https://nodejs.org/api/corepack.html) by running `corepack enable`;
346-
2. install [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) globally;
346+
2. install `wasm-bindgen-cli` and `wasm-opt` by running `just install-tools`;
347347
3. run `pnpm --filter "@biomejs/backend-jsonrpc" build`;
348348
4. run the `pnpm --filter "@biomejs/js-api" build:wasm-dev` and `pnpm --filter "@biomejs/js-api" build` commands;
349349
5. run `pnpm i --filter "@biomejs/js-api" --frozen-lockfile` to link the WebAssembly bindings and the JSON-RPC bindings

crates/biome_wasm/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ js-sys = "0.3.82"
2828
serde = { workspace = true }
2929
serde-wasm-bindgen = "0.6.5"
3030
serde_json = { workspace = true }
31-
wasm-bindgen = { version = "0.2.105", features = ["serde-serialize"] }
31+
# IMPORTANT: if you update this package, you must update justfile and workflows so we install the same CLI version
32+
wasm-bindgen = { version = "0.2.105", features = ["serde-serialize"] }
3233

3334
# The `console_error_panic_hook` crate provides better debugging of panics by
3435
# logging them with `console.error`. This is great for development, but requires

justfile

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ alias qt := test-quick
1010
# Installs the tools needed to develop
1111
install-tools:
1212
cargo install cargo-binstall
13-
cargo binstall cargo-insta taplo-cli wasm-pack wasm-tools
13+
cargo binstall cargo-insta taplo-cli wasm-opt
14+
cargo binstall wasm-bindgen-cli --version 0.2.105
1415

1516
# Upgrades the tools needed to develop
1617
upgrade-tools:
1718
cargo install cargo-binstall --force
18-
cargo binstall cargo-insta taplo-cli wasm-pack wasm-tools --force
19+
cargo binstall cargo-insta taplo-cli wasm-opt --force
20+
cargo binstall wasm-bindgen-cli --version 0.2.105 --force
1921

2022
# Generate all files across crates and tools. You rarely want to use it locally.
2123
gen-all:
@@ -69,6 +71,69 @@ gen-tw:
6971
pnpm build
7072
pnpm execute
7173

74+
# Build WASM for bundler target (development)
75+
build-wasm-bundler-dev:
76+
cargo build --lib --target wasm32-unknown-unknown -p biome_wasm
77+
wasm-bindgen target/wasm32-unknown-unknown/debug/biome_wasm.wasm \
78+
--out-dir packages/@biomejs/wasm-bundler \
79+
--target bundler \
80+
--typescript
81+
82+
# Build WASM for bundler target (release)
83+
build-wasm-bundler:
84+
cargo build --lib --target wasm32-unknown-unknown --release -p biome_wasm
85+
wasm-bindgen target/wasm32-unknown-unknown/release/biome_wasm.wasm \
86+
--out-dir packages/@biomejs/wasm-bundler \
87+
--no-demangle \
88+
--target bundler \
89+
--typescript
90+
wasm-opt packages/@biomejs/wasm-bundler/biome_wasm_bg.wasm \
91+
-o packages/@biomejs/wasm-bundler/biome_wasm_bg.wasm \
92+
-Os \
93+
-g
94+
95+
# Build WASM for Node.js target (development)
96+
build-wasm-node-dev:
97+
cargo build --lib --target wasm32-unknown-unknown -p biome_wasm
98+
wasm-bindgen target/wasm32-unknown-unknown/debug/biome_wasm.wasm \
99+
--out-dir packages/@biomejs/wasm-nodejs \
100+
--target nodejs \
101+
--typescript
102+
103+
# Build WASM for Node.js target (release)
104+
build-wasm-node:
105+
cargo build --lib --target wasm32-unknown-unknown --release -p biome_wasm
106+
wasm-bindgen target/wasm32-unknown-unknown/release/biome_wasm.wasm \
107+
--out-dir packages/@biomejs/wasm-nodejs \
108+
--no-demangle \
109+
--target nodejs \
110+
--typescript
111+
wasm-opt packages/@biomejs/wasm-nodejs/biome_wasm_bg.wasm \
112+
-o packages/@biomejs/wasm-nodejs/biome_wasm_bg.wasm \
113+
-Os \
114+
-g
115+
116+
# Build WASM for web target (development)
117+
build-wasm-web-dev:
118+
cargo build --lib --target wasm32-unknown-unknown -p biome_wasm
119+
wasm-bindgen target/wasm32-unknown-unknown/debug/biome_wasm.wasm \
120+
--out-dir packages/@biomejs/wasm-web \
121+
--target web \
122+
--typescript
123+
124+
# Build WASM for web target (release)
125+
build-wasm-web:
126+
cargo build --lib --target wasm32-unknown-unknown --release -p biome_wasm
127+
wasm-bindgen target/wasm32-unknown-unknown/release/biome_wasm.wasm \
128+
--out-dir packages/@biomejs/wasm-web \
129+
--no-demangle \
130+
--target web \
131+
--typescript
132+
wasm-opt packages/@biomejs/wasm-web/biome_wasm_bg.wasm \
133+
-o packages/@biomejs/wasm-web/biome_wasm_bg.wasm \
134+
-Os \
135+
-g
136+
72137
# Generates the code of the grammars available in Biome
73138
gen-grammar *args='':
74139
cargo run -p xtask_codegen -- grammar {{args}}

packages/@biomejs/js-api/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"check:apply": "cargo biome-cli-dev check --apply-unsafe .",
1212
"build:wasm-dev": "pnpm run \"/^build:wasm-.+-dev$/\"",
1313
"build:wasm": "pnpm run \"/^build:wasm-.+(?<!dev)$/\"",
14-
"build:wasm-bundler-dev": "wasm-pack build --out-dir ../../packages/@biomejs/wasm-bundler --target bundler --dev --scope biomejs ../../../crates/biome_wasm",
15-
"build:wasm-bundler": "wasm-pack build --out-dir ../../packages/@biomejs/wasm-bundler --target bundler --release --scope biomejs ../../../crates/biome_wasm",
16-
"build:wasm-node-dev": "wasm-pack build --out-dir ../../packages/@biomejs/wasm-nodejs --target nodejs --dev --scope biomejs ../../../crates/biome_wasm",
17-
"build:wasm-node": "wasm-pack build --out-dir ../../packages/@biomejs/wasm-nodejs --target nodejs --release --scope biomejs ../../../crates/biome_wasm",
18-
"build:wasm-web-dev": "wasm-pack build --out-dir ../../packages/@biomejs/wasm-web --target web --dev --scope biomejs ../../../crates/biome_wasm",
19-
"build:wasm-web": "wasm-pack build --out-dir ../../packages/@biomejs/wasm-web --target web --release --scope biomejs ../../../crates/biome_wasm",
14+
"build:wasm-bundler-dev": "just build-wasm-bundler-dev",
15+
"build:wasm-bundler": "just build-wasm-bundler",
16+
"build:wasm-node-dev": "just build-wasm-node-dev",
17+
"build:wasm-node": "just build-wasm-node",
18+
"build:wasm-web-dev": "just build-wasm-web-dev",
19+
"build:wasm-web": "just build-wasm-web",
2020
"test": "vitest",
2121
"test:ci": "vitest run",
2222
"build": "tsc"

0 commit comments

Comments
 (0)