SQLite

Check-in [b029c406]
Login

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

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wasm-build-rework
Files: files | file ages | folders
SHA3-256: b029c4067943e366a9b25b8303136fab10822bd771ea4658ac4cd716ff4a0d8f
User & Date: stephan 2024-07-25 14:00:26
Context
2024-07-25
16:21
Strip progress handlers and window functions from the wasm bare-bones (formerly 'minimal') JS bits, noting that we can't yet use OMIT_WINDOWFUNC (for the C parts) without a custom amalgamation. Currently at 604kb. (check-in: ec02e923 user: stephan tags: wasm-build-rework)
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)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/wasm/GNUmakefile.

11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
#
#  default, all = build in dev mode
#
#  o0, o1, o2, o3, os, oz = full clean/rebuild with the -Ox level indicated
#      by the target name. Rebuild is necessary for all components to get
#      the desired optimization level.
#

#  quick, q = do just a minimal build (sqlite3.js/wasm, tester1) for
#      faster development-mode turnaround.
#
#  dist = create end user deliverables. Add dist.build=oX to build
#      with a specific optimization level, where oX is one of the
#      above-listed o? or qo? target names.
#
#  snapshot = like dist, but uses a zip file name which clearly
#      marks it as a prerelease/snapshot build.







>
|
|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#
#  default, all = build in dev mode
#
#  o0, o1, o2, o3, os, oz = full clean/rebuild with the -Ox level indicated
#      by the target name. Rebuild is necessary for all components to get
#      the desired optimization level.
#
#  quick, q = do just build the essentials for testing
#      (sqlite3.js/wasm, tester1) for faster development-mode
#      turnaround.
#
#  dist = create end user deliverables. Add dist.build=oX to build
#      with a specific optimization level, where oX is one of the
#      above-listed o? or qo? target names.
#
#  snapshot = like dist, but uses a zip file name which clearly
#      marks it as a prerelease/snapshot build.
41
42
43
44
45
46
47
48

49
50
51
52



53
54
55
56
57





58
59
60
61
62
63
64
#
# 1) Consolidate the code generation for sqlite3*.*js into a script
#    which generates the makefile code, rather than using $(call) and
#    $(eval), or at least centralize the setup of the numerous vars
#    related to each build variant $(JS_BUILD_MODES). (Update: an
#    external script was attempted but generating properly-escaped
#    makefile code from within a shell script is even less legible
#    than the $(eval) indirection going on in this file.)

#
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
#







|
>



|
>
>
>

|

<

>
>
>
>
>







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
#
# 1) Consolidate the code generation for sqlite3*.*js into a script
#    which generates the makefile code, rather than using $(call) and
#    $(eval), or at least centralize the setup of the numerous vars
#    related to each build variant $(JS_BUILD_MODES). (Update: an
#    external script was attempted but generating properly-escaped
#    makefile code from within a shell script is even less legible
#    than the $(eval) indirection going on in this file.) (Update 2:
#    a second attempt at that make yet another mess of it.)
#
default: all
#default: quick
SHELL := $(firstword $(wildcard /usr/local/bin/bash /usr/bin/bash /bin/bash))
ifeq (,$(SHELL))
  $(error Cannot find the bash shell)
endif
MAKEFILE := $(lastword $(MAKEFILE_LIST))
CLEAN_FILES := .gen.make
DISTCLEAN_FILES := ./--dummy--

MAKING_CLEAN := $(if $(filter %clean,$(MAKECMDGOALS)),1,0)
.PHONY: clean distclean
clean:
	-rm -f $(CLEAN_FILES)
distclean: clean
	-rm -f $(DISTCLEAN_FILES)

########################################################################
# JS_BUILD_NAMES exists for documentation purposes only. It enumerates
# the core build styles:
#
# - sqlite3 = canonical library build
#
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201

202
203
204
205
206
207

208

209
210
211
212
213
214
215
# 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 \
  -DSQLITE_OMIT_DEPRECATED \
  -DSQLITE_OMIT_UTF16 \
  -DSQLITE_OMIT_SHARED_CACHE \



  -DSQLITE_THREADSAFE=0 \
  -DSQLITE_TEMP_STORE=2 \
  -DSQLITE_OS_KV_OPTIONAL=1 \
  '-DSQLITE_DEFAULT_UNIX_VFS="unix-none"' \
  -DSQLITE_USE_URI=1 \
  -DSQLITE_WASM_ENABLE_C_TESTS \
  -DSQLITE_C=$(sqlite3.c)

#SQLITE_OPT += -DSQLITE_DEBUG
# Enabling SQLITE_DEBUG will break sqlite3_wasm_vfs_create_file()
# (and thus sqlite3_js_vfs_create_file()). Those functions are
# deprecated and alternatives are in place, but this crash behavior
# can be used to find errant uses of sqlite3_js_vfs_create_file()
# in client code.

########################################################################
# 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)))

  ifeq (,$(wasm-strip))
    $(error Cannot make release-quality binary because wasm-strip is not available. \
            See notes in the warning above)
  endif
