Wasm Labs

SQLite builds for WASI since 3.41.0

By Asen Alexandrov
At 2023 / 04 2 mins reading

TL;DR

The Wasm Labs team worked with the SQLite team to upstream WASI support. Starting with SQLite 3.41.0 you can build libsqlite3.a for WASI by running:

./configure --with-wasi-sdk=$WASI_SDK_PATH --enable-all
make -j

We are excited about the official support as these changes make it easier to use SQLite in any WASI environment. We recently published precompiled Wasm binaries for libsqlite 3.41.2 using these new build options.

The story

A major goal for our work on the WebAssembly Language Runtimes is to contribute back to the original projects whenever possible.

We wanted to contribute upstream our patches for SQLite, as we were heavily relying on libsqlite for our tests of PHP.wasm with WordPress and Drupal.

Collaborating with the SQLite team

A few months ago we got in touch with the SQLite team to see what would be the best way to add WASI support to their official releases. It turned out that the process for contributing to SQLite is somewhat different from what most of us are used to. For legal reasons, we could not contribute directly, but we could discuss the required changes with someone from the SQLite team and then iterate with them by testing or commenting.

This led to a fun and enriching conversation with Stephan Beal from the SQLite team, who over a few iterations, simplified and improved the patches for a WASI build into what we have today.

Previous work

The work to port SQLite to WASI has a history of several teams and projects which pioneered those changes.

Future work

We still don't build SQLite CLI. This was never necessary for our needs, but working towards it will complete the SQLite experience.

There are a bunch of features (like Write-Ahead Logging, loadable extensions, etc) that are disabled in this SQLite build, because they cannot be implemented with WASI preview1 as of today. Given time and WASI preview2, we expect to implement those as well.

Try it out

Try out the latest libsqlite release and let us know what you think!

(10 min) Take a look at the sample app at WLR/libs/examples/sqlite_example, which can be built for wasm32-wasi.

Do you want to stay up to date with WebAssembly and our projects?