Build Script
Thebuild.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
fastorsmall
Example Usage
Makefile Targets
The root Makefile provides convenient targets:- Build All
- Build Fast
- Build Small
- Build + Gzip
Build both optimization modes:Equivalent to:
Makefile:
Build Process
The build happens in multiple stages:Compile to WASM
Compile the Rust code to WebAssembly:This runs for each provider:
postgresql, mysql, sqlite, sqlserver, cockroachdbGenerate JS Bindings
Use Generates:
wasm-bindgen to create TypeScript/JavaScript bindings:query_compiler_fast.jsquery_compiler_fast.d.tsquery_compiler_fast_bg.wasm
wasm-opt Flags
The script uses extensive optimization flags:| Flag | Purpose |
|---|---|
-O4 / -Os | Optimization level (speed vs size) |
--vacuum | Remove obviously unneeded code |
--duplicate-function-elimination | Deduplicate identical functions |
--duplicate-import-elimination | Deduplicate imports |
--remove-unused-module-elements | Strip unused exports |
--dae-optimizing | Dead argument elimination |
--remove-unused-names | Remove unreferenced names |
--rse | Redundant local.set elimination |
--gsi | Global struct inference |
--gufa-optimizing | Type monomorphization |
--strip-dwarf | Remove debug info |
--strip-producers | Remove producers section |
--strip-target-features | Remove target features |
query-compiler-wasm/build.sh:
Build Profiles
The build can use different Cargo profiles:- Dev (Local)
- Release (CI)
- Profiling
Default when building locally:
- Faster compilation
- Larger artifacts
- Skips
wasm-optentirely
Cargo Configuration
Fromquery-compiler-wasm/Cargo.toml:
Output Structure
After building, the output directory contains:TypeScript Usage
Once built, import and use the WASM module:Measuring Sizes
Measure the final artifact sizes:Makefile:
Cleaning Build Artifacts
Clean the WASM build directory:query-compiler/query-compiler-wasm/pkg/ except README.md.
Optional Tools
wasm2wat
Convert WASM to WebAssembly Text Format for inspection:.wat files if wasm2wat is installed.
Graphviz
Render query graphs as PNG:dot (from Graphviz) to be installed.
CI Integration
In GitHub Actions:Troubleshooting
wasm-opt not found
wasm-opt not found
Install Binaryen:
Out of memory during wasm-opt
Out of memory during wasm-opt
The
-O4 and --gufa-optimizing flags are memory-intensive. Options:- Use
smallmode instead offast - Increase available memory
- Disable specific optimization passes
Build fails with missing features
Build fails with missing features
Ensure the provider feature is enabled:The build script handles this automatically.
wasm-bindgen version mismatch
wasm-bindgen version mismatch
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