sqlite/ext/wasm
stephan c8f245ab5c Add an optional argument to oo1.DB.transaction() to specify an explicit BEGIN qualifier.
FossilOrigin-Name: 507335c12b1dbe21d180cf6f0a0deb4cc737417acb44c8f1d8fac98b86f62b01
2022-12-27 11:40:05 +00:00
..
api Add an optional argument to oo1.DB.transaction() to specify an explicit BEGIN qualifier. 2022-12-27 11:40:05 +00:00
common Expose the auto-extension API to JS and reorganize some nearby code. 2022-12-26 17:15:05 +00:00
fiddle Move the sqlite3.capi.wasm namespace to sqlite3.wasm. This causes a tiny bit of naming confusion with the sqlite3.wasm *file*, but seems to make more sense than having it as a sub-namespace of capi. 2022-10-29 07:54:10 +00:00
jaccwabyt Work on an alternate (slightly simpler) approach to binding JS vtabs. Non-eponymous vtabs are not working, for reasons as yet unknown. 2022-12-07 07:22:34 +00:00
sql Minor cleanups in OO API #1. Add Sudoku SQL to batch-runner.js's list. 2022-09-05 13:24:08 +00:00
tests/opfs/concurrency Rework the oo1.DB's distinct-per-VFS post-open() step to accept either a batch of SQL or a callback function. Increase OPFS's busy timeout to 10s. 2022-12-03 01:59:03 +00:00
batch-runner.html Apply considerable acrobatics to get the JS/WASM deliverables building to and loadable from a directory other than the one which contains the app-level code. Requires an only-slightly-leaky abstraction of passing a URL argument when loading sqlite3.js but provides much greater flexibility in where the JS/WASM files are located. 2022-10-19 04:44:58 +00:00
batch-runner.js Rename the oft-used, verbose sqlite3.wasm.get/setMemValue() and get/setPtrValue() to peek/poke() and peek/pokePtr(). The old names are retained as aliases just in case any client code actually uses them, but they are now deprecated. 2022-12-09 09:23:27 +00:00
c-pp.c Replace use of cpp with the fit-to-purpose c-pp to avoid cpp's C-centric/JS-unfriendly quirks. 2022-11-18 02:29:59 +00:00
demo-123-worker.html Apply considerable acrobatics to get the JS/WASM deliverables building to and loadable from a directory other than the one which contains the app-level code. Requires an only-slightly-leaky abstraction of passing a URL argument when loading sqlite3.js but provides much greater flexibility in where the JS/WASM files are located. 2022-10-19 04:44:58 +00:00
demo-123.html Apply considerable acrobatics to get the JS/WASM deliverables building to and loadable from a directory other than the one which contains the app-level code. Requires an only-slightly-leaky abstraction of passing a URL argument when loading sqlite3.js but provides much greater flexibility in where the JS/WASM files are located. 2022-10-19 04:44:58 +00:00
demo-123.js Apply considerable acrobatics to get the JS/WASM deliverables building to and loadable from a directory other than the one which contains the app-level code. Requires an only-slightly-leaky abstraction of passing a URL argument when loading sqlite3.js but provides much greater flexibility in where the JS/WASM files are located. 2022-10-19 04:44:58 +00:00
demo-jsstorage.html Rename several demo/test files and include more of them in the end-user dist archive. 2022-10-19 07:34:36 +00:00
demo-jsstorage.js Move the sqlite3.capi.wasm namespace to sqlite3.wasm. This causes a tiny bit of naming confusion with the sqlite3.wasm *file*, but seems to make more sense than having it as a sub-namespace of capi. 2022-10-29 07:54:10 +00:00
demo-worker1-promiser.html Rename several demo/test files and include more of them in the end-user dist archive. 2022-10-19 07:34:36 +00:00
demo-worker1-promiser.js Update JS worker #1 API and related tests for recent API changes. 2022-12-25 23:45:59 +00:00
demo-worker1.html Rename several demo/test files and include more of them in the end-user dist archive. 2022-10-19 07:34:36 +00:00
demo-worker1.js Add sqlite3_wasm_vfs_create_file() to replace Emscripten's FS.createDataFile() in a (mostly) VFS-agnostic way. Add a test for worker1's export (to bytearray) support. Re-add worker1 open-from-bytearray using sqlite3_wasm_vfs_create_file() but it's untested (requires a new interactive test app or maybe reconsideration). 2022-11-02 11:53:31 +00:00
dist.make Minor build tweaks in ext/wasm to create a faster-running build for the common dev-mode cases. No code changes. 2022-12-11 07:53:03 +00:00
EXPORTED_FUNCTIONS.fiddle.in Fiddle: replace db export routine with a C-side one which works for both Emscripten FS-hosted and OPFS-hosted db files. Minor code-adjacent cleanups. 2022-09-26 13:55:10 +00:00
fiddle.make Remove an unnecessary/obsolete Emscripten-specific export. 2022-12-15 02:26:13 +00:00
GNUmakefile Explicitly omit threading and extension loading from the ext/wasm/c-pp binary build to avoid a link error on some systems. 2022-12-23 18:38:14 +00:00
index-dist.html Minor touchups to the JS test index page and test server push rules. 2022-12-02 11:35:21 +00:00
index.html Update wasmfs.make to get WASMFS building again, but changes made to OPFS-over-WASMFS since we last tested it have made it incompatible with how we used it. It can now only be used from worker threads, eliminating the one benefit it had over the sqlite3_vfs OPFS implementation. Remove/amend references to WASMFS in the docs and remove all WASMFS-specific test app links from index.html. 2022-12-17 11:14:35 +00:00
module-symbols.html Reimplement sqlite3.capi.sqlite3_close_v2() and sqlite3session_delete() as a hand-written bindings so that they can attempt to clean up certain (potentially) FuncPtrAdapter-installed functions before closing. Correct the create-function family of JS-to-function-pointer automated conversions to include the UDF's arity as part of the mapping's key so that (un)binding a UDF to different functions for different arities works (and add tests confirming it). Correct a broken doc link in module-symbols.html. 2022-12-26 11:13:09 +00:00
README-dist.txt Add doc page link to the wasm dist README.txt. 2022-10-25 16:57:42 +00:00
README.md Update ext/wasm/README.md for recent developments. 2022-10-29 12:31:50 +00:00
scratchpad-wasmfs-main.html Split wasmfs-enabled build of sqlite3.js/wasm into sqlite3-wasmfs.js/wasm, as enabling wasmfs breaks all tests/demos which run from a Worker thread. 2022-09-15 03:09:00 +00:00
scratchpad-wasmfs-main.js Move the sqlite3.capi.wasm namespace to sqlite3.wasm. This causes a tiny bit of naming confusion with the sqlite3.wasm *file*, but seems to make more sense than having it as a sub-namespace of capi. 2022-10-29 07:54:10 +00:00
speedtest1-wasmfs.html Update wasmfs.make to get WASMFS building again, but changes made to OPFS-over-WASMFS since we last tested it have made it incompatible with how we used it. It can now only be used from worker threads, eliminating the one benefit it had over the sqlite3_vfs OPFS implementation. Remove/amend references to WASMFS in the docs and remove all WASMFS-specific test app links from index.html. 2022-12-17 11:14:35 +00:00
speedtest1-worker.html Remove some dead JS code and tweak some docs. 2022-12-08 04:19:38 +00:00
speedtest1-worker.js Move the sqlite3.capi.wasm namespace to sqlite3.wasm. This causes a tiny bit of naming confusion with the sqlite3.wasm *file*, but seems to make more sense than having it as a sub-namespace of capi. 2022-10-29 07:54:10 +00:00
speedtest1.html Remove some dead JS code and tweak some docs. 2022-12-08 04:19:38 +00:00
split-speedtest1-script.sh batch-runner.js: move generated SQL files into ./sql and start adding hand-written ones (like the Mandelbrot) to that set. 2022-08-30 10:04:08 +00:00
test-opfs-vfs.html Apply considerable acrobatics to get the JS/WASM deliverables building to and loadable from a directory other than the one which contains the app-level code. Requires an only-slightly-leaky abstraction of passing a URL argument when loading sqlite3.js but provides much greater flexibility in where the JS/WASM files are located. 2022-10-19 04:44:58 +00:00
test-opfs-vfs.js Update test-opfs-vfs.js to account for recent API changes. Reported in [forum:4a97813fcbd4f63e|forum post 4a97813fcbd4f63e]. 2022-12-19 14:43:17 +00:00
tester1-worker.html Expose sqlite3_get/set_auxdata() to wasm. Minor test app CSS tweaks. 2022-12-05 14:13:55 +00:00
tester1.c-pp.html Expose sqlite3_get/set_auxdata() to wasm. Minor test app CSS tweaks. 2022-12-05 14:13:55 +00:00
tester1.c-pp.js Expose the auto-extension API to JS and reorganize some nearby code. 2022-12-26 17:15:05 +00:00
version-info.c Add --download-version flag to ext/wasm/version-info.c and correct dist target's output version format to match. 2022-10-26 06:05:44 +00:00
wasmfs.make Update wasmfs.make to get WASMFS building again, but changes made to OPFS-over-WASMFS since we last tested it have made it incompatible with how we used it. It can now only be used from worker threads, eliminating the one benefit it had over the sqlite3_vfs OPFS implementation. Remove/amend references to WASMFS in the docs and remove all WASMFS-specific test app links from index.html. 2022-12-17 11:14:35 +00:00

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

The following needs to be run for each shell instance which needs the emcc compiler:

# Activate PATH and other environment variables in the current terminal:
$ source ./emsdk_env.sh

$ which emcc
/path/to/emsdk/upstream/emscripten/emcc

Optionally, add that to your login shell's resource file (~/.bashrc or equivalent).

That env script needs to be sourced for building this application from the top of the sqlite3 build tree:

$ make fiddle

Or:

$ cd ext/wasm
$ make

That 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

That will open the system's browser and run the index page, from which all of the test and demo applications can be accessed.

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 2022-08-18

  • Remote: Install git, emsdk, and althttpd
  • 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 SharedArrayBuffers, 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". 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.