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 wasmwa-sqlite/is our wasm port of SQLiters/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.