2022-08-10 12:36:10 +03:00
|
|
|
This directory houses the [Web Assembly (WASM)](https://en.wikipedia.org/wiki/WebAssembly)
|
|
|
|
parts of the sqlite3 build.
|
2022-05-18 20:14:24 +03:00
|
|
|
|
|
|
|
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](https://emscripten.org/docs/getting_started/downloads.html) and summarized
|
|
|
|
below for Linux environments:
|
|
|
|
|
|
|
|
```
|
|
|
|
# Clone the emscripten repository:
|
2022-08-18 18:53:27 +03:00
|
|
|
$ sudo apt install git
|
2022-05-18 20:14:24 +03:00
|
|
|
$ 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
|
|
|
|
```
|
|
|
|
|
2022-08-10 12:36:10 +03:00
|
|
|
Those parts only need to be run once, but the SDK can be updated using:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ git pull
|
2022-09-30 01:08:22 +03:00
|
|
|
$ ./emsdk install latest
|
2022-08-10 12:36:10 +03:00
|
|
|
$ ./emsdk activate latest
|
|
|
|
```
|
|
|
|
|
|
|
|
The following needs to be run for each shell instance which needs the
|
|
|
|
`emcc` compiler:
|
2022-05-18 20:14:24 +03:00
|
|
|
|
|
|
|
```
|
|
|
|
# Activate PATH and other environment variables in the current terminal:
|
|
|
|
$ source ./emsdk_env.sh
|
|
|
|
|
|
|
|
$ which emcc
|
|
|
|
/path/to/emsdk/upstream/emscripten/emcc
|
|
|
|
```
|
|
|
|
|
2022-08-10 12:36:10 +03:00
|
|
|
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:
|
2022-05-18 20:14:24 +03:00
|
|
|
|
|
|
|
```
|
|
|
|
$ make fiddle
|
|
|
|
```
|
|
|
|
|
|
|
|
Or:
|
|
|
|
|
|
|
|
```
|
2022-08-10 12:36:10 +03:00
|
|
|
$ cd ext/wasm
|
2022-05-18 20:14:24 +03:00
|
|
|
$ make
|
|
|
|
```
|
|
|
|
|
2022-10-29 15:31:50 +03:00
|
|
|
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][]:
|
2022-05-18 20:14:24 +03:00
|
|
|
|
|
|
|
```
|
2022-10-29 15:31:50 +03:00
|
|
|
$ cd ext/wasm
|
|
|
|
$ althttpd --enable-sab --max-age 1 --page index.html
|
2022-05-18 20:14:24 +03:00
|
|
|
```
|
|
|
|
|
2022-10-29 15:31:50 +03:00
|
|
|
That will open the system's browser and run the index page, from which
|
|
|
|
all of the test and demo applications can be accessed.
|
2022-05-18 20:14:24 +03:00
|
|
|
|
|
|
|
Note that when serving this app via [althttpd][], it must be a version
|
2022-10-29 15:31:50 +03:00
|
|
|
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.
|
2022-05-19 01:58:34 +03:00
|
|
|
|
2022-08-18 18:53:27 +03:00
|
|
|
# Testing on a remote machine that is accessed via SSH
|
|
|
|
|
2023-07-19 20:46:28 +03:00
|
|
|
*NB: The following are developer notes, last validated on 2023-07-19*
|
2022-08-18 18:53:27 +03:00
|
|
|
|
|
|
|
* Remote: Install git, emsdk, and althttpd
|
2022-10-29 15:31:50 +03:00
|
|
|
* Use a [version of althttpd][althttpd] from
|
|
|
|
September 26, 2022 or newer.
|
2022-08-18 18:53:27 +03:00
|
|
|
* Remote: Install the SQLite source tree. CD to ext/wasm
|
|
|
|
* Remote: "`make`" to build WASM
|
2022-10-29 15:31:50 +03:00
|
|
|
* Remote: `althttpd --enable-sab --port 8080 --popup`
|
2023-07-28 14:52:58 +03:00
|
|
|
* Local: `ssh -L 8180:localhost:8080 remote`
|
2022-10-29 15:31:50 +03:00
|
|
|
* Local: Point your web-browser at http://localhost:8180/index.html
|
2022-08-18 18:53:27 +03:00
|
|
|
|
2023-07-19 20:46:28 +03:00
|
|
|
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.
|
2022-08-18 18:53:27 +03:00
|
|
|
|
|
|
|
|
2022-05-18 20:14:24 +03:00
|
|
|
[emscripten]: https://emscripten.org
|
|
|
|
[althttpd]: https://sqlite.org/althttpd
|
2023-07-19 20:46:28 +03:00
|
|
|
[SharedArrayBuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
|