0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2024-11-23 13:16:16 +00:00
libsql/libsql-sqlite3/ext/wasm
2024-10-31 13:19:49 +04:00
..
api Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
common restructure repository 2023-10-16 13:58:16 +02:00
fiddle ext/wasm: allow WAL mode 2023-11-28 09:26:28 +01:00
jaccwabyt Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
sql restructure repository 2023-10-16 13:58:16 +02:00
SQLTester ext/wasm: fix SQLTester path 2023-11-29 16:53:59 +01:00
tests/opfs/concurrency restructure repository 2023-10-16 13:58:16 +02:00
batch-runner-sahpool.html Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
batch-runner-sahpool.js Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
batch-runner.html restructure repository 2023-10-16 13:58:16 +02:00
batch-runner.js Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
c-pp.c restructure repository 2023-10-16 13:58:16 +02:00
demo-123-worker.html restructure repository 2023-10-16 13:58:16 +02:00
demo-123.html restructure repository 2023-10-16 13:58:16 +02:00
demo-123.js Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
demo-jsstorage.html restructure repository 2023-10-16 13:58:16 +02:00
demo-jsstorage.js restructure repository 2023-10-16 13:58:16 +02:00
demo-worker1-promiser.html restructure repository 2023-10-16 13:58:16 +02:00
demo-worker1-promiser.js restructure repository 2023-10-16 13:58:16 +02:00
demo-worker1.html restructure repository 2023-10-16 13:58:16 +02:00
demo-worker1.js restructure repository 2023-10-16 13:58:16 +02:00
dist.make restructure repository 2023-10-16 13:58:16 +02:00
example_extra_init.c restructure repository 2023-10-16 13:58:16 +02:00
EXPORTED_FUNCTIONS.fiddle.in restructure repository 2023-10-16 13:58:16 +02:00
fiddle.make restructure repository 2023-10-16 13:58:16 +02:00
GNUmakefile link math lib which necessary for LibSQL vector search 2024-10-31 13:19:49 +04:00
index-dist.html Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
index.html Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
module-symbols.html restructure repository 2023-10-16 13:58:16 +02:00
README-dist.txt restructure repository 2023-10-16 13:58:16 +02:00
README.md restructure repository 2023-10-16 13:58:16 +02:00
scratchpad-wasmfs.html restructure repository 2023-10-16 13:58:16 +02:00
scratchpad-wasmfs.mjs restructure repository 2023-10-16 13:58:16 +02:00
speedtest1-wasmfs.html restructure repository 2023-10-16 13:58:16 +02:00
speedtest1-wasmfs.mjs restructure repository 2023-10-16 13:58:16 +02:00
speedtest1-worker.html Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
speedtest1-worker.js Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
speedtest1.html restructure repository 2023-10-16 13:58:16 +02:00
split-speedtest1-script.sh restructure repository 2023-10-16 13:58:16 +02:00
test-opfs-vfs.html restructure repository 2023-10-16 13:58:16 +02:00
test-opfs-vfs.js Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
tester1-worker.html restructure repository 2023-10-16 13:58:16 +02:00
tester1.c-pp.html restructure repository 2023-10-16 13:58:16 +02:00
tester1.c-pp.js Merge upstream SQLite 3.45.1 2024-07-25 13:45:06 +03:00
wasmfs.make restructure repository 2023-10-16 13:58:16 +02: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.