else
  $(info Development build. Use '$(MAKE) release' for a smaller release build.)

endif


########################################################################
# Adding custom C code via sqlite3_wasm_extra_init.c:
#
# If the canonical build process finds the file
# sqlite3_wasm_extra_init.c in the main wasm build directory, it
# arranges to include that file in the build of sqlite3.wasm and







>
|


>
>
>

|

|

|
<

|
>
>
>


>

|
|
|
|
|
>
>
|
|
|
>
>
>
>



|
>
>
>







>










<


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

<
>

>







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
186
187
188
189
190
191
192
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





219

220
221



222

223
224
225
226
227
228
229
230
231
232
# 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)

########################################################################
# .gen.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).
#
# .gen.make is also home to make-side vars which are needed for
# generating makefile code via shell code.
ifeq (0,$(MAKING_CLEAN))
.gen.make: $(MAKEFILE) $(sqlite3.c)
	rm -f $@
	$(SHELL) make-make.sh $(sqlite3.c) > $@
	chmod -w $@
-include .gen.make

endif

ifeq (,$(filter release snapshot,$(MAKECMDGOALS)))
  $(info Development build. Use 'release' or 'snapshot' target for a smaller release build.)
endif

# Common options for building sqlite3-wasm.c and speedtest1.c.
# Explicit ENABLEs...
SQLITE_OPT = \
  -DSQLITE_ENABLE_BYTECODE_VTAB \
  -DSQLITE_ENABLE_DBPAGE_VTAB \
  -DSQLITE_ENABLE_DBSTAT_VTAB \
  -DSQLITE_ENABLE_FTS5 \
  -DSQLITE_ENABLE_MATH_FUNCTIONS \
  -DSQLITE_ENABLE_OFFSET_SQL_FUNC \
  -DSQLITE_ENABLE_PREUPDATE_HOOK \
  -DSQLITE_ENABLE_RTREE \
  -DSQLITE_ENABLE_SESSION \
  -DSQLITE_ENABLE_STMTVTAB \
  -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION

# Explicit OMITs...
SQLITE_OPT += \
  -DSQLITE_OMIT_LOAD_EXTENSION \
  -DSQLITE_OMIT_DEPRECATED \
  -DSQLITE_OMIT_UTF16 \
  -DSQLITE_OMIT_SHARED_CACHE

# Misc. build-time config options...
SQLITE_OPT += \
  -DSQLITE_THREADSAFE=0 \
  -DSQLITE_TEMP_STORE=2 \
  -DSQLITE_OS_KV_OPTIONAL=1 \
  '-DSQLITE_DEFAULT_UNIX_VFS="unix-none"' \
  -DSQLITE_USE_URI=1 \
  -DSQLITE_WASM_ENABLE_C_TESTS \
  -DSQLITE_C=$(sqlite3.c)

#SQLITE_OPT += -DSQLITE_DEBUG
# Enabling SQLITE_DEBUG will break sqlite3_wasm_vfs_create_file()
# (and thus sqlite3_js_vfs_create_file()). Those functions are
# deprecated and alternatives are in place, but this crash behavior
# can be used to find errant uses of sqlite3_js_vfs_create_file()
# in client code.

########################################################################
# minimal=1 disables all "extraneous" stuff from sqlite3-wasm.c, the
# goal being to create a WASM file with only the core APIs.

ifeq (1,$(minimal))
  SQLITE_OPT += -DSQLITE_WASM_MINIMAL

  # SQLITE_WASM_MINIMAL tells sqlite3-wasm.c to explicitly omit





  # a bunch of stuff, in the interest of keeping the wasm file size

  # down.
  wasm-minimal := 1



else

  wasm-minimal := 0
endif
undefine minimal

########################################################################
# Adding custom C code via sqlite3_wasm_extra_init.c:
#
# If the canonical build process finds the file
# sqlite3_wasm_extra_init.c in the main wasm build directory, it
# arranges to include that file in the build of sqlite3.wasm and
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# 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)
	cat $(EXPORTED_FUNCTIONS.api.in) > $@

########################################################################







|



|







381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# 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,$(wasm-minimal))
  EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras
else
  $(info ========================================)
  $(info This is a minimal-mode build. It is missing many features.)
  $(info ========================================)
endif
EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api
$(EXPORTED_FUNCTIONS.api): $(EXPORTED_FUNCTIONS.api.in) $(sqlite3.c) $(MAKEFILE)
	cat $(EXPORTED_FUNCTIONS.api.in) > $@

########################################################################
404
405
406
407
408
409
410

411
412

413
414
415
416
417
418
419
sqlite3-api.jses += $(sqlite3-api-build-version.js)
# sqlite3-api-oo1 = the oo1 API:
sqlite3-api.jses += $(dir.api)/sqlite3-api-oo1.c-pp.js
# sqlite3-api-worker = the Worker1 API:
sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.c-pp.js
# sqlite3-vfs-helper = helper APIs for VFSes:
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-helper.c-pp.js

