Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/sqlite/blob/master/ext/wasm/README.md
# sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
branch `master` Branches Tags History
`sqlite / ext / wasm / README.md`
190 lines ยท 6327 bytes Raw Blame History Rendered
1 This directory houses the browser-side
2 [Web Assembly (WASM)](https://en.wikipedia.org/wiki/WebAssembly)
3 parts of the sqlite3 build.
4
5 See also: [](./api/README.md)
6
7 It requires [Emscripten][] and that the build environment be set up
8 for emscripten. _Release_ builds also require [the wabt tools](#wabt)
9 1.0.36 or higher, but dev builds do not. A mini-HOWTO for setting that
10 up follows...
11
12 First, install the Emscripten SDK, as documented
13 [here](https://emscripten.org/docs/getting_started/downloads.html) and summarized
14 below for Linux environments:
15
16 ```
17 # Clone the emscripten repository:
18 $ git clone https://github.com/emscripten-core/emsdk.git
19 $ cd emsdk
20
21 # Download and install the latest SDK tools:
22 $ ./emsdk install latest
23
24 # Make the "latest" SDK "active" for the current user:
25 $ ./emsdk activate latest
26 ```
27
28 The SDK can later be updated using:
29
30 ```
31 $ git pull
32 $ ./emsdk install latest
33 $ ./emsdk activate latest
34 ```
35
36 (Sidebar: Emscripten updates can and do _change things_, i.e. _break
37 things_, so it's considered _required practice_ to test thoroughly
38 after upgrading it! Our build process makes no guarantees about which
39 Emscripten version(s) will or won't work, but it's important that
40 production builds are built using a compatible version. During active
41 development, the EMSDK is frequently updated, the goal being to keep
42 `sqlite3.wasm` working with "the latest" EMSDK.)
43
44 The SQLite configure script will search for the EMSDK. One way
45 to ensure that it finds it is:
46
47 ```
48 # Activate PATH and other environment variables in the current terminal
49 # from the emsdk checkout:
50 $ source ./emsdk_env.sh
51
52 $ which emcc
53 /path/to/emsdk/upstream/emscripten/emcc
54
55 $ ./configure ...
56 ```
57
58 Optionally, add that `source` part to your login shell's resource file
59 (`~/.bashrc` or equivalent).
60
61 Another way is to pass the EMSDK dir to configure:
62
63 ```
64 $ ./configure --with-emsdk=/path/to/emsdk
65 ```
66
67 The build tree uses a small wrapper for invoking the `emcc` (the
68 Emscripten compiler): `tool/emcc.sh` is generated from
69 `tool/emcc.sh.in` using the EMSDK path found by the configure process.
70
71 With that in place, the most common build approaches are:
72
73 ```
74 # From the top of the tree:
75 $ make fiddle
76 ```
77
78 Or:
79
80 ```
81 $ make sqlite3.c shell.c; # needed in advance of...
82 $ cd ext/wasm
83 $ make
84 ```
85
86 Those will generate the a number of files required for a handful of
87 test and demo applications which can be accessed via
88 `index.html`. WASM content cannot, due to XMLHttpRequest security
89 limitations, be loaded if the containing HTML file is opened directly
90 in the browser (i.e. if it is opened using a `file://` URL), so it
91 needs to be served via an HTTP server. For example, using
92 [althttpd][]:
93
94 ```
95 $ cd ext/wasm
96 $ althttpd --enable-sab --max-age 1 --page index.html
97 # Or, more simply, from the ext/wasm dir:
98 $ make httpd
99 ```
100
101 That will open the system's browser and visit the index page, from
102 which (almost) all of the test and demo applications can be accessed.
103 (`ext/wasm/SQLTester` is not listed in that page because it's only of
104 real utility when it's used in conjunction with the project's
105 proprietary test suite, which most users don't have access to.)
106
107 When serving this app via [althttpd][], it must be a version from
108 2022-09-26 or newer so that it recognizes the `--enable-sab` flag,
109 which causes althttpd to emit two HTTP response headers which are
110 required to enable JavaScript's `SharedArrayBuffer` and `Atomics`
111 APIs. Those APIs are required in order to enable the [OPFS][]-related
112 features in the apps which use them.
113
114
115
116 # Major Makefile Targets
117
118 - default, all
119 Build intended for day-to-day development, optimized for reduced
120 build time. i.e. unoptimized debug builds.
121 - o0, o1, o2, o3, os, oz
122 A full clean/rebuild with the `-Ox` optimization level indicated by
123 the target name. A clean rebuild is necessary for all components to
124 get the desired optimization level.
125 - dist
126 Creates an optimized build and distribution zip file.
127 - snapshot
128 Similar to `dist` but the resulting archive is clearly marked as a
129 snapshot/prerelease build.
130
131
132 Targets intended only for use by the code maintainers:
133
134 - for-testing
135 Create an optimized build for the test server.
136 - push-testing
137 Push the current build to the test server. Requires SSH access to
138 the test server and that an SSH alias be set up for it locally.
139 - update-docs
140 Updates certain derived/generated files in a local checkout of
141 the [sqlite.org/wasm][www-wasm] site, if found. It uses whatever
142 build is currently sitting in the tree - care must be taken
143 to use an `oz`, `dist`, or `for-testing` build to ensure that
144 the optimized JS/WASM files used.
145
146
147 # Testing on a remote machine that is accessed via SSH
148
149 *NB: The following are developer notes, last validated on 2023-07-19*
150
151 * Remote: Install git, emsdk, and althttpd
152 * Use a [version of althttpd][althttpd] from
153 September 26, 2022 or newer.
154 * Remote: Install the SQLite source tree. CD to ext/wasm
155 * Remote: "`make`" to build WASM
156 * Remote: `althttpd --enable-sab --port 8080 --popup`
157 * Local: `ssh -L 8180:localhost:8080 remote`
158 * Local: Point your web-browser at http://localhost:8180/index.html
159
160 In order to enable [SharedArrayBuffer][], the web-browser requires
161 that the two extra Cross-Origin lines be present in HTTP reply headers
162 and that the request must come from "localhost" (_or_ over an SSL
163 connection). Since the web-server is on a different machine from the
164 web-broser, the localhost requirement means that the connection must
165 be tunneled using SSH.
166
167
168
169 # The wabt Tools
170
171 _Release_ builds require the wabt tools:
172
173
174
175 Specifically, we need `wasm-strip` so that the resulting WASM file is not
176 several megabytes.
177
178 Pre-built binaries can be downloaded from:
179
180
181
182 As of 2025-10-14, versions 1.36.0 or higher are known to work and
183 1.34.0 is known to not work with current Emscripten output.
184
185
186 [emscripten]: https://emscripten.org
187 [althttpd]: https://sqlite.org/althttpd
188 [SharedArrayBuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
189 [OPFS]: https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system
190 [www-wasm]: https://sqlite.org/wasm