sqlite/ext/wasm
stephan 6a0f297da9 Unconditionally force use of SQLITE_ENABLE_API_ARMOR in the WASM and JNI builds. Their corresponding test suites still work.
FossilOrigin-Name: c11394b50d0687b6d6abad9c80d5cd3cdce77e9b9c278f40601c460f463744a1
2023-10-11 20:37:42 +00:00
..
api Unconditionally force use of SQLITE_ENABLE_API_ARMOR in the WASM and JNI builds. Their corresponding test suites still work. 2023-10-11 20:37:42 +00:00
common Resolve the timing/ordering issue of a JS-to-WASM-converted xDestroy() function being uninstalled from WASM right before the underlying native call tries to call it. This has been a long-unnoticed bug which appears only when removing such functions or replacing them. 2023-08-04 08:45:25 +00:00
fiddle Fix part 2 of 2 for /fiddle: a make deps problem which caused fiddle to load but fail to run when sqlite3.c was missing. 2023-08-01 16:38:08 +00:00
jaccwabyt Replace some JS 'self' references with 'globalThis', as reported via the npm subproject. 2023-06-26 07:05:05 +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
SQLTester Add a timer to the JS SQLTester app to warn if it appears that loading the module has failed, which is commonly caused by the test scripts not being compiled. 2023-09-01 17:51:09 +00:00
tests/opfs/concurrency Enhance oo1.DB.exec() to simplify returning whole result sets. 2023-01-28 05:09:26 +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 Resolve a nested if-block bug in ext/wasm/c-pp.c which caused output after a nested block to be unduly elided. Remove a kludge, added in the previous check-in, which worked around that bug. 2023-01-27 02:21:16 +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 Resolve an ES6 module export construct which is incompatible with node.js, as reported in [forum:b9680fa9ad|forum post b9680fa9ad]. 2023-07-24 15:41: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 Add ability for the JS Worker1.exec() API to report the number of changes made to the caller, per request in [forum:d0b19483642e20dd | forum post d0b19483642e20dd]. 2023-05-25 16:49:06 +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 Minor cleanups in demo JS code, per forum feedback. 2023-05-23 19:11:42 +00:00
dist.make Add the opfs-sahpool sqlite3_vfs implementation to JS, offering an alternative to the other OPFS VFS (with tradeoffs). 2023-07-22 19:57:42 +00:00
example_extra_init.c Minor doc tweak for the previous commit. 2023-02-27 07:23:54 +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 Fix part 2 of 2 for /fiddle: a make deps problem which caused fiddle to load but fail to run when sqlite3.c was missing. 2023-08-01 16:38:08 +00:00
GNUmakefile Resolve a makefile bug which causes sqlite3-worker1-bundler-friendly.mjs to be built incorrectly. Reported in [forum:a874e435cf4690c1|forum post a874e435cf4690c1]. 2023-08-28 04:59:16 +00:00
index-dist.html Minor text-only updates to wasm demo/test HTML and license header. 2023-02-10 11:05:16 +00:00
index.html Remove the batch SQL runner from the JS build's 'all' target, as it's long-since unused and adds noticable build time. Add makefile comments about JSPI. 2023-07-26 11:41:41 +00:00
module-symbols.html Add a doc link for the new sqlite3_js_posix_create_file(). 2023-08-11 17:45:23 +00:00
README-dist.txt Correct the handling of the worker1 and promiser JS files in the face of the bundler-friendly changes. Those files require separate, bundler-friendly copies. 2023-01-29 05:09:39 +00:00
README.md Correct a recently-introduced falsehood in ext/wasm/README.md regarding ssh port forwarding. 2023-07-28 11:52:58 +00:00
scratchpad-wasmfs.html More work on the wasmfs build and its test apps. 2023-07-13 17:27:05 +00:00
scratchpad-wasmfs.mjs More work on the wasmfs build and its test apps. 2023-07-13 17:27:05 +00:00
speedtest1-wasmfs.html Minor wasm build cleanups. 2023-07-14 12:21:05 +00:00
speedtest1-wasmfs.mjs More work on the wasmfs build and its test apps. 2023-07-13 17:27:05 +00:00
speedtest1-worker.html During "opfs" VFS init, check for URL param opfs-disable and, if set, do not install the VFS. Added per forum suggestion to provide a way to help rule out misinteraction between the "opfs" and "opfs-sahpool" VFSes. 2023-07-16 12:02:37 +00:00
speedtest1-worker.js Refactor opfs-sahpool to support multiple instances, each with a separate VFS name and directory. 2023-07-18 12:09:16 +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 sqlite3.oo1.Stmt.finalize() now throws if sqlite3_finalize() returns non-zero. This is intended to address the INSERT RETURNING case covered in [forum:36f7a2e7494897df|forum post 36f7a2e7494897df]. 2023-05-19 15:54:41 +00:00
tester1.c-pp.html Add JS bundler-friendly JS build. Minor test code cleanups. 2023-01-28 04:20:46 +00:00
tester1.c-pp.js Ensure that all fields of static sqlite3_module objects are explicitly 2023-10-06 12:51:05 +00:00
wasmfs.make Minor wasm build cleanups. 2023-07-14 12:21:05 +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 2023-07-19

  • 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 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.