# sqlite3-vtab-helper = helper APIs for VTABLEs:
sqlite3-api.jses += $(dir.api)/sqlite3-vtab-helper.c-pp.js

# sqlite3-vfs-opfs = the first OPFS VFS:
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs.c-pp.js
# sqlite3-vfs-opfs-sahpool = the second OPFS VFS:
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs-sahpool.c-pp.js
# sqlite3-api-cleanup.js = "finalizes" the build and cleans up
# any extraneous global symbols which are needed temporarily
# by the previous files.







>
|
|
>







421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
sqlite3-api.jses += $(sqlite3-api-build-version.js)
# sqlite3-api-oo1 = the oo1 API:
sqlite3-api.jses += $(dir.api)/sqlite3-api-oo1.c-pp.js
# sqlite3-api-worker = the Worker1 API:
sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.c-pp.js
# sqlite3-vfs-helper = helper APIs for VFSes:
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-helper.c-pp.js
ifeq (0,$(wasm-minimal))
  # sqlite3-vtab-helper = helper APIs for VTABLEs:
  sqlite3-api.jses += $(dir.api)/sqlite3-vtab-helper.c-pp.js
endif
# sqlite3-vfs-opfs = the first OPFS VFS:
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs.c-pp.js
# sqlite3-vfs-opfs-sahpool = the second OPFS VFS:
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs-sahpool.c-pp.js
# sqlite3-api-cleanup.js = "finalizes" the build and cleans up
# any extraneous global symbols which are needed temporarily
# by the previous files.

Changes to ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core.

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
_sqlite3_data_count
_sqlite3_db_filename
_sqlite3_db_handle
_sqlite3_db_name
_sqlite3_db_readonly
_sqlite3_db_status
_sqlite3_deserialize
_sqlite3_drop_modules
_sqlite3_errcode
_sqlite3_errmsg
_sqlite3_error_offset
_sqlite3_errstr
_sqlite3_exec
_sqlite3_expanded_sql
_sqlite3_extended_errcode







<







45
46
47
48
49
50
51

52
53
54
55
56
57
58
_sqlite3_data_count
_sqlite3_db_filename
_sqlite3_db_handle
_sqlite3_db_name
_sqlite3_db_readonly
_sqlite3_db_status
_sqlite3_deserialize

_sqlite3_errcode
_sqlite3_errmsg
_sqlite3_error_offset
_sqlite3_errstr
_sqlite3_exec
_sqlite3_expanded_sql
_sqlite3_extended_errcode

Changes to ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras.

46
47
48
49
50
51
52

53
54
55
56
57
58
59
_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







>







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
_sqlite3session_object_config
_sqlite3session_patchset
_sqlite3session_patchset_strm
_sqlite3session_table_filter
_sqlite3_create_module
_sqlite3_create_module_v2
_sqlite3_declare_vtab
_sqlite3_drop_modules
_sqlite3_vtab_collation
_sqlite3_vtab_distinct
_sqlite3_vtab_in
_sqlite3_vtab_in_first
_sqlite3_vtab_in_next
_sqlite3_vtab_nochange
_sqlite3_vtab_on_conflict

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

381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
    /* Careful! Short version: de/serialize() are problematic because they
       might use a different allocator than the user for managing the
       deserialized block. de/serialize() are ONLY safe to use with
       sqlite3_malloc(), sqlite3_free(), and its 64-bit variants. Because
       of this, the canonical builds of sqlite3.wasm/js guarantee that
       sqlite3.wasm.alloc() and friends use those allocators. Custom builds
       may not guarantee that, however. */,
    ["sqlite3_drop_modules", "int", ["sqlite3*", "**"]],
    ["sqlite3_last_insert_rowid", "i64", ["sqlite3*"]],
    ["sqlite3_malloc64", "*","i64"],
    ["sqlite3_msize", "i64", "*"],
    ["sqlite3_overload_function", "int", ["sqlite3*","string","int"]],
    ["sqlite3_realloc64", "*","*", "i64"],
    ["sqlite3_result_int64", undefined, "*", "i64"],
    ["sqlite3_result_zeroblob64", "int", "*", "i64"],







<







381
382
383
384
385
386
387

388
389
390
391
392
393
394
    /* Careful! Short version: de/serialize() are problematic because they
       might use a different allocator than the user for managing the
       deserialized block. de/serialize() are ONLY safe to use with
       sqlite3_malloc(), sqlite3_free(), and its 64-bit variants. Because
       of this, the canonical builds of sqlite3.wasm/js guarantee that
       sqlite3.wasm.alloc() and friends use those allocators. Custom builds
       may not guarantee that, however. */,

    ["sqlite3_last_insert_rowid", "i64", ["sqlite3*"]],
    ["sqlite3_malloc64", "*","i64"],
    ["sqlite3_msize", "i64", "*"],
    ["sqlite3_overload_function", "int", ["sqlite3*","string","int"]],
    ["sqlite3_realloc64", "*","*", "i64"],
    ["sqlite3_result_int64", undefined, "*", "i64"],
    ["sqlite3_result_zeroblob64", "int", "*", "i64"],
