SQLite

Check-in [ed746b3d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Start work on an overhaul of the wasm build process, with an eye towards less over-engineering.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wasm-build-rework
Files: files | file ages | folders
SHA3-256: ed746b3dd3248b68cb91de50ac5ba5fd3a7c2fcbde76324e86b88edbfecd896b
User & Date: stephan 2024-07-25 10:50:45
Context
2024-07-25
14:00
More work on the minimal-mode wasm build (now 603kb uncompressed). Remove the hard-coded feature-enable flags from sqlite3-wasm.c and rely on the build to provide them. Some wasm build cleanup, but attempts to completely overhaul it have been thwarted by my inability to make script-generated makefile code more legible/maintainable than the current eval spaghetti. (check-in: b029c406 user: stephan tags: wasm-build-rework)
10:50
Start work on an overhaul of the wasm build process, with an eye towards less over-engineering. (check-in: ed746b3d user: stephan tags: wasm-build-rework)
2024-07-24
23:58
wasm minimal build: strip authorizers and JSON support (saves approx 35kb). Strip vtab support from the JS bits but cannot yet strip it from the C bits because that requires a custom-configured sqlite3.c. (check-in: eb64d106 user: stephan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/wasm/GNUmakefile.

50
51
52
53
54
55
56

57
58
59
60
61
62
63
default: all
#default: quick
SHELL := $(shell which bash 2>/dev/null)
MAKEFILE := $(lastword $(MAKEFILE_LIST))
CLEAN_FILES :=
DISTCLEAN_FILES := ./--dummy--
release: oz


########################################################################
# JS_BUILD_NAMES exists for documentation purposes only. It enumerates
# the core build styles:
#
# - sqlite3 = canonical library build
#







>







50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
default: all
#default: quick
SHELL := $(shell which bash 2>/dev/null)
MAKEFILE := $(lastword $(MAKEFILE_LIST))
CLEAN_FILES :=
DISTCLEAN_FILES := ./--dummy--
release: oz
MAKING_CLEAN := $(if $(filter %clean,$(MAKECMDGOALS)),1,0)

########################################################################
# JS_BUILD_NAMES exists for documentation purposes only. It enumerates
# the core build styles:
#
# - sqlite3 = canonical library build
#
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#
# - node = for use by node.js for node.js, as opposed to by node.js on
#   behalf o browser-side code (use bundler-friendly for that). Note
#   that persistent storage (OPFS) is not available in these builds.
#
JS_BUILD_MODES := vanilla esm bunder-friendly node

########################################################################
# Emscripten SDK home dir and related binaries...
EMSDK_HOME ?= $(word 1,$(wildcard $(HOME)/emsdk $(HOME)/src/emsdk))
emcc.bin ?= $(word 1,$(wildcard $(EMSDK_HOME)/upstream/emscripten/emcc) $(shell which emcc))
ifeq (,$(emcc.bin))
  $(error Cannot find emcc.)
endif
emcc.version := $(shell "$(emcc.bin)" --version | sed -n 1p \
                  | sed -e 's/^.* \([3-9][^ ]*\) .*$$/\1/;')
ifeq (,$(emcc.version))
  $(warning Cannot determine emcc version. This might unduly impact build flags.)
else
  $(info using emcc version [$(emcc.version)])
endif

wasm-strip ?= $(shell which wasm-strip 2>/dev/null)
ifeq (,$(filter clean,$(MAKECMDGOALS)))
ifeq (,$(wasm-strip))
  $(info WARNING: *******************************************************************)
  $(info WARNING: builds using -O2/-O3/-Os/-Oz will minify WASM-exported names,)
  $(info WARNING: breaking _All The Things_. The workaround for that is to build)
  $(info WARNING: with -g3 (which explodes the file size) and then strip the debug)
  $(info WARNING: info after compilation, using wasm-strip, to shrink the wasm file.)
  $(info WARNING: wasm-strip was not found in the PATH so we cannot strip those.)
  $(info WARNING: If this build uses any optimization level higher than -O1 then)
  $(info WARNING: the ***resulting JS code WILL NOT BE USABLE***.)
  $(info WARNING: wasm-strip is part of the wabt package:)
  $(info WARNING:    https://github.com/WebAssembly/wabt)
  $(info WARNING: on Ubuntu-like systems it can be installed with:)
  $(info WARNING:    sudo apt install wabt)
  $(info WARNING: *******************************************************************)
endif
endif # 'make clean' check

ifeq (,$(wasm-strip))
  maybe-wasm-strip = echo "not wasm-stripping"
else
  maybe-wasm-strip = $(wasm-strip)
endif

########################################################################
# dir.top = the top dir of the canonical build tree, where
# sqlite3.[ch] live.
dir.top := ../..
# Maintenance reminder: some Emscripten flags require absolute paths
# but we want relative paths for most stuff simply to reduce
# noise. The $(abspath...) GNU make function can transform relative
# paths to absolute.
dir.wasm := $(patsubst %/,%,$(dir $(MAKEFILE)))
dir.api := api
dir.jacc := jaccwabyt
dir.common := common
dir.fiddle := fiddle
dir.fiddle-debug := fiddle-debug
dir.tool := $(dir.top)/tool
CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ $(dir.fiddle)/*~ \
  $(dir.fiddle-debug)/*

########################################################################
# dir.dout = output dir for deliverables.
#
# MAINTENANCE REMINDER: the output .js and .wasm files of certain emcc
# buildables must be in _this_ dir, rather than a subdir, or else
# parts of the generated code get confused and cannot load
# property. Specifically, when X.js loads X.wasm, whether or not X.js
# uses the correct path for X.wasm depends on how it's loaded: an HTML
# script tag will resolve it intuitively, whereas a Worker's call to
# importScripts() will not.  That's a fundamental incompatibility with
# how URL resolution in JS happens between those two contexts. See:
#
# https://zzz.buzz/2017/03/14/relative-uris-in-web-development/
#
# We unfortunately have no way, from Worker-initiated code, to
# automatically resolve the path from X.js to X.wasm.
#
# We have an "only slightly unsightly" solution for our main builds
# but it does not work for the WASMFS builds, so those builds have to
# be built to _this_ directory and can only run when the client app is
# loaded from the same directory.
dir.dout := $(dir.wasm)/jswasm
# dir.tmp = output dir for intermediary build files, as opposed to
# end-user deliverables.


dir.tmp := $(dir.wasm)/bld
CLEAN_FILES += $(dir.tmp)/* $(dir.dout)/*
ifeq (,$(wildcard $(dir.dout)))
  dir._tmp := $(shell mkdir -p $(dir.dout))
endif
ifeq (,$(wildcard $(dir.tmp)))
  dir._tmp := $(shell mkdir -p $(dir.tmp))
endif

########################################################################
# Set up sqlite3.c and sqlite3.h...
#
# To build with SEE (https://sqlite.org/see), either put sqlite3-see.c
# in $(dir.top) or pass sqlite3.c=PATH_TO_sqlite3-see.c to the $(MAKE)
# invocation. Note that only encryption modules with no 3rd-party







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<















<
|
|
<
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


>
>

|
|
<
<
<
<
<







83
84
85
86
87
88
89








































90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

105
106


107



















108
109
110
111
112
113
114





115
116
117
118
119
120
121
#
# - node = for use by node.js for node.js, as opposed to by node.js on
#   behalf o browser-side code (use bundler-friendly for that). Note
#   that persistent storage (OPFS) is not available in these builds.
#
JS_BUILD_MODES := vanilla esm bunder-friendly node









































########################################################################
# dir.top = the top dir of the canonical build tree, where
# sqlite3.[ch] live.
dir.top := ../..
# Maintenance reminder: some Emscripten flags require absolute paths
# but we want relative paths for most stuff simply to reduce
# noise. The $(abspath...) GNU make function can transform relative
# paths to absolute.
dir.wasm := $(patsubst %/,%,$(dir $(MAKEFILE)))
dir.api := api
dir.jacc := jaccwabyt
dir.common := common
dir.fiddle := fiddle
dir.fiddle-debug := fiddle-debug
dir.tool := $(dir.top)/tool

# Maintenance reminder: the names of $(dir.dout) and $(dir.tmp) must
# stay in sync with make-make.sh


#



















# dir.tmp = output dir for intermediary build files, as opposed to
# end-user deliverables.
dir.dout := $(dir.wasm)/jswasm
# dir.dout = output dir for deliverables
dir.tmp := $(dir.wasm)/bld
CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ $(dir.fiddle)/*~ \
  $(dir.fiddle-debug)/* $(dir.dout)/* $(dir.tmp)/*






########################################################################
# Set up sqlite3.c and sqlite3.h...
#
# To build with SEE (https://sqlite.org/see), either put sqlite3-see.c
# in $(dir.top) or pass sqlite3.c=PATH_TO_sqlite3-see.c to the $(MAKE)
# invocation. Note that only encryption modules with no 3rd-party
193
194
195
196
197
198
199
200
201





202


203
204










205

206
207
208
209
210
211
212
213
214
215
216
217
218
# A custom sqlite3.c must not have any spaces in its name.
# $(sqlite3.canonical.c) must point to the sqlite3.c in
# the sqlite3 canonical source tree, as that source file
# is required for certain utility and test code.
sqlite3.canonical.c := $(dir.top)/sqlite3.c
sqlite3.c ?= $(firstword $(wildcard $(dir.top)/sqlite3-see.c) $(sqlite3.canonical.c))
sqlite3.h := $(dir.top)/sqlite3.h
ifeq (,$(shell grep sqlite3_activate_see $(sqlite3.c) 2>/dev/null))
  SQLITE_C_IS_SEE := 0





else


  SQLITE_C_IS_SEE := 1
  $(info This is an SEE build.)










endif

# Most SQLITE_OPT flags are set in sqlite3-wasm.c but we need them
# made explicit here for building speedtest1.c.
SQLITE_OPT = \
  -DSQLITE_ENABLE_FTS5 \
  -DSQLITE_ENABLE_RTREE \
  -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
  -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION \
  -DSQLITE_ENABLE_STMTVTAB \
  -DSQLITE_ENABLE_DBPAGE_VTAB \
  -DSQLITE_ENABLE_DBSTAT_VTAB \
  -DSQLITE_ENABLE_BYTECODE_VTAB \
  -DSQLITE_ENABLE_OFFSET_SQL_FUNC \
  -DSQLITE_OMIT_LOAD_EXTENSION \







|
<
>
>
>
>
>
|
>
>
|
<
>
>
>
>
>
>
>
>
>
>

>
|
|



<







129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
# A custom sqlite3.c must not have any spaces in its name.
# $(sqlite3.canonical.c) must point to the sqlite3.c in
# the sqlite3 canonical source tree, as that source file
# is required for certain utility and test code.
sqlite3.canonical.c := $(dir.top)/sqlite3.c
sqlite3.c ?= $(firstword $(wildcard $(dir.top)/sqlite3-see.c) $(sqlite3.canonical.c))
sqlite3.h := $(dir.top)/sqlite3.h


########################################################################@
# It's important that sqlite3.h be built to completion before any
# other parts of the build run, thus we use .NOTPARALLEL to disable
# parallel build of that file and its dependants.
.NOTPARALLEL: $(sqlite3.h)
$(sqlite3.h):
	$(MAKE) -C $(dir.top) sqlite3.c
$(sqlite3.c): $(sqlite3.h)


# .cache.make is generated by a shell script and holds certain parts
# of the makefile, some of which are relatively expensive to calculate
# on each run (that is, they can take a human-visible amount of time).
ifeq (0,$(MAKING_CLEAN))
.cache.make: $(sqlite3.c) $(sqlite3.canonical.c) $(MAKEFILE) make-make.sh
	rm -f $@
	$(SHELL) make-make.sh "$(sqlite3.c)" > $@
	chmod -w $@
-include .cache.make
.cache.make: $(emcc.bin)
endif
CLEAN_FILES += .cache.make

# Common options for building sqlite3-wasm.c and speedtest1.c.
SQLITE_OPT = \
  -DSQLITE_ENABLE_FTS5 \
  -DSQLITE_ENABLE_RTREE \

  -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION \
  -DSQLITE_ENABLE_STMTVTAB \
  -DSQLITE_ENABLE_DBPAGE_VTAB \
  -DSQLITE_ENABLE_DBSTAT_VTAB \
  -DSQLITE_ENABLE_BYTECODE_VTAB \
  -DSQLITE_ENABLE_OFFSET_SQL_FUNC \
  -DSQLITE_OMIT_LOAD_EXTENSION \
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# minimal=1 disables all "extraneous" stuff from sqlite3-wasm.c, the
# goal being to create a WASM file with only the core APIs.
minimal ?= 0
ifeq (1,$(minimal))
  SQLITE_OPT += -DSQLITE_WASM_MINIMAL
endif

########################################################################@
# It's important that sqlite3.h be built to completion before any
# other parts of the build run, thus we use .NOTPARALLEL to disable
# parallel build of that file and its dependants.
.NOTPARALLEL: $(sqlite3.h)
$(sqlite3.h):
	$(MAKE) -C $(dir.top) sqlite3.c
$(sqlite3.c): $(sqlite3.h)

.PHONY: clean distclean
clean:
	-rm -f $(CLEAN_FILES)
distclean: clean
	-rm -f $(DISTCLEAN_FILES)

ifeq (release,$(filter release,$(MAKECMDGOALS)))







<
<
<
<
<
<
<
<
<







188
189
190
191
192
193
194









195
196
197
198
199
200
201
# minimal=1 disables all "extraneous" stuff from sqlite3-wasm.c, the
# goal being to create a WASM file with only the core APIs.
minimal ?= 0
ifeq (1,$(minimal))
  SQLITE_OPT += -DSQLITE_WASM_MINIMAL
endif










.PHONY: clean distclean
clean:
	-rm -f $(CLEAN_FILES)
distclean: clean
	-rm -f $(DISTCLEAN_FILES)

ifeq (release,$(filter release,$(MAKECMDGOALS)))
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
define C-PP.FILTER
# Create $2 from $1 using $(bin.c-pp)
# $1 = Input file: c-pp -f $(1).js
# $2 = Output file: c-pp -o $(2).js
# $3 = optional c-pp -D... flags
$(2): $(1) $$(MAKEFILE) $$(bin.c-pp)
	$$(bin.c-pp) -f $(1) -o $$@ $(3) $(C-PP.FILTER.global)
CLEAN_FILES += $(2)
endef
# /end C-PP.FILTER
########################################################################

# cflags.common = C compiler flags for all builds
cflags.common :=  -I. -I$(dir $(sqlite3.c))
# emcc.WASM_BIGINT = 1 for BigInt (C int64) support, else 0.  The API







|







309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
define C-PP.FILTER
# Create $2 from $1 using $(bin.c-pp)
# $1 = Input file: c-pp -f $(1).js
# $2 = Output file: c-pp -o $(2).js
# $3 = optional c-pp -D... flags
$(2): $(1) $$(MAKEFILE) $$(bin.c-pp)
	$$(bin.c-pp) -f $(1) -o $$@ $(3) $(C-PP.FILTER.global)
#CLEAN_FILES += $(2)
endef
# /end C-PP.FILTER
########################################################################

# cflags.common = C compiler flags for all builds
cflags.common :=  -I. -I$(dir $(sqlite3.c))
# emcc.WASM_BIGINT = 1 for BigInt (C int64) support, else 0.  The API
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# runtime speeds, but not by a large enough factor to rule out use of
# -Oz when small deliverable size is a priority.
########################################################################

########################################################################
# EXPORTED_FUNCTIONS.* = files for use with Emscripten's
# -sEXPORTED_FUNCTION flag.
EXPORTED_FUNCTIONS.api.core := $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-core)
EXPORTED_FUNCTIONS.api.in := $(EXPORTED_FUNCTIONS.api.core)
ifeq (1,$(SQLITE_C_IS_SEE))
  EXPORTED_FUNCTIONS.api.in += $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-see)
endif
ifeq (0,$(minimal))
  EXPORTED_FUNCTIONS.api.in += \
    $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-auth) \
    $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-preupdate) \
    $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-session) \
    $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-vtab)
else
  $(info ========================================)
  $(info This is a minimal-mode build)
  $(info ========================================)
endif
EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api
$(EXPORTED_FUNCTIONS.api): $(EXPORTED_FUNCTIONS.api.in) $(sqlite3.c) $(MAKEFILE)







|


|


|
<
<
<
<







359
360
361
362
363
364
365
366
367
368
369
370
371
372




373
374
375
376
377
378
379
# runtime speeds, but not by a large enough factor to rule out use of
# -Oz when small deliverable size is a priority.
########################################################################

########################################################################
# EXPORTED_FUNCTIONS.* = files for use with Emscripten's
# -sEXPORTED_FUNCTION flag.
EXPORTED_FUNCTIONS.api.core := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-core
EXPORTED_FUNCTIONS.api.in := $(EXPORTED_FUNCTIONS.api.core)
ifeq (1,$(SQLITE_C_IS_SEE))
  EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-see
endif
ifeq (0,$(minimal))
  EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras




else
  $(info ========================================)
  $(info This is a minimal-mode build)
  $(info ========================================)
endif
EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api
$(EXPORTED_FUNCTIONS.api): $(EXPORTED_FUNCTIONS.api.in) $(sqlite3.c) $(MAKEFILE)
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
      dotwasm=; \
      sed -i -e 's/$(1)-$(2).wasm/$(1).wasm/g' $$@ || exit $$$$?; \
      ;; \
	esac; \
	ls -la $$$$dotwasm $$@
all: $(5)
#quick: $(5)
CLEAN_FILES += $(4) $(5)
endef
# ^^^ /SETUP_LIB_BUILD_MODE
########################################################################
sqlite3-api.js := $(dir.dout)/sqlite3-api.js
sqlite3.js := $(dir.dout)/sqlite3.js
sqlite3-api.mjs := $(dir.dout)/sqlite3-api.mjs
sqlite3.mjs := $(dir.dout)/sqlite3.mjs







|







840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
      dotwasm=; \
      sed -i -e 's/$(1)-$(2).wasm/$(1).wasm/g' $$@ || exit $$$$?; \
      ;; \
	esac; \
	ls -la $$$$dotwasm $$@
all: $(5)
#quick: $(5)
#CLEAN_FILES += $(4) $(5)
endef
# ^^^ /SETUP_LIB_BUILD_MODE
########################################################################
sqlite3-api.js := $(dir.dout)/sqlite3-api.js
sqlite3.js := $(dir.dout)/sqlite3.js
sqlite3-api.mjs := $(dir.dout)/sqlite3-api.mjs
sqlite3.mjs := $(dir.dout)/sqlite3.mjs
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
# imports needed by the wasm file, so they have to be built
# together. i.e.  we're building $(sqlite3.wasm) multiple times, but
# that's unavoidable (and harmless, just a waste of build time).
$(sqlite3.wasm): $(sqlite3.js)
$(sqlite3.mjs): $(sqlite3.js)
$(sqlite3-bundler-friendly.mjs): $(sqlite3.mjs)
$(sqlite3-node.mjs): $(sqlite3.mjs)
CLEAN_FILES += $(sqlite3.wasm)

########################################################################
# We need separate copies of certain supplementary JS files for the
# bundler-friendly build. Concretely, any supplemental JS files which
# themselves use importScripts() or Workers or URL() constructors
# which refer to other in-tree (m)JS files quire a bundler-friendly
# copy.







|







896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
# imports needed by the wasm file, so they have to be built
# together. i.e.  we're building $(sqlite3.wasm) multiple times, but
# that's unavoidable (and harmless, just a waste of build time).
$(sqlite3.wasm): $(sqlite3.js)
$(sqlite3.mjs): $(sqlite3.js)
$(sqlite3-bundler-friendly.mjs): $(sqlite3.mjs)
$(sqlite3-node.mjs): $(sqlite3.mjs)
#CLEAN_FILES += $(sqlite3.wasm)

########################################################################
# We need separate copies of certain supplementary JS files for the
# bundler-friendly build. Concretely, any supplemental JS files which
# themselves use importScripts() or Workers or URL() constructors
# which refer to other in-tree (m)JS files quire a bundler-friendly
# copy.
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
        -o $@ $(speedtest1.cfiles) -lm
	$(maybe-wasm-strip) $(speedtest1.wasm)
	chmod -x $(speedtest1.wasm)
	ls -la $@ $(speedtest1.wasm)

speedtest1: $(speedtest1.js)
all: speedtest1
CLEAN_FILES += $(speedtest1.js) $(speedtest1.wasm)
# end speedtest1.js
########################################################################

########################################################################
# tester1 is the main unit and regression test application and needs
# to be able to run in 4 separate modes to cover the primary
# client-side use cases:







|







1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
        -o $@ $(speedtest1.cfiles) -lm
	$(maybe-wasm-strip) $(speedtest1.wasm)
	chmod -x $(speedtest1.wasm)
	ls -la $@ $(speedtest1.wasm)

speedtest1: $(speedtest1.js)
all: speedtest1
#CLEAN_FILES += $(speedtest1.js) $(speedtest1.wasm)
# end speedtest1.js
########################################################################

########################################################################
# tester1 is the main unit and regression test application and needs
# to be able to run in 4 separate modes to cover the primary
# client-side use cases:
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184

# Only add wasmfs if wasmfs.enable=1 or we're running (dist)clean
ifneq (,$(filter wasmfs,$(MAKECMDGOALS)))
wasmfs.enable ?= 1
else
# Unconditionally enable wasmfs for [dist]clean so that the wasmfs
# sub-make can clean up.
wasmfs.enable ?= $(if $(filter %clean,$(MAKECMDGOALS)),1,0)
endif
ifeq (1,$(wasmfs.enable))
# wasmfs build disabled 2022-10-19 per /chat discussion.
# OPFS-over-wasmfs was initially a stopgap measure and a convenient
# point of comparison for the OPFS sqlite3_vfs's performance, but it
# currently doubles our deliverables and build maintenance burden for
# little benefit.







|







1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122

# Only add wasmfs if wasmfs.enable=1 or we're running (dist)clean
ifneq (,$(filter wasmfs,$(MAKECMDGOALS)))
wasmfs.enable ?= 1
else
# Unconditionally enable wasmfs for [dist]clean so that the wasmfs
# sub-make can clean up.
wasmfs.enable ?= $(MAKING_CLEAN)
endif
ifeq (1,$(wasmfs.enable))
# wasmfs build disabled 2022-10-19 per /chat discussion.
# OPFS-over-wasmfs was initially a stopgap measure and a convenient
# point of comparison for the OPFS sqlite3_vfs's performance, but it
# currently doubles our deliverables and build maintenance burden for
# little benefit.

Deleted ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-auth.

1
_sqlite3_set_authorizer
<


Name change from ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-session to ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras.








1
2
3
4
5
6
7







_sqlite3changegroup_add
_sqlite3changegroup_add_strm
_sqlite3changegroup_delete
_sqlite3changegroup_new
_sqlite3changegroup_output
_sqlite3changegroup_output_strm
_sqlite3changeset_apply
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
_sqlite3_set_authorizer
_sqlite3_preupdate_blobwrite
_sqlite3_preupdate_count
_sqlite3_preupdate_depth
_sqlite3_preupdate_hook
_sqlite3_preupdate_new
_sqlite3_preupdate_old
_sqlite3changegroup_add
_sqlite3changegroup_add_strm
_sqlite3changegroup_delete
_sqlite3changegroup_new
_sqlite3changegroup_output
_sqlite3changegroup_output_strm
_sqlite3changeset_apply
36
37
38
39
40
41
42











_sqlite3session_indirect
_sqlite3session_isempty
_sqlite3session_memory_used
_sqlite3session_object_config
_sqlite3session_patchset
_sqlite3session_patchset_strm
_sqlite3session_table_filter


















>
>
>
>
>
>
>
>
>
>
>
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
_sqlite3session_indirect
_sqlite3session_isempty
_sqlite3session_memory_used
_sqlite3session_object_config
_sqlite3session_patchset
_sqlite3session_patchset_strm
_sqlite3session_table_filter
_sqlite3_create_module
_sqlite3_create_module_v2
_sqlite3_declare_vtab
_sqlite3_vtab_collation
_sqlite3_vtab_distinct
_sqlite3_vtab_in
_sqlite3_vtab_in_first
_sqlite3_vtab_in_next
_sqlite3_vtab_nochange
_sqlite3_vtab_on_conflict
_sqlite3_vtab_rhs_value

Deleted ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-preupdate.

1
2
3
4
5
6
_sqlite3_preupdate_blobwrite
_sqlite3_preupdate_count
_sqlite3_preupdate_depth
_sqlite3_preupdate_hook
_sqlite3_preupdate_new
_sqlite3_preupdate_old
<
<
<
<
<
<












Deleted ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-vtab.

1
2
3
4
5
6
7
8
9
10
11
_sqlite3_create_module
_sqlite3_create_module_v2
_sqlite3_declare_vtab
_sqlite3_vtab_collation
_sqlite3_vtab_distinct
_sqlite3_vtab_in
_sqlite3_vtab_in_first
_sqlite3_vtab_in_next
_sqlite3_vtab_nochange
_sqlite3_vtab_on_conflict
_sqlite3_vtab_rhs_value
<
<
<
<
<
<
<
<
<
<
<






















Changes to ext/wasm/api/sqlite3-api-glue.c-pp.js.

332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
        }),
        "*"/*pUserData*/
      ]]
    );
  }/* sqlite3_set_authorizer() */

  if(false && wasm.compileOptionUsed('SQLITE_ENABLE_NORMALIZE')){
    /* ^^^ "the problem" is that this is an option feature and the
       build-time function-export list does not currently take
       optional features into account. */
    wasm.bindingSignatures.push(["sqlite3_normalized_sql", "string", "sqlite3_stmt*"]);
  }

