From d568b593fceebfcc0a1ca98a60250ae7cdc9a921 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 26 Nov 2025 09:13:26 +0000 Subject: [PATCH 1/2] ci: bundle WASM manually --- .github/workflows/beta.yml | 17 ++++-- .github/workflows/beta_js_api.yml | 10 +++- .github/workflows/preview.yml | 19 +++++-- .github/workflows/pull_request_node.yml | 6 +- .github/workflows/release.yml | 46 +++++++++------ .github/workflows/repository_dispatch.yml | 27 +++++---- CONTRIBUTING.md | 4 +- crates/biome_wasm/Cargo.toml | 49 ++++++++-------- justfile | 69 ++++++++++++++++++++++- packages/@biomejs/js-api/package.json | 12 ++-- packages/@biomejs/wasm-bundler/.gitignore | 5 ++ packages/@biomejs/wasm-nodejs/.gitignore | 4 ++ packages/@biomejs/wasm-web/.gitignore | 4 ++ rust-toolchain.toml | 1 + 14 files changed, 197 insertions(+), 76 deletions(-) create mode 100644 packages/@biomejs/wasm-bundler/.gitignore create mode 100644 packages/@biomejs/wasm-nodejs/.gitignore create mode 100644 packages/@biomejs/wasm-web/.gitignore diff --git a/.github/workflows/beta.yml b/.github/workflows/beta.yml index 10398e1cf651..c3a6d60e28b4 100644 --- a/.github/workflows/beta.yml +++ b/.github/workflows/beta.yml @@ -171,15 +171,22 @@ jobs: - name: Checkout repository uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + - name: Install just + uses: extractions/setup-just@v2 + + - name: Install toolchain + uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2 + with: + bins: wasm-bindgen-cli@0.2.105, wasm-opt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Build WASM module for bundlers - run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-bundler --target bundler --release --scope biomejs crates/biome_wasm + run: just build-wasm-bundler - name: Build WASM module for node.js - run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-nodejs --target nodejs --release --scope biomejs crates/biome_wasm + run: just build-wasm-node - name: Build WASM module for the web - run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-web --target web --release --scope biomejs crates/biome_wasm + run: just build-wasm-web - name: Upload WASM artifact uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 diff --git a/.github/workflows/beta_js_api.yml b/.github/workflows/beta_js_api.yml index ca6b26fa5c2e..0feafcb2e086 100644 --- a/.github/workflows/beta_js_api.yml +++ b/.github/workflows/beta_js_api.yml @@ -42,8 +42,14 @@ jobs: with: node-version: 24.11.1 - - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + - name: Install just + uses: extractions/setup-just@v2 + + - name: Install wasm-bindgen-cli + run: cargo install wasm-bindgen-cli --version 0.2.105 + + - name: Install wasm-tools + run: cargo install wasm-tools - name: Cache pnpm modules uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 6ce3eec9c28e..f03f5e265575 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -158,20 +158,27 @@ jobs: matrix: include: - target: wasm-bundler - wasm-pack-target: bundler + just-recipe: build-wasm-bundler - target: wasm-nodejs - wasm-pack-target: nodejs + just-recipe: build-wasm-node - target: wasm-web - wasm-pack-target: web + just-recipe: build-wasm-web steps: - name: Checkout repository uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + - name: Install just + uses: extractions/setup-just@v2 + + - name: Install toolchain + uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2 + with: + bins: wasm-bindgen-cli@0.2.105, wasm-opt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Build WASM module ${{ matrix.target }} - run: wasm-pack build --out-dir ../../packages/@biomejs/${{ matrix.target }} --target ${{ matrix.wasm-pack-target }} --release --scope biomejs crates/biome_wasm + run: just ${{ matrix.just-recipe }} - name: Upload WASM artifact uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 diff --git a/.github/workflows/pull_request_node.yml b/.github/workflows/pull_request_node.yml index e50ebc825432..48297c085ce3 100644 --- a/.github/workflows/pull_request_node.yml +++ b/.github/workflows/pull_request_node.yml @@ -36,6 +36,7 @@ jobs: with: cache-target: release cache-base: main + bins: wasm-bindgen-cli@0.2.105, wasm-opt env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Build main binary @@ -52,8 +53,9 @@ jobs: restore-keys: | ${{ runner.os }}- - uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 - - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + + - name: Install just + uses: extractions/setup-just@v2 - name: Build TypeScript code # We use the `*-dev` builds below because release builds take very long. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 013aa9467494..86c0494cc878 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -243,19 +243,31 @@ jobs: runs-on: depot-ubuntu-24.04-arm-16 needs: version if: needs.version.outputs.cli-version + strategy: + matrix: + include: + - target: wasm-bundler + just-recipe: build-wasm-bundler + - target: wasm-nodejs + just-recipe: build-wasm-node + - target: wasm-web + just-recipe: build-wasm-web steps: - name: Checkout repository uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + - name: Install just + uses: extractions/setup-just@v2 + + - name: Install toolchain + uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2 + with: + bins: wasm-bindgen-cli@0.2.105, wasm-opt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Build WASM module for bundlers - run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-bundler --target bundler --release --scope biomejs crates/biome_wasm - - name: Build WASM module for node.js - run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-nodejs --target nodejs --release --scope biomejs crates/biome_wasm - - name: Build WASM module for the web - run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-web --target web --release --scope biomejs crates/biome_wasm + - name: Build WASM module ${{ matrix.target }} + run: just ${{ matrix.just-recipe }} - name: Upload WASM artifact uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 @@ -283,8 +295,15 @@ jobs: with: node-version: 24.11.1 - - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + - name: Install just + uses: extractions/setup-just@v2 + + - name: Install toolchain + uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2 + with: + bins: wasm-bindgen-cli@0.2.105, wasm-opt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Cache pnpm modules uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 @@ -358,13 +377,6 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile - # The WASM job updates the package.json file, because of wasm-pack, which we need to restore - - name: Restore packages changes - run: | - git restore packages/@biomejs/wasm-bundler/package.json - git restore packages/@biomejs/wasm-nodejs/package.json - git restore packages/@biomejs/wasm-web/package.json - - name: Generate npm packages run: node packages/@biomejs/biome/scripts/generate-packages.mjs diff --git a/.github/workflows/repository_dispatch.yml b/.github/workflows/repository_dispatch.yml index 6b40e8e75470..d2d804887b02 100644 --- a/.github/workflows/repository_dispatch.yml +++ b/.github/workflows/repository_dispatch.yml @@ -13,7 +13,7 @@ permissions: env: BIOME_WEBSITE_REPO: biomejs/website BIOME_PUSH_ON_MAIN_EVENT_TYPE: biome-push-on-main-event - WASM_PACK_CACHE_KEY: wasm-pack-cache + WASM_CACHE_KEY: wasm-cache concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -27,38 +27,45 @@ jobs: - name: Checkout repository uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - - name: Warm up wasm-pack cache + - name: Warm up wasm cache id: cache-restore uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: | ./target ./packages/@biomejs/wasm-web - key: ${{ env.WASM_PACK_CACHE_KEY }} + key: ${{ env.WASM_CACHE_KEY }} - - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + - name: Install just + uses: extractions/setup-just@v2 + + - name: Install toolchain + uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2 + with: + bins: wasm-bindgen-cli@0.2.105, wasm-opt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Build WASM module for the web - run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-web --target web --profiling --scope biomejs crates/biome_wasm + run: just build-wasm-web # https://github.com/actions/cache/issues/342 - - name: Clear old wasm-pack cache + - name: Clear old wasm cache if: ${{ steps.cache-restore.outputs.cache-hit }} run: | gh extension install actions/gh-actions-cache - gh actions-cache delete ${{ env.WASM_PACK_CACHE_KEY }} --confirm + gh actions-cache delete ${{ env.WASM_CACHE_KEY }} --confirm env: GH_TOKEN: ${{ github.token }} continue-on-error: true - - name: Save new wasm-pack cache + - name: Save new wasm cache uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: | ./target ./packages/@biomejs/wasm-web - key: ${{ env.WASM_PACK_CACHE_KEY }} + key: ${{ env.WASM_CACHE_KEY }} - name: Install pnpm # workaround for the issue https://github.com/actions/setup-node/issues/1222 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c2795534d903..ef6faf2babd4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -131,7 +131,7 @@ This command will install: - `cargo-binstall`, to install binary extensions for `cargo`. - `cargo-insta`, a `cargo` extension to manage snapshot testing inside the repository. - `taplo-cli`, a small tool for formatting TOML files. -- `wasm-pack` and `wasm-tools` for managing the WASM build of Biome. +- `wasm-bindgen-cli` and `wasm-opt` for managing the WASM build of Biome. 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) @@ -343,7 +343,7 @@ The npm module `packages/@biomejs/biome` contains Biome's Node.js API that suppo For testing and developing, you need to build these packages, following the steps: 1. install pnpm via [corepack](https://nodejs.org/api/corepack.html) by running `corepack enable`; -2. install [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) globally; +2. install `wasm-bindgen-cli` and `wasm-opt` by running `just install-tools`; 3. run `pnpm --filter "@biomejs/backend-jsonrpc" build`; 4. run the `pnpm --filter "@biomejs/js-api" build:wasm-dev` and `pnpm --filter "@biomejs/js-api" build` commands; 5. run `pnpm i --filter "@biomejs/js-api" --frozen-lockfile` to link the WebAssembly bindings and the JSON-RPC bindings diff --git a/crates/biome_wasm/Cargo.toml b/crates/biome_wasm/Cargo.toml index b0b780ee33e6..2b847457d192 100644 --- a/crates/biome_wasm/Cargo.toml +++ b/crates/biome_wasm/Cargo.toml @@ -1,15 +1,15 @@ [package] -authors = ["Biome Developers and Contributors"] -categories = ["development-tools", "web-programming"] +authors = ["Biome Developers and Contributors"] +categories = ["development-tools", "web-programming"] description = "WebAssembly bindings to the Biome workspace API" -edition = "2024" -homepage = "https://biomejs.dev/" -keywords = ["parser", "linter", "formatter", "wasm"] -license = "MIT OR Apache-2.0" -name = "biome_wasm" -publish = false -repository = "https://github.com/biomejs/biome" -version = "1.9.4" +edition = "2024" +homepage = "https://biomejs.dev/" +keywords = ["parser", "linter", "formatter", "wasm"] +license = "MIT OR Apache-2.0" +name = "biome_wasm" +publish = false +repository = "https://github.com/biomejs/biome" +version = "1.9.4" [lib] @@ -19,16 +19,17 @@ crate-type = ["cdylib", "rlib"] default = ["console_error_panic_hook"] [dependencies] -biome_console = { workspace = true } -biome_diagnostics = { workspace = true } -biome_fs = { workspace = true } -biome_service = { workspace = true, features = ["schema"] } -camino = { workspace = true } -js-sys = "0.3.82" -serde = { workspace = true } +biome_console = { workspace = true } +biome_diagnostics = { workspace = true } +biome_fs = { workspace = true } +biome_service = { workspace = true, features = ["schema"] } +camino = { workspace = true } +js-sys = "0.3.82" +serde = { workspace = true } serde-wasm-bindgen = "0.6.5" -serde_json = { workspace = true } -wasm-bindgen = { version = "0.2.105", features = ["serde-serialize"] } +serde_json = { workspace = true } +# IMPORTANT: if you update this package, you must update justfile and workflows so we install the same CLI version +wasm-bindgen = { version = "0.2.105", features = ["serde-serialize"] } # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires @@ -38,12 +39,12 @@ console_error_panic_hook = { version = "0.1.7", optional = true } [build-dependencies] -biome_js_factory = { workspace = true } +biome_js_factory = { workspace = true } biome_js_formatter = { workspace = true } -biome_rowan = { workspace = true } -biome_service = { workspace = true, features = ["schema"] } -quote = "1.0.14" -schemars = { workspace = true } +biome_rowan = { workspace = true } +biome_service = { workspace = true, features = ["schema"] } +quote = "1.0.14" +schemars = { workspace = true } [lints] workspace = true diff --git a/justfile b/justfile index 246a0146b724..872ad5c1d4ac 100644 --- a/justfile +++ b/justfile @@ -10,12 +10,14 @@ alias qt := test-quick # Installs the tools needed to develop install-tools: cargo install cargo-binstall - cargo binstall cargo-insta taplo-cli wasm-pack wasm-tools + cargo binstall cargo-insta taplo-cli wasm-opt + cargo binstall wasm-bindgen-cli --version 0.2.105 # Upgrades the tools needed to develop upgrade-tools: cargo install cargo-binstall --force - cargo binstall cargo-insta taplo-cli wasm-pack wasm-tools --force + cargo binstall cargo-insta taplo-cli wasm-opt --force + cargo binstall wasm-bindgen-cli --version 0.2.105 --force # Generate all files across crates and tools. You rarely want to use it locally. gen-all: @@ -69,6 +71,69 @@ gen-tw: pnpm build pnpm execute +# Build WASM for bundler target (development) +build-wasm-bundler-dev: + cargo build --lib --target wasm32-unknown-unknown -p biome_wasm + wasm-bindgen target/wasm32-unknown-unknown/debug/biome_wasm.wasm \ + --out-dir packages/@biomejs/wasm-bundler \ + --target bundler \ + --typescript + +# Build WASM for bundler target (release) +build-wasm-bundler: + cargo build --lib --target wasm32-unknown-unknown --release -p biome_wasm + wasm-bindgen target/wasm32-unknown-unknown/release/biome_wasm.wasm \ + --out-dir packages/@biomejs/wasm-bundler \ + --no-demangle \ + --target bundler \ + --typescript + wasm-opt packages/@biomejs/wasm-bundler/biome_wasm_bg.wasm \ + -o packages/@biomejs/wasm-bundler/biome_wasm_bg.wasm \ + -Os \ + -g + +# Build WASM for Node.js target (development) +build-wasm-node-dev: + cargo build --lib --target wasm32-unknown-unknown -p biome_wasm + wasm-bindgen target/wasm32-unknown-unknown/debug/biome_wasm.wasm \ + --out-dir packages/@biomejs/wasm-nodejs \ + --target nodejs \ + --typescript + +# Build WASM for Node.js target (release) +build-wasm-node: + cargo build --lib --target wasm32-unknown-unknown --release -p biome_wasm + wasm-bindgen target/wasm32-unknown-unknown/release/biome_wasm.wasm \ + --out-dir packages/@biomejs/wasm-nodejs \ + --no-demangle \ + --target nodejs \ + --typescript + wasm-opt packages/@biomejs/wasm-nodejs/biome_wasm_bg.wasm \ + -o packages/@biomejs/wasm-nodejs/biome_wasm_bg.wasm \ + -Os \ + -g + +# Build WASM for web target (development) +build-wasm-web-dev: + cargo build --lib --target wasm32-unknown-unknown -p biome_wasm + wasm-bindgen target/wasm32-unknown-unknown/debug/biome_wasm.wasm \ + --out-dir packages/@biomejs/wasm-web \ + --target web \ + --typescript + +# Build WASM for web target (release) +build-wasm-web: + cargo build --lib --target wasm32-unknown-unknown --release -p biome_wasm + wasm-bindgen target/wasm32-unknown-unknown/release/biome_wasm.wasm \ + --out-dir packages/@biomejs/wasm-web \ + --no-demangle \ + --target web \ + --typescript + wasm-opt packages/@biomejs/wasm-web/biome_wasm_bg.wasm \ + -o packages/@biomejs/wasm-web/biome_wasm_bg.wasm \ + -Os \ + -g + # Generates the code of the grammars available in Biome gen-grammar *args='': cargo run -p xtask_codegen -- grammar {{args}} diff --git a/packages/@biomejs/js-api/package.json b/packages/@biomejs/js-api/package.json index 8aec12d7f166..54e5a2660396 100644 --- a/packages/@biomejs/js-api/package.json +++ b/packages/@biomejs/js-api/package.json @@ -11,12 +11,12 @@ "check:apply": "cargo biome-cli-dev check --apply-unsafe .", "build:wasm-dev": "pnpm run \"/^build:wasm-.+-dev$/\"", "build:wasm": "pnpm run \"/^build:wasm-.+(? Date: Thu, 27 Nov 2025 11:44:47 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- crates/biome_wasm/Cargo.toml | 46 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/crates/biome_wasm/Cargo.toml b/crates/biome_wasm/Cargo.toml index 2b847457d192..5e4928ec19ca 100644 --- a/crates/biome_wasm/Cargo.toml +++ b/crates/biome_wasm/Cargo.toml @@ -1,15 +1,15 @@ [package] -authors = ["Biome Developers and Contributors"] -categories = ["development-tools", "web-programming"] +authors = ["Biome Developers and Contributors"] +categories = ["development-tools", "web-programming"] description = "WebAssembly bindings to the Biome workspace API" -edition = "2024" -homepage = "https://biomejs.dev/" -keywords = ["parser", "linter", "formatter", "wasm"] -license = "MIT OR Apache-2.0" -name = "biome_wasm" -publish = false -repository = "https://github.com/biomejs/biome" -version = "1.9.4" +edition = "2024" +homepage = "https://biomejs.dev/" +keywords = ["parser", "linter", "formatter", "wasm"] +license = "MIT OR Apache-2.0" +name = "biome_wasm" +publish = false +repository = "https://github.com/biomejs/biome" +version = "1.9.4" [lib] @@ -19,15 +19,15 @@ crate-type = ["cdylib", "rlib"] default = ["console_error_panic_hook"] [dependencies] -biome_console = { workspace = true } -biome_diagnostics = { workspace = true } -biome_fs = { workspace = true } -biome_service = { workspace = true, features = ["schema"] } -camino = { workspace = true } -js-sys = "0.3.82" -serde = { workspace = true } +biome_console = { workspace = true } +biome_diagnostics = { workspace = true } +biome_fs = { workspace = true } +biome_service = { workspace = true, features = ["schema"] } +camino = { workspace = true } +js-sys = "0.3.82" +serde = { workspace = true } serde-wasm-bindgen = "0.6.5" -serde_json = { workspace = true } +serde_json = { workspace = true } # IMPORTANT: if you update this package, you must update justfile and workflows so we install the same CLI version wasm-bindgen = { version = "0.2.105", features = ["serde-serialize"] } @@ -39,12 +39,12 @@ console_error_panic_hook = { version = "0.1.7", optional = true } [build-dependencies] -biome_js_factory = { workspace = true } +biome_js_factory = { workspace = true } biome_js_formatter = { workspace = true } -biome_rowan = { workspace = true } -biome_service = { workspace = true, features = ["schema"] } -quote = "1.0.14" -schemars = { workspace = true } +biome_rowan = { workspace = true } +biome_service = { workspace = true, features = ["schema"] } +quote = "1.0.14" +schemars = { workspace = true } [lints] workspace = true