418
419
420
421
422
423
424

425
426
427
428
429
430
431
  if( wasm.bigIntEnabled && !!wasm.exports.sqlite3_declare_vtab ){
    wasm.bindingSignatures.int64.push(
      ["sqlite3_create_module", "int",
       ["sqlite3*","string","sqlite3_module*","*"]],
      ["sqlite3_create_module_v2", "int",
       ["sqlite3*","string","sqlite3_module*","*","*"]],
      ["sqlite3_declare_vtab", "int", ["sqlite3*", "string:flexible"]],

      ["sqlite3_vtab_collation","string","sqlite3_index_info*","int"],
      ["sqlite3_vtab_distinct","int", "sqlite3_index_info*"],
      ["sqlite3_vtab_in","int", "sqlite3_index_info*", "int", "int"],
      ["sqlite3_vtab_in_first", "int", "sqlite3_value*", "**"],
      ["sqlite3_vtab_in_next", "int", "sqlite3_value*", "**"],
      /*["sqlite3_vtab_config" is variadic and requires a hand-written
        proxy.] */







>







417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
  if( wasm.bigIntEnabled && !!wasm.exports.sqlite3_declare_vtab ){
    wasm.bindingSignatures.int64.push(
      ["sqlite3_create_module", "int",
       ["sqlite3*","string","sqlite3_module*","*"]],
      ["sqlite3_create_module_v2", "int",
       ["sqlite3*","string","sqlite3_module*","*","*"]],
      ["sqlite3_declare_vtab", "int", ["sqlite3*", "string:flexible"]],
      ["sqlite3_drop_modules", "int", ["sqlite3*", "**"]],
      ["sqlite3_vtab_collation","string","sqlite3_index_info*","int"],
      ["sqlite3_vtab_distinct","int", "sqlite3_index_info*"],
      ["sqlite3_vtab_in","int", "sqlite3_index_info*", "int", "int"],
      ["sqlite3_vtab_in_first", "int", "sqlite3_value*", "**"],
      ["sqlite3_vtab_in_next", "int", "sqlite3_value*", "**"],
      /*["sqlite3_vtab_config" is variadic and requires a hand-written
        proxy.] */

Changes to ext/wasm/api/sqlite3-wasm.c.

10
11
12
13
14
15
16


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
** -I/path flag to tell the compiler where to find both of those
** files, then compile this file. For example:
**
** emcc -o sqlite3.wasm ... -I/path/to/sqlite3-c-and-h sqlite3-wasm.c
*/
#define SQLITE_WASM
#ifdef SQLITE_WASM_ENABLE_C_TESTS


/*
** Code blocked off by SQLITE_WASM_TESTS is intended solely for use in
** unit/regression testing. They may be safely omitted from
** client-side builds. The main unit test script, tester1.js, will
** skip related tests if it doesn't find the corresponding functions
** in the WASM exports.
*/
#  define SQLITE_WASM_TESTS 1
#else
#  define SQLITE_WASM_TESTS 0
#endif

/*
** Threading and file locking: JS is single-threaded. Each Worker
** thread is a separate instance of the JS engine so can never access
** the same db handle as another thread, thus multi-threading support
** is unnecessary in the library. Because the filesystems are virtual







>
>

|
|




<

|







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
** -I/path flag to tell the compiler where to find both of those
** files, then compile this file. For example:
**
** emcc -o sqlite3.wasm ... -I/path/to/sqlite3-c-and-h sqlite3-wasm.c
*/
#define SQLITE_WASM
#ifdef SQLITE_WASM_ENABLE_C_TESTS
#  undef SQLITE_WASM_ENABLE_C_TESTS
#  define SQLITE_WASM_ENABLE_C_TESTS 1
/*
** Code blocked off by SQLITE_WASM_ENABLE_C_TESTS is intended solely
** for use in unit/regression testing. They may be safely omitted from
** client-side builds. The main unit test script, tester1.js, will
** skip related tests if it doesn't find the corresponding functions
** in the WASM exports.
*/

#else
#  define SQLITE_WASM_ENABLE_C_TESTS 0
#endif

/*
** Threading and file locking: JS is single-threaded. Each Worker
** thread is a separate instance of the JS engine so can never access
** the same db handle as another thread, thus multi-threading support
** is unnecessary in the library. Because the filesystems are virtual
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
** Unconditionally enable API_ARMOR in the WASM build. It ensures that
** public APIs behave predictable in the face of passing illegal NULLs
** or ranges which might otherwise invoke undefined behavior.
*/
#undef SQLITE_ENABLE_API_ARMOR
#define SQLITE_ENABLE_API_ARMOR 1

#ifndef SQLITE_ENABLE_BYTECODE_VTAB
#  define SQLITE_ENABLE_BYTECODE_VTAB 1
#endif
#ifndef SQLITE_ENABLE_DBPAGE_VTAB
#  define SQLITE_ENABLE_DBPAGE_VTAB 1
#endif
#ifndef SQLITE_ENABLE_DBSTAT_VTAB
#  define SQLITE_ENABLE_DBSTAT_VTAB 1
#endif
#ifndef SQLITE_ENABLE_EXPLAIN_COMMENTS
#  define SQLITE_ENABLE_EXPLAIN_COMMENTS 1
#endif
#ifndef SQLITE_ENABLE_FTS5
#  define SQLITE_ENABLE_FTS5 1
#endif
#ifndef SQLITE_ENABLE_MATH_FUNCTIONS
#  define SQLITE_ENABLE_MATH_FUNCTIONS 1
#endif
#ifndef SQLITE_ENABLE_OFFSET_SQL_FUNC
#  define SQLITE_ENABLE_OFFSET_SQL_FUNC 1
#endif
#ifndef SQLITE_ENABLE_PREUPDATE_HOOK
#  define SQLITE_ENABLE_PREUPDATE_HOOK 1 /*required by session extension*/
#endif
#ifndef SQLITE_ENABLE_RTREE
#  define SQLITE_ENABLE_RTREE 1
#endif
#ifndef SQLITE_ENABLE_SESSION
#  define SQLITE_ENABLE_SESSION 1
#endif
#ifndef SQLITE_ENABLE_STMTVTAB
#  define SQLITE_ENABLE_STMTVTAB 1
#endif
#ifndef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
#  define SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
#endif

/**********************************************************************/
/* SQLITE_O... */
#ifndef SQLITE_OMIT_DEPRECATED
# define SQLITE_OMIT_DEPRECATED 1
#endif
#ifndef SQLITE_OMIT_LOAD_EXTENSION
# define SQLITE_OMIT_LOAD_EXTENSION 1







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







89
90
91
92
93
94
95





































96
97
98
99
100
101
102
** Unconditionally enable API_ARMOR in the WASM build. It ensures that
** public APIs behave predictable in the face of passing illegal NULLs
** or ranges which might otherwise invoke undefined behavior.
*/
#undef SQLITE_ENABLE_API_ARMOR
#define SQLITE_ENABLE_API_ARMOR 1






































/**********************************************************************/
/* SQLITE_O... */
#ifndef SQLITE_OMIT_DEPRECATED
# define SQLITE_OMIT_DEPRECATED 1
#endif
#ifndef SQLITE_OMIT_LOAD_EXTENSION
# define SQLITE_OMIT_LOAD_EXTENSION 1
209
210
211
212
213
214
215






216
217
218
219
220
221
222
/*Requires a custom sqlite3.c
#  undef SQLITE_OMIT_VIRTUALTABLE
#  define SQLITE_OMIT_VIRTUALTABLE
*/
#  undef SQLITE_OMIT_JSON
#  define SQLITE_OMIT_JSON
#endif







#include <assert.h>

/*
** SQLITE_WASM_EXPORT is functionally identical to EMSCRIPTEN_KEEPALIVE
** but is not Emscripten-specific. It explicitly marks functions for
** export into the target wasm file without requiring explicit listing







>
>
>
>
>
>







173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*Requires a custom sqlite3.c
#  undef SQLITE_OMIT_VIRTUALTABLE
#  define SQLITE_OMIT_VIRTUALTABLE
*/
#  undef SQLITE_OMIT_JSON
#  define SQLITE_OMIT_JSON
#endif

#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_MINIMAL)
#  define SQLITE_WASM_HAS_VTAB 1
#else
#  define SQLITE_WASM_HAS_VTAB 0
#endif

#include <assert.h>

/*
** SQLITE_WASM_EXPORT is functionally identical to EMSCRIPTEN_KEEPALIVE
** but is not Emscripten-specific. It explicitly marks functions for
** export into the target wasm file without requiring explicit listing
408
409
410
411
412
413
414
415
416
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
442
    }else{
      sqlite3ErrorWithMsg(db, err_code, NULL);
    }
  }
  return err_code;
}

#if SQLITE_WASM_TESTS
struct WasmTestStruct {
  int v4;
  void * ppV;
  const char * cstr;
  int64_t v8;
  void (*xFunc)(void*);
};
typedef struct WasmTestStruct WasmTestStruct;
SQLITE_WASM_EXPORT
void sqlite3__wasm_test_struct(WasmTestStruct * s){
  if(s){
    s->v4 *= 2;
    s->v8 = s->v4 * 2;
    s->ppV = s;
    s->cstr = __FILE__;
    if(s->xFunc) s->xFunc(s);
  }
  return;
}
#endif /* SQLITE_WASM_TESTS */

/*
** This function is NOT part of the sqlite3 public API. It is strictly
** for use by the sqlite project's own JS/WASM bindings. Unlike the
** rest of the sqlite3 API, this part requires C99 for snprintf() and
** variadic macros.
**







|



















|







378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
    }else{
      sqlite3ErrorWithMsg(db, err_code, NULL);
    }
  }
  return err_code;
}

#if SQLITE_WASM_ENABLE_C_TESTS
struct WasmTestStruct {
  int v4;
  void * ppV;
  const char * cstr;
  int64_t v8;
  void (*xFunc)(void*);
};
typedef struct WasmTestStruct WasmTestStruct;
SQLITE_WASM_EXPORT
void sqlite3__wasm_test_struct(WasmTestStruct * s){
  if(s){
    s->v4 *= 2;
    s->v8 = s->v4 * 2;
    s->ppV = s;
    s->cstr = __FILE__;
    if(s->xFunc) s->xFunc(s);
  }
  return;
}
#endif /* SQLITE_WASM_ENABLE_C_TESTS */

/*
** This function is NOT part of the sqlite3 public API. It is strictly
** for use by the sqlite project's own JS/WASM bindings. Unlike the
** rest of the sqlite3 API, this part requires C99 for snprintf() and
** variadic macros.
**
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
  DefGroup(version) {
    DefInt(SQLITE_VERSION_NUMBER);
    DefStr(SQLITE_VERSION);
    DefStr(SQLITE_SOURCE_ID);
  } _DefGroup;

  DefGroup(vtab) {
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_MINIMAL)
    DefInt(SQLITE_INDEX_SCAN_UNIQUE);
    DefInt(SQLITE_INDEX_CONSTRAINT_EQ);
    DefInt(SQLITE_INDEX_CONSTRAINT_GT);
    DefInt(SQLITE_INDEX_CONSTRAINT_LE);
    DefInt(SQLITE_INDEX_CONSTRAINT_LT);
    DefInt(SQLITE_INDEX_CONSTRAINT_GE);
    DefInt(SQLITE_INDEX_CONSTRAINT_MATCH);







|







933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
  DefGroup(version) {
    DefInt(SQLITE_VERSION_NUMBER);
    DefStr(SQLITE_VERSION);
    DefStr(SQLITE_SOURCE_ID);
  } _DefGroup;

  DefGroup(vtab) {
#if SQLITE_WASM_HAS_VTAB
    DefInt(SQLITE_INDEX_SCAN_UNIQUE);
    DefInt(SQLITE_INDEX_CONSTRAINT_EQ);
    DefInt(SQLITE_INDEX_CONSTRAINT_GT);
    DefInt(SQLITE_INDEX_CONSTRAINT_LE);
    DefInt(SQLITE_INDEX_CONSTRAINT_LT);
    DefInt(SQLITE_INDEX_CONSTRAINT_GE);
    DefInt(SQLITE_INDEX_CONSTRAINT_MATCH);
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
    DefInt(SQLITE_VTAB_DIRECTONLY);
    DefInt(SQLITE_VTAB_USES_ALL_SCHEMAS);
    DefInt(SQLITE_ROLLBACK);
    //DefInt(SQLITE_IGNORE); // Also used by sqlite3_authorizer() callback
    DefInt(SQLITE_FAIL);
    //DefInt(SQLITE_ABORT); // Also an error code
    DefInt(SQLITE_REPLACE);
#endif /*!SQLITE_OMIT_VIRTUALTABLE*/
  } _DefGroup;

#undef DefGroup
#undef DefStr
#undef DefInt
#undef _DefGroup








|







961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
    DefInt(SQLITE_VTAB_DIRECTONLY);
    DefInt(SQLITE_VTAB_USES_ALL_SCHEMAS);
    DefInt(SQLITE_ROLLBACK);
    //DefInt(SQLITE_IGNORE); // Also used by sqlite3_authorizer() callback
    DefInt(SQLITE_FAIL);
    //DefInt(SQLITE_ABORT); // Also an error code
    DefInt(SQLITE_REPLACE);
#endif /*SQLITE_WASM_HAS_VTAB*/
  } _DefGroup;

#undef DefGroup
#undef DefStr
#undef DefInt
#undef _DefGroup

1106
1107
1108
1109
1110
1111
1112

1113
1114
1115
1116
1117
1118
1119
      M(xWrite,   "i(sss)");
      M(xDelete,  "i(ss)");
      M(nKeySize, "i");
    } _StructBinder;
#undef CurrentStruct



#define CurrentStruct sqlite3_vtab
    StructBinder {
      M(pModule, "p");
      M(nRef,    "i");
      M(zErrMsg, "p");
    } _StructBinder;
#undef CurrentStruct







>







1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
      M(xWrite,   "i(sss)");
      M(xDelete,  "i(ss)");
      M(nKeySize, "i");
    } _StructBinder;
