@birchill/nice-sqlite-wasm 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # @birchill/nice-sqlite-wasm
2
+
3
+ This is a custom build of SQLite that only supports the "opfs-sahpool" VFS.
4
+ It's "nice" because:
5
+
6
+ - It remove the "opfs" VFS and worker parts of the JS bindings making for a
7
+ smaller bundle size.
8
+ - It allows passing in a custom path for the WASM module in order to support
9
+ cache-busting filenames / bundlers.
10
+ - It fixes some warnings that otherwise might occur at build or run-time
11
+ (e.g. the COOP/COEP header warning which is only relevant to the "opfs" VFS
12
+ and a warning about dependencies based on expressions).
13
+
14
+ In general, it should be nicer for apps using bundlers that only need the
15
+ "opfs-sahpool" VFS.
16
+
17
+ > [!NOTE]
18
+ > The JS/WASM part of SQLite is under heavy development and is expected to
19
+ > change a lot in future (e.g. using WASI instead of Emscripten). As a result
20
+ > this project may no longer be necessary or may become impractical to update.
21
+
22
+ For the official SQLite WASM package see
23
+ [sqlite-wasm](https://github.com/sqlite/sqlite-wasm).
24
+
25
+ ## Usage
26
+
27
+ TODO
28
+
29
+ ## Developing
30
+
31
+ ### Installing prerequisites
32
+
33
+ ```
34
+ pnpm install
35
+ ```
36
+
37
+ This will install some tools we use like
38
+ [oxfmt](https://oxc.rs/docs/guide/usage/formatter.html).
39
+
40
+ ### Fetching the SQLite source code
41
+
42
+ Ensure `sqlite-revision.txt` contains the desired SQLite version (e.g.
43
+ `version-3.51.1` or any tag from the
44
+ [SQLite git repository](https://github.com/sqlite/sqlite.git)).
45
+
46
+ Then run:
47
+
48
+ ```
49
+ pnpm run fetch
50
+ ```
51
+
52
+ ### Applying patches
53
+
54
+ ```
55
+ pnpm run patch
56
+ ```
57
+
58
+ #### Creating new patches
59
+
60
+ First [fetch the source](#fetching-the-sqlite-source-code) then apply any
61
+ existing patches.
62
+
63
+ Then go to `work/sqlite-src`, make edits and run
64
+ `git diff > ../../patches/patch-name.patch`.
65
+
66
+ Something like:
67
+
68
+ ```
69
+ pnpm run fetch
70
+ pnpm run patch
71
+ cd work/sqlite-src
72
+ git commit -am "Existing patches"
73
+ vim ext/wasm/api/pre-js.c-pp.js # For example
74
+ git diff > ../../patches/000x-patch-description.patch
75
+ git stash
76
+ cd ../..
77
+ git add patches/000x-patch-description.patch
78
+ ```
79
+
80
+ Then update the table below.
81
+
82
+ #### Current patches
83
+
84
+ | Patch name | Purpose |
85
+ | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
86
+ | `0001-locatefile-nullish-coalesce.patch` | Allow a user-provided `locateFile` function to be used (rather than clobbered). |
87
+ | `0002-hardcode-locatefile-path.patch` | Hardcodes the path used in the default `locateFile` implementation so that bundlers don't complain about dependencies based on expressions. |
88
+
89
+ ### Building the WASM module
90
+
91
+ #### Getting Emscripten
92
+
93
+ First you need to [install
94
+ Emscripten](https://emscripten.org/docs/getting_started/downloads.html).
95
+
96
+ ```
97
+ git clone https://github.com/emscripten-core/emsdk.git
98
+ cd emsdk
99
+ ./emsdk install latest
100
+ ./emsdk activate latest
101
+ source ./emsdk_env.sh # Or source ./emsdk_env.fish etc.
102
+ ```
103
+
104
+ Note that you need to run the `emsdk_env.*` script every time so you might want
105
+ to add something to your shell's startup script.
106
+
107
+ e.g. for fish
108
+
109
+ ```fish
110
+ if test -e ~/emsdk/emsdk_env.fish
111
+ EMSDK_QUIET=1 source ~/emsdk/emsdk_env.fish
112
+ end
113
+ ```
114
+
115
+ #### Getting `wasm-strip` (from `wabt`)
116
+
117
+ Then you need to install
118
+ [wabt](https://github.com/WebAssembly/wabt?tab=readme-ov-file) for to make
119
+ `wasm-strip` available.
120
+
121
+ Critically, this must be version 1.0.36 or higher or else `wasm-strip` will fail
122
+ on the 64-bit build with "tables may not be 64-bit". We don't actually need the
123
+ 64-bit build but there's no way to turn it off easily.
124
+
125
+ As of this writing, using `sudo apt install wabt` gives you version 1.0.34 which
126
+ is not high enough.
127
+
128
+ Instead you probably want to download the latest release from
129
+ [https://github.com/WebAssembly/wabt/releases](https://github.com/WebAssembly/wabt/releases):
130
+
131
+ ```
132
+ wget https://github.com/WebAssembly/wabt/releases/download/1.0.39/wabt-1.0.39-linux-x64.tar.gz
133
+ tar -xzf wabt-1.0.39-linux-x64.tar.gz
134
+ sudo mv ~/wabt-1.0.39 /usr/local/wabt-1.0.39
135
+ sudo ln -s /usr/local/wabt-1.0.39 /usr/local/wabt
136
+ sudo ln -s /usr/local/wabt/bin/* /usr/local/bin/
137
+ ```
138
+
139
+ (or `brew install wabt` on macOS)
140
+
141
+ #### Actually building
142
+
143
+ Then run:
144
+
145
+ ```
146
+ pnpm build
147
+ ```