Skip to main content
The Query Compiler can be compiled to WebAssembly for browser and edge runtime environments (Cloudflare Workers, Vercel Edge Functions, etc.).

Build Script

The build.sh script handles the entire WASM build process:

Parameters

  • version: NPM package version (e.g., 0.0.0)
  • output_folder: Where to place the built artifacts (defaults to query-compiler/query-compiler-wasm/pkg)
  • optimization_mode: Either fast or small

Example Usage

Makefile Targets

The root Makefile provides convenient targets:
Build both optimization modes:
Equivalent to:
From the Makefile:

Build Process

The build happens in multiple stages:
1

Compile to WASM

Compile the Rust code to WebAssembly:
This runs for each provider: postgresql, mysql, sqlite, sqlserver, cockroachdb
2

Generate JS Bindings

Use wasm-bindgen to create TypeScript/JavaScript bindings:
Generates:
  • query_compiler_fast.js
  • query_compiler_fast.d.ts
  • query_compiler_fast_bg.wasm
3

Optimize with wasm-opt

Apply aggressive optimizations:
4

Generate package.json

Create an NPM package descriptor:
5

Report Sizes

Display the final sizes:

wasm-opt Flags

The script uses extensive optimization flags: From query-compiler-wasm/build.sh:

Build Profiles

The build can use different Cargo profiles:
Default when building locally:
  • Faster compilation
  • Larger artifacts
  • Skips wasm-opt entirely

Cargo Configuration

From query-compiler-wasm/Cargo.toml:

Output Structure

After building, the output directory contains:
Each provider gets its own subdirectory with separate WASM builds.

TypeScript Usage

Once built, import and use the WASM module:

Measuring Sizes

Measure the final artifact sizes:
Outputs to stdout:
From the Makefile:

Cleaning Build Artifacts

Clean the WASM build directory:
This removes everything in query-compiler/query-compiler-wasm/pkg/ except README.md.

Optional Tools

wasm2wat

Convert WASM to WebAssembly Text Format for inspection:
The build script automatically generates .wat files if wasm2wat is installed.

Graphviz

Render query graphs as PNG:
Requires dot (from Graphviz) to be installed.

CI Integration

In GitHub Actions:

Troubleshooting

Install Binaryen:
The -O4 and --gufa-optimizing flags are memory-intensive. Options:
  • Use small mode instead of fast
  • Increase available memory
  • Disable specific optimization passes
Ensure the provider feature is enabled:
The build script handles this automatically.
The wasm-bindgen CLI version must match the crate version. Check Cargo.lock for the exact version and install:

Next Steps

Overview

Return to architecture overview

Driver Adapters

Learn about driver adapters for query execution