#undef CurrentStruct


#if SQLITE_WASM_HAS_VTAB
#define CurrentStruct sqlite3_vtab
    StructBinder {
      M(pModule, "p");
      M(nRef,    "i");
      M(zErrMsg, "p");
    } _StructBinder;
#undef CurrentStruct
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
      M(xRelease,       "i(pi)");
      M(xRollbackTo,    "i(pi)");
      // ^^^ v2. v3+ follows...
      M(xShadowName,    "i(s)");
    } _StructBinder;
#undef CurrentStruct

#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_MINIMAL)
    /**
     ** Workaround: in order to map the various inner structs from
     ** sqlite3_index_info, we have to uplift those into constructs we
     ** can access by type name. These structs _must_ match their
     ** in-sqlite3_index_info counterparts byte for byte.
    */
    typedef struct {







<







1122
1123
1124
1125
1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
      M(xRelease,       "i(pi)");
      M(xRollbackTo,    "i(pi)");
      // ^^^ v2. v3+ follows...
      M(xShadowName,    "i(s)");
    } _StructBinder;
#undef CurrentStruct


    /**
     ** Workaround: in order to map the various inner structs from
     ** sqlite3_index_info, we have to uplift those into constructs we
     ** can access by type name. These structs _must_ match their
     ** in-sqlite3_index_info counterparts byte for byte.
    */
    typedef struct {
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
      M(estimatedCost,      "d");
      M(estimatedRows,      "j");
      M(idxFlags,           "i");
      M(colUsed,            "j");
    } _StructBinder;
