Skip to content

WASM Build

Skill Lab uses @ast-grep/wasm for cross-platform code analysis. Because this package is not yet published to npm, it is built from source and placed in vendor/ast-grep-wasm/ at the repo root.

The vendor/ directory is gitignored and must be regenerated by running:

bash
deno task setup

This must be done before running check, test, or build.


Prerequisites

Install wasm-pack:

bash
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

Make sure the wasm32-unknown-unknown Rust target is installed:

bash
rustup target add wasm32-unknown-unknown

What deno task setup does

The setup script is scripts/setup_wasm.ts. It:

  1. Clones the ast-grep repository (no-checkout, shallow) into /tmp/ast-grep-wasm-build
  2. Checks out the pinned commit 3392cb5b0b53887db618866d95a41893c1575cb6 from PR #2484
  3. Runs wasm-pack build --target nodejs --out-dir pkg in crates/wasm/
  4. Copies ast_grep_wasm_bg.wasm and ast_grep_wasm.js to vendor/ast-grep-wasm/
  5. Writes a minimal package.json to vendor/ast-grep-wasm/ for Deno module resolution

The build typically takes 2–5 minutes on first run (Rust compilation). Subsequent runs are fast if the Cargo cache (~/.cargo/registry) is warm.


Version pinning

The pinned commit (3392cb5b) corresponds to a specific point on the wasm branch. When updating to a newer commit:

  1. Update PINNED_COMMIT in scripts/setup_wasm.ts
  2. Verify web-tree-sitter ABI compatibility (see below)
  3. Re-run deno task setup

web-tree-sitter version pinning

web-tree-sitter is pinned to exact version 0.25.4 in packages/analyzer/deno.json. This is intentional — grammar .wasm files are compiled by the tree-sitter CLI against a specific WASM ABI. Mixing a grammar file compiled for one ABI version with a different web-tree-sitter runtime version causes silent parse failures (no error is thrown; the parsed tree is silently wrong).

Grammar .wasm files used by Skill Lab (from packages/analyzer/treesitter/registry.ts):

LanguageVersionSource
bash0.25.1tree-sitter/tree-sitter-bash
javascript0.25.0tree-sitter/tree-sitter-javascript
python0.25.0tree-sitter/tree-sitter-python
typescript / tsx0.23.2tree-sitter/tree-sitter-typescript
markdown0.5.2tree-sitter-grammars/tree-sitter-markdown
markdown-inline0.5.2tree-sitter-grammars/tree-sitter-markdown

If you update web-tree-sitter, you must also update all grammar URLs and verify ABI compatibility with the new runtime version.


Grammar file size

Each grammar .wasm file is approximately 1.3–1.4 MB — comparable in size to a single platform-specific .so file. The previous approach bundled four platform .so files per language into each release archive (~5 MB per language). With WASM, a single file serves all platforms, and grammars are downloaded on first use rather than bundled into the release archive.

Grammar files are cached locally in the XDG cache directory.


CI

The GitHub Actions workflow (.github/workflows/cli.yml) runs deno task setup before every build and test job. Rust build artifacts are cached using actions/cache keyed on Cargo.lock.