sqlite/ext/wasm
stephan b5e2e6fcd3 More work on the JS end-user deliverables. Add tool/stripccomments.c to support that.
FossilOrigin-Name: 2156f0744acfe425457430a0f6a7e02de907de85edba81a6d4eef40293e561c8
2022-10-18 20:36:50 +00:00
..
api Minor tweak to get bring an edge case of oo1.DB.createFunction() into aggreement with its docs. 2022-10-16 18:57:15 +00:00
common 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
fiddle Reimplement fiddle_reset_db() so that it works with all VFSes. 2022-10-03 11:42:45 +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 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
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 Correct mismatched H1 tags in test code. Minor CSS tweaks. 2022-10-12 14:39:15 +00:00
demo-123.html Correct mismatched H1 tags in test code. Minor CSS tweaks. 2022-10-12 14:39:15 +00:00
demo-123.js Add aggregate function support to sqlite3.oo1.DB.createFunction(). Change signature of the options object used by that function so that the callback property names match those of the corresponding C APIs. 2022-10-16 18:50:55 +00:00
demo-kvvfs1.html Merge kv-vfs branch into fiddle-opfs. Adjust various JS APIs and apps to deal with the new method of handling kvvfs. Adjust speedtest1 JS build to include sqlite3-api.js so that it can use kvvfs and opfs VFSes. Permit passing of the vfs as a URL parameter to certain demo/test apps. Milestone: speedtest-worker.html?vfs=opfs runs with the standalone OPFS impl. 2022-09-19 13:16:35 +00:00
demo-kvvfs1.js Add oo1.JsStorageDb.clearStorage/storageSize() methods, copies of capi.sqlite3_web_kvvfs_clear/size(). 2022-09-30 15:46:08 +00:00
dist.make More work on the JS end-user deliverables. Add tool/stripccomments.c to support that. 2022-10-18 20:36:50 +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
EXPORTED_RUNTIME_METHODS.fiddle Put pieces in place for fiddle to support opfs, but more cleanup is required in the sqlite3.js/fiddle connection. bigIntEnabled now defaults to whether the Emscripten's module has bigint enabled. Add wasm-sensible defaults for several SQLITE_ENABLE/OMIT flags in sqlite3-wasm.c. 2022-09-21 19:51:25 +00:00
fiddle.make Initial draft of archive generation for the wasm/js deliverables. 2022-10-17 17:34:41 +00:00
GNUmakefile More work on the JS end-user deliverables. Add tool/stripccomments.c to support that. 2022-10-18 20:36:50 +00:00
index.html Typo fix. 2022-10-16 23:33:24 +00:00
README-dist.txt More work on the JS end-user deliverables. Add tool/stripccomments.c to support that. 2022-10-18 20:36:50 +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 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-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 Update the 'start in speedtest kvvfs' link in speedtest1-worker to account for recent changes. 2022-10-04 08:58:22 +00:00
speedtest1-worker.js 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.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
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
sqlite3-opfs-async-proxy.js Generic minor cleanups and docs in the OPFS async proxy. 2022-10-14 15:52:29 +00:00
sqlite3-worker1-promiser.js Tweak sqlite3-worker1.js to be able to load either sqlite3.js or sqlite3-wasmfs.js, noting that the latter still does not load in a Worker because of an Emscripten loader bug. 2022-10-01 13:38:27 +00:00
sqlite3-worker1.js Tweak sqlite3-worker1.js to be able to load either sqlite3.js or sqlite3-wasmfs.js, noting that the latter still does not load in a Worker because of an Emscripten loader bug. 2022-10-01 13:38:27 +00:00
test-opfs-vfs.html Numerous cleanups in the JS bits. Removed some now-defunct wasm test files. Expose sqlite3.opfs object containing various OPFS-specific utilities. 2022-09-18 17:32:35 +00:00
test-opfs-vfs.js Replace time-based auto-unlock of opfs sync handles with lock acquisition/release via sqlite3_io_methods::xLock/xUnlock(). 2022-10-04 17:06:51 +00:00
tester1-worker.html Port the first 180-odd unit tests from testing1.* into the new tester1.*. Fix a stray-keystroke-induced typo which broke pstack.allocChunks(). 2022-10-13 08:03:31 +00:00
tester1.html Port the first 180-odd unit tests from testing1.* into the new tester1.*. Fix a stray-keystroke-induced typo which broke pstack.allocChunks(). 2022-10-13 08:03:31 +00:00
tester1.js Add aggregate function support to sqlite3.oo1.DB.createFunction(). Change signature of the options object used by that function so that the callback property names match those of the corresponding C APIs. 2022-10-16 18:50:55 +00:00
testing1.html Get testing1.js working with a kvvfs build. 2022-09-12 22:27:00 +00:00
testing2.html Minor cleanups, reorgs, and doc updates for the JS APIs. Renamed sqlite3(-api)-worker.js to sqlite3(-api)-worker1.js, for symmetry with sqlite3-api-oo1.js. 2022-08-17 16:44:05 +00:00
testing2.js Add JS wrapper for sqlite3_exec() which knows how to handle a JS callback. Add some console.error() reporting of module-load failures, as they otherwise often get silently swallowed up by the loader's mechanisms. Add 'flexible-string' JS-to-WASM argument converter which performs more X-to-string conversions than the 'string' arg converter does. 2022-09-30 20:35:37 +00:00
testing-worker1-promiser.html More work on how to configure the sqlite3 JS API bootstrapping process from higher-level code. Initial version of sqlite3-worker1-promiser, a Promise-based proxy for the Worker API #1. 2022-08-24 05:59:23 +00:00
testing-worker1-promiser.js Remove a couple of weird quirks of the Worker1 and Promiser APIs. The Worker1 (now undocumented) unlink capability needs to be reevaluated to work equivalently for all storage backends. 2022-09-30 23:49:43 +00:00
version-info.c Repair version-info.c after a local mishap caused all of the intended edits from [36e197cb3d0c]/[e9b407a4d0a0] to get deleted before checkin. Simplify version-info build (only requires sqlite3.h, not the library). 2022-10-17 16:47:59 +00:00
wasmfs.make Initial draft of archive generation for the wasm/js deliverables. 2022-10-17 17:34:41 +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.