#undef CurrentStruct

#endif /*!SQLITE_OMIT_VIRTUALTABLE*/

#if SQLITE_WASM_TESTS
#define CurrentStruct WasmTestStruct
    StructBinder {
      M(v4,    "i");
      M(cstr,  "s");
      M(ppV,   "p");
      M(v8,    "j");
      M(xFunc, "v(p)");
    } _StructBinder;
#undef CurrentStruct
#endif

  } out( "]"/*structs*/);

  out("}"/*top-level object*/);
  *zPos = 0;
  aBuffer[0] = '{'/*end of the race-condition workaround*/;
  return aBuffer;







|

|









|







1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
      M(estimatedCost,      "d");
      M(estimatedRows,      "j");
      M(idxFlags,           "i");
      M(colUsed,            "j");
    } _StructBinder;
#undef CurrentStruct

#endif /*SQLITE_WASM_HAS_VTAB*/

#if SQLITE_WASM_ENABLE_C_TESTS
#define CurrentStruct WasmTestStruct
    StructBinder {
      M(v4,    "i");
      M(cstr,  "s");
      M(ppV,   "p");
      M(v8,    "j");
      M(xFunc, "v(p)");
    } _StructBinder;
#undef CurrentStruct
#endif /*SQLITE_WASM_ENABLE_C_TESTS*/

  } out( "]"/*structs*/);

  out("}"/*top-level object*/);
  *zPos = 0;
  aBuffer[0] = '{'/*end of the race-condition workaround*/;
  return aBuffer;
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
** I/O methods and associated state.
*/
SQLITE_WASM_EXPORT
sqlite3_kvvfs_methods * sqlite3__wasm_kvvfs_methods(void){
  return &sqlite3KvvfsMethods;
}

