sqlite/ext/wasm
stephan f03ddcca32 Add ext/wasm/module-symbols.html. Adjacent minor JS touchups.
FossilOrigin-Name: 24f12e681e06e3b71a6ac9c82255fe0270953a74c711405841f7e385eeafe874
2022-10-28 11:40:46 +00:00
..
api Add ext/wasm/module-symbols.html. Adjacent minor JS touchups. 2022-10-28 11:40:46 +00:00
common Add ext/wasm/module-symbols.html. Adjacent minor JS touchups. 2022-10-28 11:40:46 +00:00
fiddle Correct misuse of localhost-mode-only symbol S in fiddle-worker.js, which should fix the outage reported in [forum:67d985ac0bbe407f|forum post 67d985ac0bbe407f]. 2022-10-26 15:40:17 +00:00
jaccwabyt Move the rest of testing1.js into tester1.js and eliminate the dependency on jaccwabyt_test.c. Extend the list of default config-related #defines in sqlite3-wasm.c and reorganize them for maintainability. 2022-10-13 16:48:35 +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
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 Add configurable cache_size to batch-runner and speedtest1-worker. Add SQL tracing to demo-123.js just for demonstration's sake. 2022-10-03 18:07:25 +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 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.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 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.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 Rename several demo/test files and include more of them in the end-user dist archive. 2022-10-19 07:34:36 +00:00
dist.make 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
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 Rename fiddle.html to index.html and move fiddle push-to-server rules from GNUmakefile into fiddle.make. 2022-10-25 15:59:27 +00:00
GNUmakefile 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
index-dist.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
index.html Add ext/wasm/module-symbols.html. Adjacent minor JS touchups. 2022-10-28 11:40:46 +00:00
module-symbols.html Add ext/wasm/module-symbols.html. Adjacent minor JS touchups. 2022-10-28 11:40:46 +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 Add JS infrastructure to ostensibly allow us to customize the wasm imports, which will hypothetically allow us to eliminate the dependency on EM_JS(), but the corresponding Emscripten glue-level feature currently breaks fatally with WASMFS builds so it's disabled. 2022-09-29 22:08:22 +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 Remove oo1.DB.hasFilename() and getFilename(), as they are unnecessary. 2022-10-26 11:12:14 +00:00
speedtest1-wasmfs.html Rework the Emscripten-emitted module loader/init function such that it passes on the sqlite3 module, instead of the Emscripten module, to the first then() of sqlite3InitModule()'s returned Promise. This eliminates any need to mention the Emscripten module object in client-side code unless they want to configure it in advance for loading-status reports. 2022-09-29 13:17:50 +00:00
speedtest1-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
speedtest1-worker.js speedtest1: use the current (or default) vfs->xDelete method to unlink the db. This is specifically necessary when running the opfs vfs in a wasm build of speedtest1. This worked without this fix until recently because the affected test code was performing similar acrobatics in its stead. 2022-10-25 15:38:38 +00:00
speedtest1.html speedtest1.html: when vfs==kvvfs, increase --size from 2 to 4, as enabled by [a4d40f6346e7]. --size 5 is 4.96mb out of (supposedly) 5mb, which works but is a bit too close to the edge. 2022-10-27 14:41: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 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
tester1-worker.html Remove persistence from the 'reverse log order?' checkbox in tester1.js to eliminate an inconsistency between the main-thread and worker-thread modes (the latter having no option for persistence of that setting). 2022-10-25 08:15:57 +00:00
tester1.html Remove persistence from the 'reverse log order?' checkbox in tester1.js to eliminate an inconsistency between the main-thread and worker-thread modes (the latter having no option for persistence of that setting). 2022-10-25 08:15:57 +00:00
tester1.js Minor doc typo fixes. 2022-10-27 03:57:48 +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 Considerable wasm/js build cleanups and reworking. Remove wasmfs builds from the end-user deliverables and disable the wasmfs build by default, per /chat discussion, as it doubles our deliverable count for only marginal gain. Attempt to move the sqlite3.js/wasm files into subdirectories but rediscovered that that breaks loading in Worker mode because URI resolution of the wasm files differs depending on whether the main script is loaded from a script tag or a Worker. 2022-10-19 01:07:30 +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 fiddle application under ext/fiddle, as fiddle.html. That application cannot, due to XMLHttpRequest security limitations, run if the 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/fiddle
$ althttpd -page fiddle.html

That will open the system's browser and run the fiddle app's page.

Note that when serving this app via althttpd, it must be a version from 2022-05-17 or newer so that it recognizes the .wasm file extension and responds with the mimetype application/wasm, as the WASM loader is pedantic about that detail.

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
    • Use a version of althttpd that adds HTTP reply header lines to enable SharedArrayBuffers. These header lines are required:
            Cross-Origin-Opener-Policy: same-origin
            Cross-Origin-Embedder-Policy: require-corp
  • Remote: Install the SQLite source tree. CD to ext/wasm
  • Remote: "make" to build WASM
  • Remote: althttpd --port 8080 --popup
  • Local: ssh -L 8180:localhost:8080 remote
  • Local: Point your web-browser at http://localhost:8180/testing1.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.

Known Quirks and Limitations

Some "impedence mismatch" between C and WASM/JavaScript is to be expected.

No I/O

sqlite3 shell commands which require file I/O or pipes are disabled in the WASM build.

exit() Triggered from C

When C code calls exit(), as happens (for example) when running an "unsafe" command when safe mode is active, WASM's connection to the sqlite3 shell environment has no sensible choice but to shut down because exit() leaves it in a state we can no longer recover from. The JavaScript-side application attempts to recognize this and warn the user that restarting the application is necessary. Currently the only way to restart it is to reload the page. Restructuring the shell code such that it could be "rebooted" without restarting the JS app would require some invasive changes which are not currently on any TODO list but have not been entirely ruled out long-term.