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..5e4928ec19ca 100644 --- a/crates/biome_wasm/Cargo.toml +++ b/crates/biome_wasm/Cargo.toml @@ -28,7 +28,8 @@ 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"] } +# 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 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-.+(?