#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_MINIMAL)
/*
** This function is NOT part of the sqlite3 public API. It is strictly
** for use by the sqlite project's own JS/WASM bindings.
**
** This is a proxy for the variadic sqlite3_vtab_config() which passes
** its argument on, or not, to sqlite3_vtab_config(), depending on the
** value of its 2nd argument. Returns the result of







|







1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
** I/O methods and associated state.
*/
SQLITE_WASM_EXPORT
sqlite3_kvvfs_methods * sqlite3__wasm_kvvfs_methods(void){
  return &sqlite3KvvfsMethods;
}

#if SQLITE_WASM_HAS_VTAB
/*
** This function is NOT part of the sqlite3 public API. It is strictly
** for use by the sqlite project's own JS/WASM bindings.
**
** This is a proxy for the variadic sqlite3_vtab_config() which passes
** its argument on, or not, to sqlite3_vtab_config(), depending on the
** value of its 2nd argument. Returns the result of
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
    return sqlite3_vtab_config(pDb, op);
  case SQLITE_VTAB_CONSTRAINT_SUPPORT:
    return sqlite3_vtab_config(pDb, op, arg);
  default:
    return SQLITE_MISUSE;
  }
}
#endif /*!SQLITE_OMIT_VIRTUALTABLE*/

/*
** This function is NOT part of the sqlite3 public API. It is strictly
** for use by the sqlite project's own JS/WASM bindings.
**
** Wrapper for the variants of sqlite3_db_config() which take
** (int,int*) variadic args.







|







1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
    return sqlite3_vtab_config(pDb, op);
  case SQLITE_VTAB_CONSTRAINT_SUPPORT:
    return sqlite3_vtab_config(pDb, op, arg);
  default:
    return SQLITE_MISUSE;
  }
}
#endif /*SQLITE_WASM_HAS_VTAB*/

/*
** This function is NOT part of the sqlite3 public API. It is strictly
** for use by the sqlite project's own JS/WASM bindings.
**
** Wrapper for the variants of sqlite3_db_config() which take
** (int,int*) variadic args.
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
int sqlite3__wasm_init_wasmfs(const char *zUnused){
  //emscripten_console_warn("WASMFS OPFS is not compiled in.");
  if(zUnused){/*unused*/}
  return SQLITE_NOTFOUND;
}
#endif /* __EMSCRIPTEN__ && SQLITE_ENABLE_WASMFS */

#if SQLITE_WASM_TESTS

