Files in directory ext/wasm in any check-in
- api
- common
- fiddle
- jaccwabyt
- sql
- SQLTester
- tests
- batch-runner-kvvfs.html
- batch-runner-sahpool.html
- batch-runner-sahpool.js
- batch-runner.html
- batch-runner.js
- c-pp.c
- config.make.in
- demo-123-worker.html
- demo-123.html
- demo-123.js
- demo-jsstorage.html
- demo-jsstorage.js
- demo-kvvfs1.html
- demo-kvvfs1.js
- demo-oo1.html
- demo-oo1.js
- demo-worker1-promiser-esm.html
- demo-worker1-promiser.c-pp.html
- demo-worker1-promiser.c-pp.js
- demo-worker1-promiser.html
- demo-worker1-promiser.js
- demo-worker1.html
- demo-worker1.js
- dist.make
- example_extra_init.c
- EXPORTED_FUNCTIONS.fiddle
- EXPORTED_FUNCTIONS.fiddle.in
- EXPORTED_FUNCTIONS.sqlite3-core
- EXPORTED_RUNTIME_METHODS.fiddle
- fiddle.make
- GNUmakefile
- index-dist.html
- index.html
- kvvfs.make
- kvvfs1.html
- kvvfs1.js
- make-make.sh
- mkwasmbuilds.c
- module-symbols.html
- README-dist.txt
- README.md
- scratchpad-opfs-main.html
- scratchpad-opfs-main.js
- scratchpad-opfs-worker.html
- scratchpad-opfs-worker.js
- scratchpad-opfs-worker2.js
- scratchpad-wasmfs-main.html
- scratchpad-wasmfs-main.js
- scratchpad-wasmfs.html
- scratchpad-wasmfs.mjs
- speedtest1-kvvfs.html
- speedtest1-wasmfs.html
- speedtest1-wasmfs.mjs
- speedtest1-worker.html
- speedtest1-worker.js
- speedtest1.html
- split-speedtest1-script.sh
- sqlite3-opfs-async-proxy.js
- sqlite3-worker.js
- sqlite3-worker1-promiser.js
- sqlite3-worker1.js
- test-opfs-vfs.html
- test-opfs-vfs.js
- tester1-esm.html
- tester1-worker.html
- tester1.c-pp.html
- tester1.c-pp.js
- tester1.html
- tester1.js
- testing-worker-promise.html
- testing-worker-promise.js
- testing-worker1-promiser.html
- testing-worker1-promiser.js
- testing1.html
- testing1.js
- testing2.html
- testing2.js
- version-info.c
- version-json.c
- wasmfs.make
- x-sync-async.html
- x-sync-async.js
This directory houses the Web Assembly (WASM) parts of the sqlite3 build.
It requires emscripten and that the build environment be set up for emscripten. A mini-HOWTO for setting that up follows...
First, install the Emscripten SDK, as documented here and summarized below for Linux environments:
# Clone the emscripten repository:
$ sudo apt install git
$ git clone https://github.com/emscripten-core/emsdk.git
$ cd emsdk
# Download and install the latest SDK tools:
$ ./emsdk install latest
# Make the "latest" SDK "active" for the current user:
$ ./emsdk activate latest
Those parts only need to be run once, but the SDK can be updated using:
$ git pull
$ ./emsdk install latest
$ ./emsdk activate latest
(Sidebar: Emscripten updates can and do change things, i.e. break things, so it's considered required practice to test thoroughly after upgrading it! Our build process makes no guarantees about which Emscripten version(s) will or won't work, but it's important that production builds are built using a compatible version. During active development, the EMSDK is frequently updated, the goal being to keep sqlite3.wasm working with "the latest" EMSDK.)
The SQLite configure script will search for the EMSDK. One way to ensure that it finds it is:
# Activate PATH and other environment variables in the current terminal:
$ source ./emsdk_env.sh
$ which emcc
/path/to/emsdk/upstream/emscripten/emcc
$ ./configure ...
Optionally, add that source
part to your login shell's resource file
(~/.bashrc
or equivalent).
Another way is to pass the EMSDK dir to configure:
$ ./configure --with-emsdk=/path/to/emsdk
The build tree uses a small wrapper for invoking the emcc
(the
Emscripten compiler): tool/emcc.sh
is generated from
tool/emcc.sh.in
using the EMSDK path found by the configure process.
With that in place, the most common build approaches are:
# From the top of the tree:
$ make fiddle
Or:
$ cd ext/wasm
$ make
Those will generate the a number of files required for a handful of
test and demo applications which can be accessed via
index.html
. WASM content cannot, due to XMLHttpRequest security
limitations, be loaded if the containing HTML file is opened directly
in the browser (i.e. if it is opened using a file://
URL), so it
needs to be served via an HTTP server. For example, using
althttpd:
$ cd ext/wasm
$ althttpd --enable-sab --max-age 1 --page index.html
# Or, more simply, from the ext/wasm dir:
$ make httpd
That will open the system's browser and visit the index page, from
which (almost) all of the test and demo applications can be accessed.
(ext/wasm/SQLTester
is not listed in that page because it's only of
real utility when it's used in conjunction with the proprietary test
suite, which most users don't have access to.)
Note that when serving this app via althttpd, it must be a version
from 2022-09-26 or newer so that it recognizes the --enable-sab
flag, which causes althttpd to emit two HTTP response headers which
are required to enable JavaScript's SharedArrayBuffer
and Atomics
APIs. Those APIs are required in order to enable the OPFS-related
features in the apps which use them.
Testing on a remote machine that is accessed via SSH
NB: The following are developer notes, last validated on 2023-07-19
- Remote: Install git, emsdk, and althttpd
- Use a version of althttpd from September 26, 2022 or newer.
- Remote: Install the SQLite source tree. CD to ext/wasm
- Remote: "
make
" to build WASM - Remote:
althttpd --enable-sab --port 8080 --popup
- Local:
ssh -L 8180:localhost:8080 remote
- Local: Point your web-browser at http://localhost:8180/index.html
In order to enable SharedArrayBuffer, the web-browser requires that the two extra Cross-Origin lines be present in HTTP reply headers and that the request must come from "localhost" (or over an SSL connection). Since the web-server is on a different machine from the web-broser, the localhost requirement means that the connection must be tunneled using SSH.