//#if enable-see
  if(wasm.exports.sqlite3_key_v2 instanceof Function){







|







332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
        }),
        "*"/*pUserData*/
      ]]
    );
  }/* sqlite3_set_authorizer() */

  if(false && wasm.compileOptionUsed('SQLITE_ENABLE_NORMALIZE')){
    /* ^^^ "the problem" is that this is an optional feature and the
       build-time function-export list does not currently take
       optional features into account. */
    wasm.bindingSignatures.push(["sqlite3_normalized_sql", "string", "sqlite3_stmt*"]);
  }

//#if enable-see
  if(wasm.exports.sqlite3_key_v2 instanceof Function){

Added ext/wasm/make-make.sh.









































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/bash
########################################################################
# Emits the makefile code for .cache.make. Any makefile bits which are
# potentially expensive to calculate on every build but rarely change
# should be emitted from here.
#
# Arguments:
#
#  $1 = path to sqlite3.c. Default: ../../sqlite3.c
#
########################################################################

function die(){
    local rc=$1
    shift
    echo "\$(error $0 failed: $@)"
    # ^^^ Ensure that if this output is being redirected, the
    # resulting makefile will fail loudly instead of just being
    # truncated.
    echo "Error: $@" 1>&2
    exit $rc
}

SQLITE3_C="${1-../../sqlite3.c}"

echo "# GENERATED makefile code. DO NOT EDIT."

if grep sqlite3_activate_see "$SQLITE3_C" &>/dev/null; then
  echo 'SQLITE_C_IS_SEE := 1'
  echo '$(info This is an SEE build)'
else
  echo 'SQLITE_C_IS_SEE := 0'
fi

########################################################################
# Locate the emcc (Emscripten) binary...
EMCC_BIN=$(which emcc)
if [[ x = "x${EMCC_BIN}" ]]; then
  if [[ x != "x${EMSDK_HOME}" ]]; then
    EMCC_BIN="${EMSDK_HOME}/upstream/emscripten/emcc"
  fi
fi
if [[ x = "x${EMCC_BIN}" ]]; then
  die 1 "Cannot find emcc binary in PATH or EMSDK_HOME."
fi
[[ -x "${EMCC_BIN}" ]] || die 1 "emcc is not executable"
echo "emcc.bin := ${EMCC_BIN}"
echo "emcc.version :=" $("${EMCC_BIN}" --version | sed -n 1p \
                           | sed -e 's/^.* \([3-9][^ ]*\) .*$/\1/;')
echo '$(info using emcc version [$(emcc.version)])'

#########################################################################
# wasm-strip binary...
WASM_STRIP_BIN=$(which wasm-strip 2>/dev/null)
echo "wasm-strip ?= ${WASM_STRIP_BIN}"
if [[ x = "x${WASM_STRIP_BIN}" ]]; then
cat <<EOF
maybe-wasm-strip = echo "not wasm-stripping"
ifeq (,\$(filter clean,\$(MAKECMDGOALS)))'
  \$(info WARNING: *******************************************************************)
  \$(info WARNING: builds using -O2/-O3/-Os/-Oz will minify WASM-exported names,)
  \$(info WARNING: breaking _All The Things_. The workaround for that is to build)
  \$(info WARNING: with -g3 (which explodes the file size) and then strip the debug)
  \$(info WARNING: info after compilation, using wasm-strip, to shrink the wasm file.)
  \$(info WARNING: wasm-strip was not found in the PATH so we cannot strip those.)
  \$(info WARNING: If this build uses any optimization level higher than -O1 then)
  \$(info WARNING: the ***resulting JS code WILL NOT BE USABLE***.)
  \$(info WARNING: wasm-strip is part of the wabt package:)
  \$(info WARNING:    https://github.com/WebAssembly/wabt)
  \$(info WARNING: on Ubuntu-like systems it can be installed with:)
  \$(info WARNING:    sudo apt install wabt)
  \$(info WARNING: *******************************************************************)
endif
EOF
else
  echo 'maybe-wasm-strip = $(wasm-strip)'
fi


dir_dout=jswasm
dir_tmp=bld
for d in $dir_dout $dir_tmp; do
  [ -d $d ] || mkdir -p $d
done

Changes to ext/wasm/tester1.c-pp.js.

3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
      db.close();
    })

  ////////////////////////////////////////////////////////////////////////
  T.g('Bug Reports')
    .t({
      name: 'Delete via bound parameter in subquery',
      predicate: function(sqlite3){
        const d = new sqlite3.oo1.DB();
        try{
          d.exec("create virtual table f using fts5(x)");
          return true;
        }catch(e){
          return "FTS5 is not available";
        }finally{
          d.close();
        }
      },
      test: function(sqlite3){
        // Testing https://sqlite.org/forum/forumpost/40ce55bdf5
        // with the exception that that post uses "external content"
        // for the FTS index.
        const db = new sqlite3.oo1.DB();//(':memory:','wt');
        db.exec([
          "create virtual table f using fts5 (path);",







<
<
<
<
<
<
|
<
<
<
<







3296
3297
3298
3299
3300
3301
3302






3303




3304
3305
3306
3307
3308
3309
3310
      db.close();
    })

  ////////////////////////////////////////////////////////////////////////
  T.g('Bug Reports')
    .t({
      name: 'Delete via bound parameter in subquery',






      predicate: ()=>wasm.compileOptionUsed('ENABLE_FTS5') || "FTS5 is not available",




      test: function(sqlite3){
        // Testing https://sqlite.org/forum/forumpost/40ce55bdf5
        // with the exception that that post uses "external content"
        // for the FTS index.
        const db = new sqlite3.oo1.DB();//(':memory:','wt');
        db.exec([
          "create virtual table f using fts5 (path);",

Changes to ext/wasm/wasmfs.make.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

#dir.wasmfs := $(dir.wasm)
dir.wasmfs := $(dir.dout)
sqlite3-wasmfs.js     := $(dir.wasmfs)/sqlite3-wasmfs.js
sqlite3-wasmfs.mjs    := $(dir.wasmfs)/sqlite3-wasmfs.mjs
sqlite3-wasmfs.wasm   := $(dir.wasmfs)/sqlite3-wasmfs.wasm

CLEAN_FILES += $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.wasm) \
    $(subst .js,.worker.js,$(sqlite3-wasmfs.js)) \
    $(sqlite3-wasmfs.mjs) \
    $(subst .mjs,.worker.mjs,$(sqlite3-wasmfs.mjs))

########################################################################
# emcc flags for .c/.o.
cflags.sqlite3-wasmfs :=
cflags.sqlite3-wasmfs += -std=c99 -fPIC
cflags.sqlite3-wasmfs += -pthread
cflags.sqlite3-wasmfs += -DSQLITE_ENABLE_WASMFS








<
<
<
<
<







10
11
12
13
14
15
16





17
18
19
20
21
22
23

#dir.wasmfs := $(dir.wasm)
dir.wasmfs := $(dir.dout)
sqlite3-wasmfs.js     := $(dir.wasmfs)/sqlite3-wasmfs.js
sqlite3-wasmfs.mjs    := $(dir.wasmfs)/sqlite3-wasmfs.mjs
sqlite3-wasmfs.wasm   := $(dir.wasmfs)/sqlite3-wasmfs.wasm






########################################################################
# emcc flags for .c/.o.
cflags.sqlite3-wasmfs :=
cflags.sqlite3-wasmfs += -std=c99 -fPIC
cflags.sqlite3-wasmfs += -pthread
cflags.sqlite3-wasmfs += -DSQLITE_ENABLE_WASMFS

105
106
107
108
109
110
111
112
113
114
115
        -o $@ $(speedtest1.cfiles) -lm
	@$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,1)
	$(maybe-wasm-strip) $(speedtest1-wasmfs.wasm)
	chmod -x $(speedtest1-wasmfs.wasm)
	ls -la $@ $(speedtest1-wasmfs.wasm)

wasmfs: $(speedtest1-wasmfs.mjs)
CLEAN_FILES += $(speedtest1-wasmfs.mjs) $(speedtest1-wasmfs.wasm) \
     $(subst .js,.worker.js,$(speedtest1-wasmfs.mjs))
# end speedtest1.js
########################################################################







<
<


100
101
102
103
104
105
106


107
108
        -o $@ $(speedtest1.cfiles) -lm
	@$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,1)
	$(maybe-wasm-strip) $(speedtest1-wasmfs.wasm)
	chmod -x $(speedtest1-wasmfs.wasm)
	ls -la $@ $(speedtest1-wasmfs.wasm)

wasmfs: $(speedtest1-wasmfs.mjs)


# end speedtest1.js
########################################################################