SQLITE_WASM_EXPORT
int sqlite3__wasm_test_intptr(int * p){
  return *p = *p * 2;
}

SQLITE_WASM_EXPORT







|







1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
int sqlite3__wasm_init_wasmfs(const char *zUnused){
  //emscripten_console_warn("WASMFS OPFS is not compiled in.");
  if(zUnused){/*unused*/}
  return SQLITE_NOTFOUND;
}
#endif /* __EMSCRIPTEN__ && SQLITE_ENABLE_WASMFS */

#if SQLITE_WASM_ENABLE_C_TESTS

SQLITE_WASM_EXPORT
int sqlite3__wasm_test_intptr(int * p){
  return *p = *p * 2;
}

SQLITE_WASM_EXPORT
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972



}

SQLITE_WASM_EXPORT
int sqlite3__wasm_SQLTester_strglob(const char *zGlob, const char *z){
 return !sqlite3__wasm_SQLTester_strnotglob(zGlob, z);
}

#endif /* SQLITE_WASM_TESTS */

#undef SQLITE_WASM_EXPORT










|


>
>
>
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
}

SQLITE_WASM_EXPORT
int sqlite3__wasm_SQLTester_strglob(const char *zGlob, const char *z){
 return !sqlite3__wasm_SQLTester_strnotglob(zGlob, z);
}

#endif /* SQLITE_WASM_ENABLE_C_TESTS */

#undef SQLITE_WASM_EXPORT
#undef SQLITE_WASM_HAS_VTAB
#undef SQLITE_WASM_MINIMAL
#undef SQLITE_WASM_ENABLE_C_TESTS

Changes to ext/wasm/make-make.sh.

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
    # 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







>
>
>
|
>
>
>
>










>

















>




















>
>
>


|

|
>

<
<
>
>
>
|


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
85
86
87
88
89
90
91
92


93
94
95
96
97
98
    # truncated.
    echo "Error: $@" 1>&2
    exit $rc
}

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

separator='########################################################################'

cat <<EOF
# GENERATED makefile code. DO NOT EDIT.
# Generated by $0 on $(date)
_GEN_MAKE := \$(lastword \$(MAKEFILE_LIST))
\$(_GEN_MAKE): ${SQLITE3_C} $0
EOF

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...
echo $separator
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...
echo $separator
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
ifneq (,\$(filter release snapshot,\$(MAKECMDGOALS)))
  \$(error Cannot make release-quality binary because wasm-strip is not available.)
endif
EOF
else
echo 'maybe-wasm-strip = $(wasm-strip)'
fi
# /$(wasm-strip)
########################################################################



########################################################################
# Make necessary dirs. Note that these need to align with their names
# in the main makefile.
for d in jswasm bld; do
  [ -d $d ] || mkdir -p $d
done

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

2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
        }
      }
    }/* jaccwabyt-specific tests */)

  ////////////////////////////////////////////////////////////////////////
    .t({
      name: 'virtual table #1: eponymous w/ manual exception handling',
      predicate: ()=>!!capi.sqlite3_create_module || "Missing vtab support",
      test: function(sqlite3){
        const VT = sqlite3.vtab;
        const tmplCols = Object.assign(Object.create(null),{
          A: 0, B: 1
        });
        /**
           The vtab demonstrated here is a JS-ification of







|







2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
        }
      }
    }/* jaccwabyt-specific tests */)

  ////////////////////////////////////////////////////////////////////////
    .t({
      name: 'virtual table #1: eponymous w/ manual exception handling',
      predicate: (sqlite3)=>!!sqlite3.capi.sqlite3_vtab || "Missing vtab support",
      test: function(sqlite3){
        const VT = sqlite3.vtab;
        const tmplCols = Object.assign(Object.create(null),{
          A: 0, B: 1
        });
        /**
           The vtab demonstrated here is a JS-ification of
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
          .assert(2009===list[list.length-1][1]);
      }
    })/*custom vtab #1*/

  ////////////////////////////////////////////////////////////////////////
    .t({
      name: 'virtual table #2: non-eponymous w/ automated exception wrapping',
      predicate: ()=>!!capi.sqlite3_create_module || "Missing vtab support",
      test: function(sqlite3){
        const VT = sqlite3.vtab;
        const tmplCols = Object.assign(Object.create(null),{
          A: 0, B: 1
        });
        /**
           The vtab demonstrated here is a JS-ification of







|







2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
          .assert(2009===list[list.length-1][1]);
      }
    })/*custom vtab #1*/

  ////////////////////////////////////////////////////////////////////////
    .t({
      name: 'virtual table #2: non-eponymous w/ automated exception wrapping',
      predicate: (sqlite3)=>!!sqlite3.capi.sqlite3_vtab || "Missing vtab support",
      test: function(sqlite3){
        const VT = sqlite3.vtab;
        const tmplCols = Object.assign(Object.create(null),{
          A: 0, B: 1
        });
        /**
           The vtab demonstrated here is a JS-ification of
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);",







|







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') || "Missing FTS5",
      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);",