mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Considerable wasm/js build cleanups and reworking. Remove wasmfs builds from the end-user deliverables and disable the wasmfs build by default, per /chat discussion, as it doubles our deliverable count for only marginal gain. Attempt to move the sqlite3.js/wasm files into subdirectories but rediscovered that that breaks loading in Worker mode because URI resolution of the wasm files differs depending on whether the main script is loaded from a script tag or a Worker.
FossilOrigin-Name: 5b23e0675efdd2f1ea7b4f5836a579e8d6aa8a25b3f1a6a950520ad845ff01bb
This commit is contained in:
@ -1,15 +0,0 @@
|
||||
FS
|
||||
addFunction
|
||||
allocateUTF8OnStack
|
||||
ccall
|
||||
cwrap
|
||||
getValue
|
||||
intArrayFromString
|
||||
lengthBytesUTF8
|
||||
removeFunction
|
||||
setValue
|
||||
stackAlloc
|
||||
stackRestore
|
||||
stackSave
|
||||
stringToUTF8Array
|
||||
wasmMemory
|
@ -1,4 +1,4 @@
|
||||
########################################################################
|
||||
#######################################################################
|
||||
# This GNU makefile drives the build of the sqlite3 WASM
|
||||
# components. It is not part of the canonical build process.
|
||||
#
|
||||
@ -22,8 +22,10 @@
|
||||
########################################################################
|
||||
SHELL := $(shell which bash 2>/dev/null)
|
||||
MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
||||
CLEAN_FILES :=
|
||||
DISTCLEAN_FILES := ./--dummy--
|
||||
default: all
|
||||
release: default
|
||||
release: oz
|
||||
|
||||
# Emscripten SDK home dir and related binaries...
|
||||
EMSDK_HOME ?= $(word 1,$(wildcard $(HOME)/src/emsdk $(HOME)/emsdk))
|
||||
@ -58,15 +60,50 @@ else
|
||||
endif
|
||||
|
||||
dir.top := ../..
|
||||
# Reminder: some Emscripten flags require absolute paths
|
||||
dir.wasm := $(patsubst %/,%,$(dir $(abspath $(MAKEFILE))))
|
||||
# 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.tool := $(dir.top)/tool
|
||||
CLEAN_FILES := *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~
|
||||
DISTCLEAN_FILES := ./-dummy
|
||||
########################################################################
|
||||
# MAINTENANCE REMINDER: the output .js and .wasm files of emcc 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.
|
||||
#
|
||||
# In case we ever find a solution to that which does not require
|
||||
# duplicating the X.js files only to swap out the path to X.wasm for
|
||||
# the loading-from-worker case...
|
||||
#
|
||||
# dir.dout = output dir for deliverables.
|
||||
dir.dout := $(dir.wasm)
|
||||
# dir.tmp = output dir for intermediary build files, as opposed to
|
||||
# end-user deliverables.
|
||||
dir.tmp := $(dir.wasm)/bld
|
||||
#CLEAN_FILES += $(wildcard $(dir.dout)/*) $(wildcard $(dir.tmp)/*)
|
||||
ifeq (,$(wildcard $(dir.dout)))
|
||||
dir._tmp := $(shell mkdir -p $(dir.dout))
|
||||
endif
|
||||
ifeq (,$(wildcard $(dir.tmp)))
|
||||
dir._tmp := $(shell mkdir -p $(dir.tmp))
|
||||
endif
|
||||
|
||||
cflags.common := -I. -I.. -I$(dir.top)
|
||||
CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~
|
||||
emcc_enable_bigint ?= 1
|
||||
sqlite3.c := $(dir.top)/sqlite3.c
|
||||
sqlite3.h := $(dir.top)/sqlite3.h
|
||||
@ -149,6 +186,8 @@ else
|
||||
endif
|
||||
|
||||
version-info := $(dir.wasm)/version-info
|
||||
# ^^^^ NOT in $(dir.tmp) because we need it to survive the cleanup
|
||||
# process for the dist build to work properly.
|
||||
$(version-info): $(dir.wasm)/version-info.c $(sqlite3.h) $(MAKEFILE)
|
||||
$(CC) -O0 -I$(dir.top) -o $@ $<
|
||||
DISTCLEAN_FILES += $(version-info)
|
||||
@ -158,15 +197,16 @@ $(stripccomments): $(stripccomments).c $(MAKEFILE)
|
||||
$(CC) -o $@ $<
|
||||
DISTCLEAN_FILES += $(stripccomments)
|
||||
|
||||
EXPORTED_FUNCTIONS.api.in := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api
|
||||
|
||||
EXPORTED_FUNCTIONS.api: $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE)
|
||||
EXPORTED_FUNCTIONS.api.in := $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api)
|
||||
EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api
|
||||
$(EXPORTED_FUNCTIONS.api): $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE)
|
||||
cat $(EXPORTED_FUNCTIONS.api.in) > $@
|
||||
CLEAN_FILES += EXPORTED_FUNCTIONS.api
|
||||
|
||||
sqlite3-license-version.js := sqlite3-license-version.js
|
||||
sqlite3-license-version.js := $(dir.tmp)/sqlite3-license-version.js
|
||||
sqlite3-license-version-header.js := $(dir.api)/sqlite3-license-version-header.js
|
||||
sqlite3-api-build-version.js := $(dir.api)/sqlite3-api-build-version.js
|
||||
sqlite3-api-build-version.js := $(dir.tmp)/sqlite3-api-build-version.js
|
||||
# sqlite3-api.jses = the list of JS files which make up $(sqlite3-api.js), in
|
||||
# the order they need to be assembled.
|
||||
sqlite3-api.jses := $(sqlite3-license-version.js)
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-api-prologue.js
|
||||
sqlite3-api.jses += $(dir.common)/whwasmutil.js
|
||||
@ -178,10 +218,7 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.js
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-api-opfs.js
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js
|
||||
|
||||
sqlite3-api.js := sqlite3-api.js
|
||||
CLEAN_FILES += $(sqlite3-api.js)
|
||||
CLEAN_FILES += $(sqlite3-license-version.js)
|
||||
CLEAN_FILES += $(sqlite3-api-build-version.js)
|
||||
sqlite3-api.js := $(dir.tmp)/sqlite3-api.js
|
||||
$(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE)
|
||||
@echo "Making $@..."
|
||||
@for i in $(sqlite3-api.jses); do \
|
||||
@ -190,7 +227,7 @@ $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE)
|
||||
echo "/* END FILE: $$i */"; \
|
||||
done > $@
|
||||
|
||||
$(sqlite3-api-build-version.js): $(version-info)
|
||||
$(sqlite3-api-build-version.js): $(version-info) $(MAKEFILE)
|
||||
@echo "Making $@..."
|
||||
@{ \
|
||||
echo 'self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){'; \
|
||||
@ -204,8 +241,7 @@ $(sqlite3-api-build-version.js): $(version-info)
|
||||
# --post-js and --pre-js are emcc flags we use to append/prepend JS to
|
||||
# the generated emscripten module file.
|
||||
pre-js.js := $(dir.api)/pre-js.js
|
||||
post-js.js := post-js.js
|
||||
CLEAN_FILES += $(post-js.js)
|
||||
post-js.js := $(dir.tmp)/post-js.js
|
||||
post-jses := \
|
||||
$(dir.api)/post-js-header.js \
|
||||
$(sqlite3-api.js) \
|
||||
@ -222,7 +258,7 @@ extern-pre-js.js := $(dir.api)/extern-pre-js.js
|
||||
pre-post-common.flags := \
|
||||
--post-js=$(post-js.js) \
|
||||
--extern-post-js=$(extern-post-js.js) \
|
||||
--extern-pre-js=$(dir.wasm)/$(sqlite3-license-version.js)
|
||||
--extern-pre-js=$(sqlite3-license-version.js)
|
||||
pre-post-jses.deps := $(post-js.js) \
|
||||
$(extern-post-js.js) $(extern-pre-js.js) $(sqlite3-license-version.js)
|
||||
$(sqlite3-license-version.js): $(sqlite3.h) $(sqlite3-license-version-header.js) $(MAKEFILE)
|
||||
@ -275,12 +311,11 @@ emcc.jsflags += -sMODULARIZE
|
||||
emcc.jsflags += -sSTRICT_JS
|
||||
emcc.jsflags += -sDYNAMIC_EXECUTION=0
|
||||
emcc.jsflags += -sNO_POLYFILL
|
||||
emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.api
|
||||
emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(EXPORTED_FUNCTIONS.api)
|
||||
emcc.exportedRuntimeMethods := \
|
||||
-sEXPORTED_RUNTIME_METHODS=FS,wasmMemory,allocateUTF8OnStack
|
||||
-sEXPORTED_RUNTIME_METHODS=FS,wasmMemory
|
||||
# FS ==> stdio/POSIX I/O proxies
|
||||
# wasmMemory ==> required by our code for use with -sIMPORTED_MEMORY
|
||||
# allocateUTF8OnStack => for kvvfs internals
|
||||
emcc.jsflags += $(emcc.exportedRuntimeMethods)
|
||||
emcc.jsflags += -sUSE_CLOSURE_COMPILER=0
|
||||
emcc.jsflags += -sIMPORTED_MEMORY
|
||||
@ -312,7 +347,7 @@ emcc.jsflags += -Wno-limited-postlink-optimizations
|
||||
emcc.jsflags += -sERROR_ON_UNDEFINED_SYMBOLS=0
|
||||
emcc.jsflags += -sLLD_REPORT_UNDEFINED
|
||||
#emcc.jsflags += --allow-undefined
|
||||
emcc.jsflags += --import-undefined
|
||||
#emcc.jsflags += --import-undefined
|
||||
#emcc.jsflags += --unresolved-symbols=import-dynamic --experimental-pic
|
||||
#emcc.jsflags += --experimental-pic --unresolved-symbols=ingore-all --import-undefined
|
||||
#emcc.jsflags += --unresolved-symbols=ignore-all
|
||||
@ -340,36 +375,22 @@ emcc.jsflags += -sWASM_BIGINT=$(emcc_enable_bigint)
|
||||
# debugging info, _huge_.
|
||||
########################################################################
|
||||
|
||||
########################################################################
|
||||
# Maintenance reminder: the output .js and .wasm files of emcc must be
|
||||
# in _this_ dir, rather than a subdir, or else parts of the generated
|
||||
# code get confused and cannot load property (namely, the
|
||||
# sqlite3.worker.js generated in conjunction with -sWASMFS).
|
||||
sqlite3.js := sqlite3.js
|
||||
sqlite3.wasm := sqlite3.wasm
|
||||
sqlite3-wasm.o := $(dir.api)/sqlite3-wasm.o
|
||||
$(sqlite3-wasm.o): emcc.cflags += $(SQLITE_OPT)
|
||||
$(sqlite3-wasm.o): $(dir.top)/sqlite3.c
|
||||
sqlite3.js := $(dir.dout)/sqlite3.js
|
||||
sqlite3.wasm := $(dir.dout)/sqlite3.wasm
|
||||
sqlite3-wasm.c := $(dir.api)/sqlite3-wasm.c
|
||||
########################################################################
|
||||
# call-wasm-c-compile sets up build rules
|
||||
# for $1.o. $1 must be the name of a C file (with extension).
|
||||
define call-wasm-c-compile
|
||||
$(1).o := $$(subst .c,.o,$(1))
|
||||
sqlite3.wasm.obj += $$($(1).o)
|
||||
$$($(1).o): $$(MAKEFILE) $(1)
|
||||
$$(emcc.bin) $$(emcc_opt_full) $$(emcc.flags) $$(emcc.cflags) -c $(1) -o $$@
|
||||
CLEAN_FILES += $$($(1).o)
|
||||
endef
|
||||
$(foreach c,$(sqlite3-wasm.c),$(eval $(call call-wasm-c-compile,$(c))))
|
||||
# sqlite3-wasm.o vs sqlite3-wasm.c: building against the latter
|
||||
# (predictably) results in a slightly faster binary, but we're close
|
||||
# enough to the target speed requirements that the 500ms makes a
|
||||
# difference. Thus we build all binaries against sqlite3-wasm.c
|
||||
# instead of building a shared copy of sqlite3-wasm.o.
|
||||
$(eval $(call call-make-pre-js,sqlite3))
|
||||
$(sqlite3.js): $(MAKEFILE) $(sqlite3.wasm.obj) \
|
||||
EXPORTED_FUNCTIONS.api \
|
||||
$(EXPORTED_FUNCTIONS.api) \
|
||||
$(pre-post-sqlite3.deps)
|
||||
@echo "Building $@ ..."
|
||||
$(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \
|
||||
$(emcc.jsflags) $(pre-post-common.flags) $(pre-post-sqlite3.flags) \
|
||||
$(sqlite3.wasm.obj)
|
||||
$(cflags.common) $(SQLITE_OPT) $(sqlite3-wasm.c)
|
||||
chmod -x $(sqlite3.wasm)
|
||||
$(maybe-wasm-strip) $(sqlite3.wasm)
|
||||
@ls -la $@ $(sqlite3.wasm)
|
||||
@ -417,7 +438,8 @@ speedtest1-common.eflags += -sINITIAL_MEMORY=128450560
|
||||
speedtest1-common.eflags += -sSTRICT_JS
|
||||
speedtest1-common.eflags += -sMODULARIZE
|
||||
speedtest1-common.eflags += -Wno-limited-postlink-optimizations
|
||||
speedtest1-common.eflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.speedtest1
|
||||
EXPORTED_FUNCTIONS.speedtest1 := $(abspath $(dir.tmp)/EXPORTED_FUNCTIONS.speedtest1)
|
||||
speedtest1-common.eflags += -sEXPORTED_FUNCTIONS=@$(EXPORTED_FUNCTIONS.speedtest1)
|
||||
speedtest1-common.eflags += $(emcc.exportedRuntimeMethods)
|
||||
speedtest1-common.eflags += -sALLOW_TABLE_GROWTH
|
||||
speedtest1-common.eflags += -sDYNAMIC_EXECUTION=0
|
||||
@ -444,31 +466,24 @@ speedtest1.exit-runtime1 := -sEXIT_RUNTIME=1
|
||||
# -sEXIT_RUNTIME=1 but we need EXIT_RUNTIME=0 for the worker-based app
|
||||
# which runs speedtest1 multiple times.
|
||||
|
||||
EXPORTED_FUNCTIONS.speedtest1: EXPORTED_FUNCTIONS.api
|
||||
{ echo _wasm_main; cat EXPORTED_FUNCTIONS.api; } > $@
|
||||
CLEAN_FILES += EXPORTED_FUNCTIONS.speedtest1
|
||||
speedtest1.js := speedtest1.js
|
||||
$(EXPORTED_FUNCTIONS.speedtest1): $(EXPORTED_FUNCTIONS.api)
|
||||
@echo "Making $@ ..."
|
||||
@{ echo _wasm_main; cat $(EXPORTED_FUNCTIONS.api); } > $@
|
||||
speedtest1.js := $(dir.dout)/speedtest1.js
|
||||
speedtest1.wasm := $(subst .js,.wasm,$(speedtest1.js))
|
||||
speedtest1.cflags := \
|
||||
-I. -I.. -I$(dir.top) \
|
||||
-DSQLITE_SPEEDTEST1_WASM
|
||||
speedtest1.cs := $(speedtest1.c) $(sqlite3-wasm.c)
|
||||
$(speedtest1.js): emcc.cflags+=
|
||||
# speedtest1 notes re. sqlite3-wasm.o vs sqlite3-wasm.c: building against
|
||||
# the latter (predictably) results in a slightly faster binary, but we're
|
||||
# close enough to the target speed requirements that the 500ms makes a
|
||||
# difference.
|
||||
speedtest1.cflags := $(cflags.common) -DSQLITE_SPEEDTEST1_WASM
|
||||
speedtest1.cses := $(speedtest1.c) $(sqlite3-wasm.c)
|
||||
$(eval $(call call-make-pre-js,speedtest1))
|
||||
$(speedtest1.js): $(MAKEFILE) $(speedtest1.cs) \
|
||||
$(speedtest1.js): $(MAKEFILE) $(speedtest1.cses) \
|
||||
$(pre-post-speedtest1.deps) \
|
||||
EXPORTED_FUNCTIONS.speedtest1
|
||||
$(EXPORTED_FUNCTIONS.speedtest1)
|
||||
@echo "Building $@ ..."
|
||||
$(emcc.bin) \
|
||||
$(speedtest1.eflags) $(speedtest1-common.eflags) $(speedtest1.cflags) \
|
||||
$(pre-post-speedtest1.flags) \
|
||||
$(SQLITE_OPT) \
|
||||
$(speedtest1.exit-runtime0) \
|
||||
-o $@ $(speedtest1.cs) -lm
|
||||
-o $@ $(speedtest1.cses) -lm
|
||||
$(maybe-wasm-strip) $(speedtest1.wasm)
|
||||
ls -la $@ $(speedtest1.wasm)
|
||||
|
||||
@ -531,6 +546,13 @@ oz: clean
|
||||
|
||||
include fiddle.make
|
||||
|
||||
ifneq (,$(filter wasmfs,$(MAKECMDGOALS)))
|
||||
# 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 for very
|
||||
# little, if any, benefit.
|
||||
#
|
||||
########################################################################
|
||||
# Some platforms do not support the WASMFS build. Raspberry Pi OS is one
|
||||
# of them. As such platforms are discovered, add their (uname -m) name
|
||||
@ -544,9 +566,12 @@ else
|
||||
HAVE_WASMFS := 1
|
||||
include wasmfs.make
|
||||
endif
|
||||
endif
|
||||
# /wasmfs
|
||||
########################################################################
|
||||
|
||||
########################################################################
|
||||
# Create deliverables: TODO
|
||||
# Create deliverables:
|
||||
ifneq (,$(filter dist,$(MAKECMDGOALS)))
|
||||
include dist.make
|
||||
endif
|
||||
|
@ -4,23 +4,21 @@ Main project page: https://sqlite.org
|
||||
|
||||
TODO: link to main WASM/JS docs, once they are online
|
||||
|
||||
This archive contains two related deliverables:
|
||||
This archive contains the sqlite3.js and sqlite3.wasm file which make
|
||||
up the sqlite3 WASM/JS build.
|
||||
|
||||
- ./main contains the sqlite3.js and sqlite3.wasm file which make up
|
||||
the standard sqlite3 WASM/JS build.
|
||||
|
||||
- ./wasmfs contains a build of those files which includes the
|
||||
Emscripten WASMFS[^1]. It offers an alternative approach
|
||||
to accessing the browser-side Origin-Private FileSystem
|
||||
but is less portable than the main build, so is provided
|
||||
as a separate binary.
|
||||
|
||||
Both directories contain small demonstration and test apps. Browsers
|
||||
will not serve WASM files from file:// URLs, so the demo/test apps
|
||||
require a web server and that server must include the following
|
||||
headers in its response when serving the files:
|
||||
The jswasm directory contains both the main deliverables and small
|
||||
demonstration and test apps. Browsers will not serve WASM files from
|
||||
file:// URLs, so the demo/test apps require a web server and that
|
||||
server must include the following headers in its response when serving
|
||||
the files:
|
||||
|
||||
Cross-Origin-Opener-Policy: same-origin
|
||||
Cross-Origin-Embedder-Policy: require-corp
|
||||
|
||||
[^1]: https://emscripten.org
|
||||
The files named sqlite3*.js and sqlite3.wasm belong to the core
|
||||
sqlite3 deliverables and the others are soley for demonstration and
|
||||
may be discarded. They are not in separate directories from the main
|
||||
deliverables because a quirk of URI resolution in JS code would then
|
||||
require that sqlite3.js be duplicated and edited for Worker-loaded
|
||||
operation.
|
||||
|
@ -43,3 +43,11 @@
|
||||
self.sqlite3InitModule.ready = originalInit.ready;
|
||||
//console.warn("Replaced sqlite3InitModule()");
|
||||
})();
|
||||
|
||||
if(0){
|
||||
console.warn("self.location.href =",self.location.href);
|
||||
if('undefined' !== typeof document){
|
||||
console.warn("document.currentScript.src =",
|
||||
document?.currentScript?.src);
|
||||
}
|
||||
}
|
||||
|
@ -1158,7 +1158,6 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
*/
|
||||
capi.sqlite3_web_db_export = function(pDb){
|
||||
if(!pDb) toss('Invalid sqlite3* argument.');
|
||||
const wasm = wasm;
|
||||
if(!wasm.bigIntEnabled) toss('BigInt64 support is not enabled.');
|
||||
const stack = wasm.pstack.pointer;
|
||||
let pOut;
|
||||
|
@ -1007,7 +1007,7 @@ int sqlite3_wasm_init_wasmfs(const char *zMountPoint){
|
||||
hypothetically suffice for the transient wasm-based virtual
|
||||
filesystem we're currently running in. */
|
||||
const int rc = wasmfs_create_directory(zMountPoint, 0777, pOpfs);
|
||||
emscripten_console_logf("OPFS mkdir(%s) rc=%d", zMountPoint, rc);
|
||||
/*emscripten_console_logf("OPFS mkdir(%s) rc=%d", zMountPoint, rc);*/
|
||||
if(rc) return SQLITE_IOERR;
|
||||
}
|
||||
return pOpfs ? 0 : SQLITE_NOMEM;
|
||||
|
@ -9,10 +9,6 @@
|
||||
#######################################################################
|
||||
MAKEFILE.dist := $(lastword $(MAKEFILE_LIST))
|
||||
|
||||
ifeq (0,$(HAVE_WASMFS))
|
||||
$(error The 'dist' target needs to be run on a WASMFS-capable platform.)
|
||||
endif
|
||||
|
||||
########################################################################
|
||||
# Chicken/egg situation: we need $(version-info) to get the version
|
||||
# info for the archive name, but that binary may not yet be built, and
|
||||
@ -33,7 +29,7 @@ CLEAN_FILES += $(wildcard sqlite-wasm-*.zip)
|
||||
#endif
|
||||
|
||||
########################################################################
|
||||
# dist-opt must be the name of a target which triggers the
|
||||
# dist-build must be the name of a target which triggers the
|
||||
# build of the files to be packed into the dist archive. The
|
||||
# intention is that it be one of (o0, o1, o2, o3, os, oz), each of
|
||||
# which uses like-named -Ox optimization level flags. The o2 target
|
||||
@ -42,7 +38,7 @@ CLEAN_FILES += $(wildcard sqlite-wasm-*.zip)
|
||||
# file sizes. Note that -O2 (the o2 target) results in faster binaries
|
||||
# than both -O3 and -Os (the o3 and os targets) in all tests run to
|
||||
# date.
|
||||
dist-opt ?= oz
|
||||
dist-build ?= oz
|
||||
|
||||
demo-123.html := $(dir.wasm)/demo-123.html
|
||||
demo-123-worker.html := $(dir.wasm)/demo-123-worker.html
|
||||
@ -50,36 +46,33 @@ demo-123.js := $(dir.wasm)/demo-123.js
|
||||
demo-files := $(demo-123.js) $(demo-123.html) $(demo-123-worker.html) \
|
||||
tester1.html tester1.js tester1-worker.html
|
||||
README-dist := $(dir.wasm)/README-dist.txt
|
||||
dist-dir-main := $(dist-name)/main
|
||||
dist-dir-wasmfs := $(dist-name)/wasmfs
|
||||
dist-dir-main := $(dist-name)/jswasm
|
||||
dist.main.extras := \
|
||||
sqlite3-opfs-async-proxy.js \
|
||||
sqlite3-worker1.js \
|
||||
sqlite3-worker1-promiser.js
|
||||
|
||||
########################################################################
|
||||
# $(dist-archive): create the end-user deliverable archive.
|
||||
#
|
||||
# Maintenance reminder: because $(dist-archive) depends on
|
||||
# $(dist-opt), and $(dist-opt) will depend on clean, having any deps
|
||||
# $(dist-build), and $(dist-build) will depend on clean, having any deps
|
||||
# on $(dist-archive) which themselves may be cleaned up by the clean
|
||||
# target will lead to grief in parallel builds (-j #). Thus
|
||||
# $(dist-target)'s deps must be trimmed to non-generated files or
|
||||
# files which are _not_ cleaned up by the clean target.
|
||||
$(dist-archive): \
|
||||
$(stripccomments) $(version-info) \
|
||||
$(dist-opt) \
|
||||
$(dist-build) \
|
||||
$(MAKEFILE) $(MAKEFILE.dist)
|
||||
@echo "Making end-user deliverables..."
|
||||
@rm -fr $(dist-name)
|
||||
@mkdir -p $(dist-dir-main) $(dist-dir-wasmfs)
|
||||
@mkdir -p $(dist-dir-main)
|
||||
@cp -p $(README-dist) $(dist-name)/README.txt
|
||||
@cp -p $(sqlite3.wasm) $(dist-dir-main)
|
||||
@cp -p $(sqlite3.wasm) $(dist.main.extras) $(dist-dir-main)
|
||||
@$(stripccomments) -k -k < $(sqlite3.js) \
|
||||
> $(dist-dir-main)/$(notdir $(sqlite3.js))
|
||||
@cp -p $(demo-files) $(dist-dir-main)
|
||||
@cp -p $(sqlite3-wasmfs.wasm) sqlite3-wasmfs.worker.js $(dist-dir-wasmfs)
|
||||
@$(stripccomments) -k -k < $(sqlite3-wasmfs.js) \
|
||||
> $(dist-dir-wasmfs)/$(notdir $(sqlite3-wasmfs.js))
|
||||
@for i in $(demo-123.js) $(demo-123.html); do \
|
||||
sed -e 's/\bsqlite3\.js\b/sqlite3-wasmfs.js/' $$i \
|
||||
> $(dist-dir-wasmfs)/$${i##*/} || exit; \
|
||||
done
|
||||
@vnum=$$($(version-info) --version-number); \
|
||||
vdir=sqlite-wasm-$$vnum; \
|
||||
arc=$$vdir.zip; \
|
||||
|
@ -23,6 +23,7 @@ $(dir.top)/shell.c: $(SHELL_SRC) $(dir.top)/tool/mkshellc.tcl
|
||||
# /shell.c
|
||||
########################################################################
|
||||
|
||||
EXPORTED_FUNCTIONS.fiddle := $(dir.tmp)/EXPORTED_FUNCTIONS.fiddle
|
||||
fiddle.emcc-flags = \
|
||||
$(emcc.cflags) $(emcc_opt_full) \
|
||||
--minify 0 \
|
||||
@ -35,17 +36,17 @@ fiddle.emcc-flags = \
|
||||
-sWASM_BIGINT=$(emcc_enable_bigint) \
|
||||
-sEXPORT_NAME=$(sqlite3.js.init-func) \
|
||||
$(sqlite3.js.flags.--post-js) \
|
||||
-sEXPORTED_RUNTIME_METHODS=@$(dir.wasm)/EXPORTED_RUNTIME_METHODS.fiddle \
|
||||
-sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.fiddle \
|
||||
$(emcc.exportedRuntimeMethods) \
|
||||
-sEXPORTED_FUNCTIONS=@$(abspath $(EXPORTED_FUNCTIONS.fiddle)) \
|
||||
$(SQLITE_OPT) $(SHELL_OPT) \
|
||||
-DSQLITE_SHELL_FIDDLE
|
||||
# -D_POSIX_C_SOURCE is needed for strdup() with emcc
|
||||
|
||||
fiddle.EXPORTED_FUNCTIONS.in := \
|
||||
EXPORTED_FUNCTIONS.fiddle.in \
|
||||
EXPORTED_FUNCTIONS.api
|
||||
$(EXPORTED_FUNCTIONS.api)
|
||||
|
||||
EXPORTED_FUNCTIONS.fiddle: $(fiddle.EXPORTED_FUNCTIONS.in) $(MAKEFILE.fiddle)
|
||||
$(EXPORTED_FUNCTIONS.fiddle): $(fiddle.EXPORTED_FUNCTIONS.in) $(MAKEFILE.fiddle)
|
||||
sort -u $(fiddle.EXPORTED_FUNCTIONS.in) > $@
|
||||
|
||||
fiddle-module.js := $(dir.fiddle)/fiddle-module.js
|
||||
@ -58,7 +59,7 @@ $(dir.fiddle)/$(SOAP.js): $(SOAP.js)
|
||||
|
||||
$(eval $(call call-make-pre-js,fiddle-module))
|
||||
$(fiddle-module.js): $(MAKEFILE) $(MAKEFILE.fiddle) \
|
||||
EXPORTED_FUNCTIONS.fiddle EXPORTED_RUNTIME_METHODS.fiddle \
|
||||
$(EXPORTED_FUNCTIONS.fiddle) \
|
||||
$(fiddle.cses) $(pre-post-fiddle-module.deps) $(dir.fiddle)/$(SOAP.js)
|
||||
$(emcc.bin) -o $@ $(fiddle.emcc-flags) \
|
||||
$(pre-post-common.flags) $(pre-post-fiddle-module.flags) \
|
||||
|
@ -34,8 +34,7 @@
|
||||
</li>
|
||||
<li>Whether or not WASMFS/OPFS support is enabled on any given
|
||||
page may depend on build-time options which are <em>off by
|
||||
default</em> because they currently (as of 2022-09-08) break
|
||||
with Worker-based pages.
|
||||
default</em>.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -68,7 +67,8 @@
|
||||
<li>speedtest1 ports (sqlite3's primary benchmarking tool)...
|
||||
<ul>
|
||||
<li><a href='speedtest1.html'>speedtest1</a>: a main-thread WASM build of speedtest1.</li>
|
||||
<li><a href='speedtest1-wasmfs.html?flags=--size,25'>speedtest1-wasmfs</a>: a variant of speedtest1 built solely for the wasmfs/opfs feature.</li>
|
||||
<!--li><a href='speedtest1-wasmfs.html?flags=--size,25'>speedtest1-wasmfs</a>: a variant of speedtest1 built solely for the wasmfs/opfs feature.
|
||||
</li-->
|
||||
<li><a href='speedtest1.html?vfs=kvvfs'>speedtest1-kvvfs</a>: speedtest1 with the kvvfs.</li>
|
||||
<li><a href='speedtest1-worker.html?size=25'>speedtest1-worker</a>: an interactive Worker-thread variant of speedtest1.</li>
|
||||
<li><a href='speedtest1-worker.html?vfs=opfs&size=25'>speedtest1-worker-opfs</a>: speedtest1-worker with the
|
||||
@ -81,10 +81,10 @@
|
||||
<li><a href='testing-worker1-promiser.html'>testing-worker1-promiser</a>:
|
||||
tests for the Promise-based wrapper of the Worker-based API.</li>
|
||||
<li><a href='batch-runner.html'>batch-runner</a>: runs batches of SQL exported from speedtest1.</li>
|
||||
<li><a href='scratchpad-wasmfs-main.html'>scratchpad-wasmfs-main</a>:
|
||||
<!--li><a href='scratchpad-wasmfs-main.html'>scratchpad-wasmfs-main</a>:
|
||||
experimenting with WASMFS/OPFS-based persistence. Maintenance
|
||||
reminder: we cannot currently (2022-09-15) load WASMFS in a
|
||||
worker due to an Emscripten limitation.</li>
|
||||
worker due to an Emscripten limitation.</li-->
|
||||
<li><a href='test-opfs-vfs.html'>test-opfs-vfs</a>
|
||||
(<a href='test-opfs-vfs.html?opfs-sanity-check&opfs-verbose'>same
|
||||
with verbose output and sanity-checking tests</a>) is an
|
||||
|
@ -25,13 +25,29 @@
|
||||
Worker-specific API needs to pass _this_ file (or equivalent) to the
|
||||
Worker constructor and then listen for an event in the form shown
|
||||
above in order to know when the module has completed initialization.
|
||||
|
||||
This file accepts a couple of URL arguments to adjust how it loads
|
||||
sqlite3.js:
|
||||
|
||||
- `sqlite3.dir`, if set, treats the given directory name as the
|
||||
directory from which `sqlite3.js` will be loaded.
|
||||
- `sqlite3.js`, if set, is used as the URI to `sqlite3.js` and it
|
||||
may contain path elements, e.g. `sqlite3.js=foo/bar/my-sqlite3.js`.
|
||||
|
||||
By default is loads 'sqlite3.js'.
|
||||
*/
|
||||
"use strict";
|
||||
(()=>{
|
||||
const urlParams = new URL(self.location.href).searchParams;
|
||||
importScripts(urlParams.has('wasmfs')
|
||||
? 'sqlite3-wasmfs.js'
|
||||
: 'sqlite3.js');
|
||||
let theJs;
|
||||
if(urlParams.has('sqlite3.js')){
|
||||
theJs = urlParams.get('sqlite3.js');
|
||||
}else if(urlParams.has('sqlite3.dir')){
|
||||
theJs = urlParams.get('sqlite3.dir')+'/sqlite3.js';
|
||||
}else{
|
||||
theJs = 'sqlite3.js';
|
||||
}
|
||||
importScripts(theJs);
|
||||
sqlite3InitModule().then((sqlite3)=>{
|
||||
sqlite3.capi.sqlite3_wasmfs_opfs_dir();
|
||||
sqlite3.initWorker1API();
|
||||
|
@ -1,36 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
|
||||
<link rel="stylesheet" href="common/emscripten.css"/>
|
||||
<link rel="stylesheet" href="common/testing.css"/>
|
||||
<title>sqlite3-api.js tests</title>
|
||||
</head>
|
||||
<body>
|
||||
<header id='titlebar'><span>sqlite3-api.js tests</span></header>
|
||||
<!-- emscripten bits -->
|
||||
<figure id="module-spinner">
|
||||
<div class="spinner"></div>
|
||||
<div class='center'><strong>Initializing app...</strong></div>
|
||||
<div class='center'>
|
||||
On a slow internet connection this may take a moment. If this
|
||||
message displays for "a long time", intialization may have
|
||||
failed and the JavaScript console may contain clues as to why.
|
||||
</div>
|
||||
</figure>
|
||||
<div class="emscripten" id="module-status">Downloading...</div>
|
||||
<div class="emscripten">
|
||||
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
|
||||
</div><!-- /emscripten bits -->
|
||||
<div>Most stuff on this page happens in the dev console.</div>
|
||||
<hr>
|
||||
<div id='test-output'></div>
|
||||
<!-- testing1.js "should" work with both sqlite3.js and sqlite3-kvvfs.js -->
|
||||
<!--script src="sqlite3-kvvfs.js"></script-->
|
||||
<script src="sqlite3.js"></script>
|
||||
<script src="common/SqliteTestUtil.js"></script>
|
||||
<script src="testing1.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -7,23 +7,24 @@
|
||||
########################################################################
|
||||
MAKEFILE.wasmfs := $(lastword $(MAKEFILE_LIST))
|
||||
|
||||
sqlite3-wasmfs.js := sqlite3-wasmfs.js
|
||||
sqlite3-wasmfs.wasm := sqlite3-wasmfs.wasm
|
||||
# Maintenance reminder: these particular files cannot be built into a
|
||||
# subdirectory because loading of the auxiliary
|
||||
# sqlite3-wasmfs.worker.js file it creates fails if sqlite3-wasmfs.js
|
||||
# is loaded from any directory other than the one in which the
|
||||
# containing HTML lives.
|
||||
dir.wasmfs := $(dir.wasm)
|
||||
sqlite3-wasmfs.js := $(dir.wasmfs)/sqlite3-wasmfs.js
|
||||
sqlite3-wasmfs.wasm := $(dir.wasmfs)/sqlite3-wasmfs.wasm
|
||||
|
||||
CLEAN_FILES += $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.wasm) \
|
||||
$(subst .js,.worker.js,$(sqlite3-wasmfs.js))
|
||||
|
||||
########################################################################
|
||||
# emcc flags for .c/.o/.wasm.
|
||||
sqlite3-wasmfs.flags =
|
||||
#sqlite3-wasmfs.flags += -v # _very_ loud but also informative about what it's doing
|
||||
|
||||
########################################################################
|
||||
# emcc flags for .c/.o.
|
||||
sqlite3-wasmfs.cflags :=
|
||||
sqlite3-wasmfs.cflags += -std=c99 -fPIC
|
||||
sqlite3-wasmfs.cflags += -pthread
|
||||
sqlite3-wasmfs.cflags += -I. -I.. -I$(dir.top)
|
||||
sqlite3-wasmfs.cflags += $(cflags.common)
|
||||
sqlite3-wasmfs.cflags += $(SQLITE_OPT) -DSQLITE_WASM_WASMFS
|
||||
|
||||
########################################################################
|
||||
@ -35,7 +36,7 @@ sqlite3-wasmfs.jsflags += -sMODULARIZE
|
||||
sqlite3-wasmfs.jsflags += -sSTRICT_JS
|
||||
sqlite3-wasmfs.jsflags += -sDYNAMIC_EXECUTION=0
|
||||
sqlite3-wasmfs.jsflags += -sNO_POLYFILL
|
||||
sqlite3-wasmfs.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api
|
||||
sqlite3-wasmfs.jsflags += -sEXPORTED_FUNCTIONS=@$(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api)
|
||||
sqlite3-wasmfs.jsflags += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory,allocateUTF8OnStack
|
||||
# wasmMemory ==> for -sIMPORTED_MEMORY
|
||||
# allocateUTF8OnStack ==> wasmfs internals
|
||||
@ -67,7 +68,7 @@ sqlite3-wasmfs.jsflags += -sWASM_BIGINT=$(emcc_enable_bigint)
|
||||
$(eval $(call call-make-pre-js,sqlite3-wasmfs))
|
||||
sqlite3-wasmfs.jsflags += $(pre-post-common.flags) $(pre-post-sqlite3-wasmfs.flags)
|
||||
$(sqlite3-wasmfs.js): $(sqlite3-wasm.c) \
|
||||
EXPORTED_FUNCTIONS.api $(MAKEFILE) $(MAKEFILE.wasmfs) \
|
||||
$(EXPORTED_FUNCTIONS.api) $(MAKEFILE) $(MAKEFILE.wasmfs) \
|
||||
$(pre-post-sqlite3-wasmfs.deps)
|
||||
@echo "Building $@ ..."
|
||||
$(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \
|
||||
@ -84,22 +85,22 @@ all: wasmfs
|
||||
# speedtest1 for wasmfs. Re. sqlite3-wasm.o vs sqlite3-wasm.c:
|
||||
# building against the latter (predictably) results in a slightly
|
||||
# faster binary.
|
||||
speedtest1-wasmfs.js := speedtest1-wasmfs.js
|
||||
speedtest1-wasmfs.js := $(dir.wasmfs)/speedtest1-wasmfs.js
|
||||
speedtest1-wasmfs.wasm := $(subst .js,.wasm,$(speedtest1-wasmfs.js))
|
||||
speedtest1-wasmfs.eflags := $(sqlite3-wasmfs.fsflags)
|
||||
speedtest1-wasmfs.eflags += $(SQLITE_OPT) -DSQLITE_WASM_WASMFS
|
||||
$(eval $(call call-make-pre-js,speedtest1-wasmfs))
|
||||
$(speedtest1-wasmfs.js): $(speedtest1.cs) $(sqlite3-wasmfs.js) \
|
||||
$(speedtest1-wasmfs.js): $(speedtest1.cses) $(sqlite3-wasmfs.js) \
|
||||
$(MAKEFILE) $(MAKEFILE.wasmfs) \
|
||||
$(pre-post-speedtest1-wasmfs.deps) \
|
||||
EXPORTED_FUNCTIONS.speedtest1
|
||||
$(EXPORTED_FUNCTIONS.speedtest1)
|
||||
@echo "Building $@ ..."
|
||||
$(emcc.bin) \
|
||||
$(speedtest1-wasmfs.eflags) $(speedtest1-common.eflags) \
|
||||
$(pre-post-speedtest1-wasmfs.flags) \
|
||||
$(speedtest1.cflags) \
|
||||
$(sqlite3-wasmfs.cflags) \
|
||||
-o $@ $(speedtest1.cs) -lm
|
||||
-o $@ $(speedtest1.cses) -lm
|
||||
$(maybe-wasm-strip) $(speedtest1-wasmfs.wasm)
|
||||
ls -la $@ $(speedtest1-wasmfs.wasm)
|
||||
|
||||
|
Reference in New Issue
Block a user