GitHunt
TA

tantaman/sqlite-rust-wasm

rust extensions loaded into a sqlite wasm build

Exploratory work to statically link a SQLite extension written in Rust to a WASM build of SQLite.

Kicked off by this issue: asg017/sqlite-loadable-rs#5

  • js/example/ contains an example app that uses the built wasm
  • wa-sqlite/ is our wasm port of SQLite
  • rs/ contains our rust lib

Building

cd wa-sqlite
make

This will build and link in the Rust code as well.

The interesting commit that updated wa-sqlite to include the rust code is this one:
vlcn-io/wa-sqlite@22985f9

Running Example App

cd js
pnpm install
pnpm start

Is it actually doing anything?

Yes. You can test that testext_commit_hook is being called by flipping the return value to 1.

In that case, the demo app fails because the transaction is aborted.

Flipping it back to 0 and recompiling and everything works as expected.

How is it done?

The Rust code is compiled to LLVM bitcode against a wasm-unknown-unknown target.

nit: probably doable by packaging into a single .a file targeting wasm32-unkown-unknown -- to test.

RUSTFLAGS="--emit=llvm-bc" cargo build --target wasm32-unknown-unknown

This bitcode is then able to be linked by emscripten to the broader SQLite WASM bundle.

Contributors

GNU General Public License v3.0
Created December 14, 2022
Updated March 27, 2025