From cc336321f83404e5e970874e184c6505079479dc Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 13 Jul 2023 14:08:30 +0000 Subject: [PATCH] Significant surgery on the wasm build on the way to incorporating wasmfs as a first-class build option. FossilOrigin-Name: 215c37fce38cf647e073480689b79d952af7eb8165ae08c7f5caed27003fecfc --- ext/wasm/GNUmakefile | 176 +++++++++++++++++++--------------- ext/wasm/common/whwasmutil.js | 44 +++++---- ext/wasm/tester1.c-pp.js | 2 + ext/wasm/wasmfs.make | 69 ++++--------- manifest | 18 ++-- manifest.uuid | 2 +- 6 files changed, 156 insertions(+), 155 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 60b33a3338..65b6294e64 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -159,6 +159,9 @@ endif # bundle. # # 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 @@ -611,26 +614,40 @@ $(post-js.js.in): $(post-jses.js) $(MAKEFILE) ######################################################################## # call-make-pre-post is a $(call)able which creates rules for -# pre-js-$(1).js. $1 = the base name of the JS file on whose behalf -# this pre-js is for (one of: sqlite3, sqlite3-wasmfs). $2 is the -# build mode: one of $(JS_BUILD_MODES). This -# sets up --[extern-][pre/post]-js flags in -# $(pre-post-$(1).flags.$(2)) and dependencies in -# $(pre-post-$(1).deps.$(2)). +# pre-js-$(1)-$(2).js. $1 = the base name of the JS file on whose +# behalf this pre-js is for (one of: sqlite3, sqlite3-wasmfs). $2 is +# the build mode: one of $(JS_BUILD_MODES). This sets up +# --[extern-][pre/post]-js flags in $(pre-post-$(1)-$(2).flags) and +# dependencies in $(pre-post-$(1)-$(2).deps). The resulting files get +# filtered using $(C-PP.FILTER). Any flags necessary for such +# filtering need to be set in $(c-pp.D.$(1)-$(2)) before $(call)ing +# this. define call-make-pre-post -pre-post-$(1).flags.$(2) ?= -$$(dir.tmp)/pre-js-$(1)-$(2).js: $$(pre-js.js.$(2)) $$(MAKEFILE) - cp $$(pre-js.js.$(2)) $$@ +pre-post-$(1)-$(2).flags ?= +pre-js.js.$(1)-$(2) := $$(dir.tmp)/pre-js.$(1)-$(2).intermediary.js +$$(eval $$(call C-PP.FILTER,$$(pre-js.js.in),$$(pre-js.js.$(1)-$(2)),$$(c-pp.D.$(1)-$(2)))) +post-js.js.$(1)-$(2) := $$(dir.tmp)/post-js.$(1)-$(2).js +$$(eval $$(call C-PP.FILTER,$$(post-js.js.in),$$(post-js.js.$(1)-$(2)),$$(c-pp.D.$(1)-$(2)))) +extern-post-js.js.$(1)-$(2) := $$(dir.tmp)/extern-post-js.$(1)-$(2).js +$$(eval $$(call C-PP.FILTER,$$(extern-post-js.js.in),$$(extern-post-js.js.$(1)-$(2)),$$(c-pp.D.$(1)-$(2)))) +pre-post-common.flags.$(1)-$(2) := \ + $$(pre-post-common.flags) \ + --post-js=$$(post-js.js.$(1)-$(2)) \ + --extern-post-js=$$(extern-post-js.js.$(1)-$(2)) +pre-post-jses.$(1)-$(2).deps := $$(pre-post-jses.deps.common) \ + $$(post-js.js.$(1)-$(2)) $$(extern-post-js.js.$(1)-$(2)) +$$(dir.tmp)/pre-js-$(1)-$(2).js: $$(pre-js.js.$(1)-$(2)) $$(MAKEFILE) + cp $$(pre-js.js.$(1)-$(2)) $$@ @if [ sqlite3-wasmfs = $(1) ]; then \ echo "delete Module[xNameOfInstantiateWasm] /*for WASMFS build*/;"; \ elif [ sqlite3 != $(1) ]; then \ echo "Module[xNameOfInstantiateWasm].uri = '$(1).wasm';"; \ fi >> $$@ -pre-post-$(1).deps.$(2) := \ - $$(pre-post-jses.deps.$(2)) \ +pre-post-$(1)-$(2).deps := \ + $$(pre-post-jses.$(1)-$(2).deps) \ $$(dir.tmp)/pre-js-$(1)-$(2).js -pre-post-$(1).flags.$(2) += \ - $$(pre-post-common.flags.$(2)) \ +pre-post-$(1)-$(2).flags += \ + $$(pre-post-common.flags.$(1)-$(2)) \ --pre-js=$$(dir.tmp)/pre-js-$(1)-$(2).js endef # /post-js and pre-js @@ -641,7 +658,8 @@ endef # https://github.com/emscripten-core/emscripten/issues/14383 sqlite3.wasm := $(dir.dout)/sqlite3.wasm sqlite3-wasm.c := $(dir.api)/sqlite3-wasm.c -sqlite3-wasm.cses := $(sqlite3-wasm.c) $(sqlite3_wasm_extra_init.c) +sqlite3-wasm.cfiles := $(sqlite3-wasm.c) $(sqlite3_wasm_extra_init.c) +sqlite3-wasmfs.cfiles := $(sqlite3-wasm.cfiles) # sqlite3-wasm.o vs sqlite3-wasm.c: building against the latter # (predictably) results in a slightly faster binary. We're close # enough to the target speed requirements that the 500ms makes a @@ -651,8 +669,8 @@ sqlite3-wasm.cses := $(sqlite3-wasm.c) $(sqlite3_wasm_extra_init.c) # SQLITE3.xJS.EXPORT-DEFAULT is part of SQLITE3-WASMFS.xJS.RECIPE and # SETUP_LIB_BUILD_MODE, factored into a separate piece to avoid code # duplication. $1 is 1 if the build mode needs this workaround (esm, -# bundler-friendly) and 0 if not (vanilla). $2 must be empty for all -# builds except sqlite3-wasmfs.mjs, in which case it must be 1. +# bundler-friendly, node) and 0 if not (vanilla). $2 must be empty for +# all builds except sqlite3-wasmfs.mjs, in which case it must be 1. # # Reminder for ESM builds: even if we use -sEXPORT_ES6=0, emcc _still_ # adds: @@ -668,7 +686,7 @@ sqlite3-wasm.cses := $(sqlite3-wasm.c) $(sqlite3_wasm_extra_init.c) # https://github.com/emscripten-core/emscripten/issues/18237 define SQLITE3.xJS.ESM-EXPORT-DEFAULT if [ x1 = x$(1) ]; then \ - echo "Fragile workaround for an Emscripten annoyance. See SQLITE3.xJS.RECIPE."; \ + echo "Fragile workaround for emscripten/issues/18237. See SQLITE3.xJS.RECIPE."; \ sed -i -e '0,/^export default/{/^export default/d;}' $@ || exit $$?; \ if [ x != x$(2) ]; then \ if ! grep -q '^export default' $@; then \ @@ -694,53 +712,57 @@ pre-post-jses.deps.common := $(extern-pre-js.js) $(sqlite3-license-version.js) # SETUP_LIB_BUILD_MODE is a $(call)'able which sets up numerous pieces # for one of the build modes. # -# $1 = build mode name: one of $(JS_BUILD_MODES) -# $2 = 1 for ESM build mode, else 0 -# $3 = resulting sqlite-api JS/MJS file -# $4 = resulting JS/MJS file -# $5 = -D... flags for $(bin.c-pp) -# $6 = emcc -sXYZ flags (CURRENTLY UNUSED - was factored out) +# $1 = one of: sqlite3, sqlite3-wasmfs +# $2 = build mode name: one of $(JS_BUILD_MODES) +# $3 = 1 for ESM build mode, else 0 +# $4 = resulting sqlite-api JS/MJS file +# $5 = resulting JS/MJS file +# $6 = -D... flags for $(bin.c-pp) +# $7 = emcc -sXYZ flags (CURRENTLY UNUSED - was factored out) # -# emcc.environment.$(1) must be set to a value for the -sENVIRONMENT flag. +# Maintenance reminder: be careful not to introduce spaces around args +# ($1, $2), otherwise string concatenation will malfunction. +# +# emcc.environment.$(2) must be set to a value for the -sENVIRONMENT flag. +# +# $(cflags.$(1)) and $(cflags.$(1).$(2)) may be defined to append +# CFLAGS to a given build mode. +# +# $(emcc.flags.$(1)) and $(emcc.flags.$(1).$(2)) may be defined to +# append emcc-specific flags to a given build mode. define SETUP_LIB_BUILD_MODE -$(info Setting up build [$(1)]: $(4)) -c-pp.D.$(1) := $(5) -pre-js.js.$(1) := $$(dir.tmp)/pre-js.$(1).js -$$(eval $$(call C-PP.FILTER,$$(pre-js.js.in),$$(pre-js.js.$(1)),$$(c-pp.D.$(1)))) -post-js.js.$(1) := $$(dir.tmp)/post-js.$(1).js -$$(eval $$(call C-PP.FILTER,$$(post-js.js.in),$$(post-js.js.$(1)),$$(c-pp.D.$(1)))) -extern-post-js.js.$(1) := $$(dir.tmp)/extern-post-js.$(1).js -$$(eval $$(call C-PP.FILTER,$$(extern-post-js.js.in),$$(extern-post-js.js.$(1)),$$(c-pp.D.$(1)))) -pre-post-common.flags.$(1) := \ - $$(pre-post-common.flags) \ - --post-js=$$(post-js.js.$(1)) \ - --extern-post-js=$$(extern-post-js.js.$(1)) -pre-post-jses.deps.$(1) := $$(pre-post-jses.deps.common) \ - $$(post-js.js.$(1)) $$(extern-post-js.js.$(1)) -$$(eval $$(call call-make-pre-post,sqlite3,$(1))) -emcc.flags.sqlite3.$(1) := $(6) -$$(eval $$(call C-PP.FILTER, $$(sqlite3-api.js.in), $(3), $(5))) -$(4): $(3) $$(MAKEFILE) $$(sqlite3-wasm.cses) $$(EXPORTED_FUNCTIONS.api) $$(pre-post-sqlite3.deps.$(1)) +$(info Setting up build [$(1)-$(2)]: $(5)) +c-pp.D.$(1)-$(2) := $(6) +$$(eval $$(call call-make-pre-post,$(1),$(2))) +emcc.flags.$(1).$(2) ?= +emcc.flags.$(1).$(2) += $(7) +$$(eval $$(call C-PP.FILTER, $$(sqlite3-api.js.in), $(4), $(6))) +$(5): $(4) $$(MAKEFILE) $$(sqlite3-wasm.cfiles) $$(EXPORTED_FUNCTIONS.api) $$(pre-post-$(1)-$(2).deps) @echo "Building $$@ ..." $$(emcc.bin) -o $$@ $$(emcc_opt_full) $$(emcc.flags) \ $$(emcc.jsflags) \ - -sENVIRONMENT=$$(emcc.environment.$(1)) \ - $$(pre-post-sqlite3.flags.$(1)) $$(emcc.flags.sqlite3.$(1)) \ - $$(cflags.common) $$(SQLITE_OPT) $$(cflags.wasm_extra_init) $$(sqlite3-wasm.cses) - @$$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,$(2)) - @case $(1) in \ + -sENVIRONMENT=$$(emcc.environment.$(2)) \ + $$(pre-post-$(1)-$(2).flags) \ + $$(emcc.flags.$(1)) $$(emcc.flags.$(1).$(2)) \ + $$(cflags.common) $$(SQLITE_OPT) \ + $$(cflags.$(1)) $$(cflags.$(1).$(2)) \ + $$(cflags.wasm_extra_init) $$(sqlite3-wasm.cfiles) + @$$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,$(3)) + @dotwasm=$$(basename $$@).wasm; \ + chmod -x $$$$dotwasm; \ + $(maybe-wasm-strip) $$$$dotwasm; \ + case $(2) in \ bundler-friendly|node) \ - echo "Patching $(3) for sqlite3.wasm..."; \ - rm -f $$(dir.dout)/sqlite3-$(1).wasm; \ - sed -i -e 's/sqlite3-$(1).wasm/sqlite3.wasm/g' $$@ || exit $$$$?; \ + echo "Patching $$@ for $(1).wasm..."; \ + rm -f $$$$dotwasm; \ + dotwasm=; \ + sed -i -e 's/$(1)-$(2).wasm/$(1).wasm/g' $$@ || exit $$$$?; \ ;; \ - esac - chmod -x $$(sqlite3.wasm) - $$(maybe-wasm-strip) $$(sqlite3.wasm) - @ls -la $@ $$(sqlite3.wasm) -all: $(4) -quick: $(4) -CLEAN_FILES += $(3) $(4) + esac; \ + ls -la $$$$dotwasm $$@ +all: $(5) +quick: $(5) +CLEAN_FILES += $(4) $(5) endef # ^^^ /SETUP_LIB_BUILD_MODE ######################################################################## @@ -752,21 +774,24 @@ sqlite3-api-bundler-friendly.mjs := $(dir.dout)/sqlite3-api-bundler-friendly.mjs sqlite3-bundler-friendly.mjs := $(dir.dout)/sqlite3-bundler-friendly.mjs sqlite3-api-node.mjs := $(dir.dout)/sqlite3-api-node.mjs sqlite3-node.mjs := $(dir.dout)/sqlite3-node.mjs -# Maintenance reminder: careful not to introduce spaces around args $1, $2 -#$(info $(call SETUP_LIB_BUILD_MODE,vanilla,0, $(sqlite3-api.js), $(sqlite3.js))) -$(eval $(call SETUP_LIB_BUILD_MODE,vanilla,0, $(sqlite3-api.js), $(sqlite3.js))) -$(eval $(call SETUP_LIB_BUILD_MODE,esm,1, $(sqlite3-api.mjs), $(sqlite3.mjs), \ +#$(info $(call SETUP_LIB_BUILD_MODE,sqlite3,vanilla,0, $(sqlite3-api.js), $(sqlite3.js))) +$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,vanilla,0,\ + $(sqlite3-api.js), $(sqlite3.js))) +$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,esm,1,\ + $(sqlite3-api.mjs), $(sqlite3.mjs), \ -Dtarget=es6-module, -sEXPORT_ES6 -sUSE_ES6_IMPORT_META)) -$(eval $(call SETUP_LIB_BUILD_MODE,bundler-friendly,1,\ +$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,bundler-friendly,1,\ $(sqlite3-api-bundler-friendly.mjs),$(sqlite3-bundler-friendly.mjs),\ - $(c-pp.D.esm) -Dtarget=es6-bundler-friendly)) -$(eval $(call SETUP_LIB_BUILD_MODE,node,1,\ + $(c-pp.D.sqlite3-esm) -Dtarget=es6-bundler-friendly)) +$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,node,1,\ $(sqlite3-api-node.mjs),$(sqlite3-node.mjs),\ - $(c-pp.D.bundler-friendly) -Dtarget=node)) + $(c-pp.D.sqlite3-bundler-friendly) -Dtarget=node)) # The various -D... values used by *.c-pp.js include: # # -Dtarget=es6-module: for all ESM module builds # +# -Dtarget=node: for node.js builds +# # -Dtarget=es6-module -Dtarget=es6-bundler-friendly: intended for # "bundler-friendly" ESM module build. These have some restrictions # on how URL() objects are constructed in some contexts: URLs which @@ -848,7 +873,7 @@ all: batch # emcc.speedtest1.common = emcc flags used by multiple builds of speedtest1 # emcc.speedtest1 = emcc flags used by main build of speedtest1 emcc.speedtest1.common := $(emcc_opt_full) -emcc.speedtest1 := +emcc.speedtest1 := -I. -I$(dir $(sqlite3.canonical.c)) emcc.speedtest1 += -sENVIRONMENT=web emcc.speedtest1 += -sALLOW_MEMORY_GROWTH emcc.speedtest1 += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.$(emcc.INITIAL_MEMORY)) @@ -891,21 +916,22 @@ $(EXPORTED_FUNCTIONS.speedtest1): $(EXPORTED_FUNCTIONS.api.main) @{ echo _wasm_main; cat $(EXPORTED_FUNCTIONS.api.main); } > $@ speedtest1.js := $(dir.dout)/speedtest1.js speedtest1.wasm := $(dir.dout)/speedtest1.wasm -cflags.speedtest1 := $(cflags.common) -DSQLITE_SPEEDTEST1_WASM -speedtest1.cses := $(speedtest1.c) $(sqlite3-wasm.c) +emcc.flags.speedtest1-vanilla := $(cflags.common) -DSQLITE_SPEEDTEST1_WASM + +speedtest1.cfiles := $(speedtest1.c) $(sqlite3-wasm.c) $(eval $(call call-make-pre-post,speedtest1,vanilla)) -$(speedtest1.js): $(MAKEFILE) $(speedtest1.cses) \ - $(pre-post-speedtest1.deps.vanilla) \ +$(speedtest1.js): $(MAKEFILE) $(speedtest1.cfiles) \ + $(pre-post-speedtest1-vanilla.deps) \ $(EXPORTED_FUNCTIONS.speedtest1) @echo "Building $@ ..." $(emcc.bin) \ - $(emcc.speedtest1) -I$(dir $(sqlite3.canonical.c)) \ + $(emcc.speedtest1) \ $(emcc.speedtest1.common) \ - $(cflags.speedtest1) $(pre-post-speedtest1.flags.vanilla) \ + $(emcc.flags.speedtest1-vanilla) $(pre-post-speedtest1-vanilla.flags) \ $(SQLITE_OPT) \ -USQLITE_C -DSQLITE_C=$(sqlite3.canonical.c) \ $(speedtest1.exit-runtime0) \ - -o $@ $(speedtest1.cses) -lm + -o $@ $(speedtest1.cfiles) -lm $(maybe-wasm-strip) $(speedtest1.wasm) ls -la $@ $(speedtest1.wasm) @@ -932,9 +958,9 @@ CLEAN_FILES += $(speedtest1.js) $(speedtest1.wasm) # # To create those, we filter tester1.c-pp.js with $(bin.c-pp)... $(eval $(call C-PP.FILTER,tester1.c-pp.js,tester1.js)) -$(eval $(call C-PP.FILTER,tester1.c-pp.js,tester1.mjs,$(c-pp.D.esm))) +$(eval $(call C-PP.FILTER,tester1.c-pp.js,tester1.mjs,$(c-pp.D.sqlite3-esm))) $(eval $(call C-PP.FILTER,tester1.c-pp.html,tester1.html)) -$(eval $(call C-PP.FILTER,tester1.c-pp.html,tester1-esm.html,$(c-pp.D.esm))) +$(eval $(call C-PP.FILTER,tester1.c-pp.html,tester1-esm.html,$(c-pp.D.sqlite3-esm))) tester1: tester1.js tester1.mjs tester1.html tester1-esm.html # Note that we do not include $(sqlite3-bundler-friendly.mjs) in this # because bundlers are client-specific. diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index aea484787d..f48e8a7d21 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -1656,25 +1656,11 @@ globalThis.WhWasmUtilInstaller = function(target){ ? opt.callProxy : undefined; } - /** If true, the constructor emits a warning. The intent is that - this be set to true after bootstrapping of the higher-level - client library is complete, to warn downstream clients that - they shouldn't be relying on this implemenation detail which - does not have a stable interface. */ - static warnOnUse = false; - - /** If true, convertArg() will FuncPtrAdapter.debugOut() when it - (un)installs a function binding to/from WASM. Note that - deinstallation of bindScope=transient bindings happens - via scopedAllocPop() so will not be output. */ - static debugFuncInstall = false; - - /** Function used for debug output. */ - static debugOut = console.debug.bind(console); - - static bindScopes = [ - 'transient', 'context', 'singleton', 'permanent' - ]; + /** + Note that static class members are defined outside of the class + to work around an emcc toolchain build problem: one of the + tools in emsdk v3.1.42 does not support the static keyword. + */ /* Dummy impl. Overwritten per-instance as needed. */ contextKey(argv,argIndex){ @@ -1761,6 +1747,26 @@ globalThis.WhWasmUtilInstaller = function(target){ }/*convertArg()*/ }/*FuncPtrAdapter*/; + /** If true, the constructor emits a warning. The intent is that + this be set to true after bootstrapping of the higher-level + client library is complete, to warn downstream clients that + they shouldn't be relying on this implemenation detail which + does not have a stable interface. */ + xArg.FuncPtrAdapter.warnOnUse = false; + + /** If true, convertArg() will FuncPtrAdapter.debugOut() when it + (un)installs a function binding to/from WASM. Note that + deinstallation of bindScope=transient bindings happens + via scopedAllocPop() so will not be output. */ + xArg.FuncPtrAdapter.debugFuncInstall = false; + + /** Function used for debug output. */ + xArg.FuncPtrAdapter.debugOut = console.debug.bind(console); + + xArg.FuncPtrAdapter.bindScopes = [ + 'transient', 'context', 'singleton', 'permanent' + ]; + const __xArgAdapterCheck = (t)=>xArg.get(t) || toss("Argument adapter not found:",t); diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index ea4a2b479a..8b71198669 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -3057,6 +3057,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; error: ()=>{} } } +//#ifnot target=es6-module if(!globalThis.sqlite3InitModule && !isUIThread()){ /* Vanilla worker, as opposed to an ES6 module worker */ /* @@ -3080,6 +3081,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; } importScripts(sqlite3Js); } +//#endif globalThis.sqlite3InitModule.__isUnderTest = true /* disables certain API-internal cleanup so that we can test internal APIs from here */; diff --git a/ext/wasm/wasmfs.make b/ext/wasm/wasmfs.make index aed6b67f03..a2415b79ef 100644 --- a/ext/wasm/wasmfs.make +++ b/ext/wasm/wasmfs.make @@ -24,72 +24,42 @@ CLEAN_FILES += $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.wasm) \ cflags.sqlite3-wasmfs := cflags.sqlite3-wasmfs += -std=c99 -fPIC cflags.sqlite3-wasmfs += -pthread -cflags.sqlite3-wasmfs += $(cflags.speedtest1) -cflags.sqlite3-wasmfs += $(SQLITE_OPT) -DSQLITE_ENABLE_WASMFS +cflags.sqlite3-wasmfs += -DSQLITE_ENABLE_WASMFS ######################################################################## # emcc flags specific to building the final .js/.wasm file... -emcc.flags.sqlite3-wasmfs := -fPIC -emcc.flags.sqlite3-wasmfs += --no-entry -emcc.flags.sqlite3-wasmfs += --minify 0 -emcc.flags.sqlite3-wasmfs += -sMODULARIZE -emcc.flags.sqlite3-wasmfs += -sEXPORT_NAME=$(sqlite3.js.init-func) -emcc.flags.sqlite3-wasmfs += -sDYNAMIC_EXECUTION=0 -emcc.flags.sqlite3-wasmfs += -sNO_POLYFILL -emcc.flags.sqlite3-wasmfs += -sWASM_BIGINT=$(emcc.WASM_BIGINT) -emcc.flags.sqlite3-wasmfs += -sEXPORTED_FUNCTIONS=@$(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api) +emcc.flags.sqlite3-wasmfs := emcc.flags.sqlite3-wasmfs += -sEXPORTED_RUNTIME_METHODS=wasmMemory,allocateUTF8OnStack # wasmMemory ==> for -sIMPORTED_MEMORY # allocateUTF8OnStack ==> wasmfs internals emcc.flags.sqlite3-wasmfs += -sUSE_CLOSURE_COMPILER=0 emcc.flags.sqlite3-wasmfs += -Wno-limited-postlink-optimizations # ^^^^^ it likes to warn when we have "limited optimizations" via the -g3 flag. -emcc.flags.sqlite3-wasmfs += -sALLOW_TABLE_GROWTH -emcc.flags.sqlite3-wasmfs += -sSTACK_SIZE=512KB -emcc.flags.sqlite3-wasmfs += -sGLOBAL_BASE=4096 # HYPOTHETICALLY keep func table indexes from overlapping w/ heap addr. emcc.flags.sqlite3-wasmfs += -sMEMORY64=0 -emcc.flags.sqlite3-wasmfs += -sIMPORTED_MEMORY emcc.flags.sqlite3-wasmfs += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.128) # ^^^^ 64MB is not enough for WASMFS/OPFS test runs using batch-runner.js sqlite3-wasmfs.fsflags := -pthread -sWASMFS \ - -sPTHREAD_POOL_SIZE=2 -sENVIRONMENT=web,worker \ - -sERROR_ON_UNDEFINED_SYMBOLS=0 -sLLD_REPORT_UNDEFINED + -sPTHREAD_POOL_SIZE=2 \ + -sERROR_ON_UNDEFINED_SYMBOLS=0 -sLLD_REPORT_UNDEFINED # ^^^^^ why undefined symbols are necessary for the wasmfs build is anyone's guess. emcc.flags.sqlite3-wasmfs += $(sqlite3-wasmfs.fsflags) -#emcc.flags.sqlite3-wasmfs += -sALLOW_MEMORY_GROWTH +emcc.flags.sqlite3-wasmfs += -sALLOW_MEMORY_GROWTH=0 #^^^ using ALLOW_MEMORY_GROWTH produces a warning from emcc: # USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, # see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth] # And, indeed, it runs slowly if memory is permitted to grow. -emcc.flags.sqlite3-wasmfs.vanilla := -emcc.flags.sqlite3-wasmfs.esm := -sEXPORT_ES6 -sUSE_ES6_IMPORT_META -$(eval $(call call-make-pre-post,sqlite3-wasmfs,vanilla)) -$(eval $(call call-make-pre-post,sqlite3-wasmfs,esm)) -Xemcc.flags.sqlite3-wasmfs.vanilla += \ - $(pre-post-common.flags.vanilla) \ - $(pre-post-sqlite3-wasmfs.flags.vanilla) -Xemcc.flags.sqlite3-wasmfs.esm += \ - $(pre-post-common.flags.esm) \ - $(pre-post-sqlite3-wasmfs.flags.esm) -$(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(sqlite3-wasm.c) \ - $(EXPORTED_FUNCTIONS.api) $(MAKEFILE) $(MAKEFILE.wasmfs) -$(sqlite3-wasmfs.js): $(pre-post-sqlite3-wasmfs.deps.vanilla) -$(sqlite3-wasmfs.mjs): $(pre-post-sqlite3-wasmfs.deps.esm) -# SQLITE3-WASMFS.xJS.RECIPE is the wasmfs-specific counterpart -# of SQLITE3.xJS.RECIPE from the main makefile. -define SQLITE3-WASMFS.xJS.RECIPE - @echo "Building $@ ..." - $(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \ - $(cflags.sqlite3-wasmfs) \ - $(emcc.flags.sqlite3-wasmfs) $(emcc.flags.sqlite3-wasmfs.$(1)) \ - $(pre-post-sqlite3-wasmfs.flags.$(1)) \ - $(sqlite3-wasm.c) - @$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,$(if $(filter %.mjs,$@),1,)) - @dotwasm=$(basename $@).wasm; \ - chmod -x $$dotwasm; \ - $(maybe-wasm-strip) $$dotwasm; \ - ls -la $$dotwasm $@ -endef +#emcc.flags.sqlite3-wasmfs.vanilla := +#emcc.flags.sqlite3-wasmfs.esm := -sEXPORT_ES6 -sUSE_ES6_IMPORT_META +sqlite3-api.mjs.wasmfs := $(dir.tmp)/sqlite3-api-wasmfs.mjs +$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3-wasmfs,esm,1,\ + $(sqlite3-api.mjs.wasmfs), $(sqlite3-wasmfs.mjs),\ + $(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs,\ + -sEXPORT_ES6 -sUSE_ES6_IMPORT_META\ +)) +#$(eval $(call call-make-pre-post,sqlite3-wasmfs,vanilla)) +$(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(MAKEFILE.wasmfs) +#$(sqlite3-wasmfs.js): $(pre-post-sqlite3-wasmfs.deps.vanilla) +#$(sqlite3-wasmfs.mjs): $(pre-post-sqlite3-wasmfs.deps.esm) ######################################################################## # Build quirk: we cannot build BOTH .js and .mjs with our current # build infrastructure because the supplemental *.worker.js files get @@ -102,10 +72,7 @@ endef # built/saved multiple times. # wasmfs.build.ext := mjs -$(sqlite3-wasmfs.js): $(SOAP.js.bld) - $(call SQLITE3-WASMFS.xJS.RECIPE,vanilla) -$(sqlite3-wasmfs.mjs): $(SOAP.js.bld) - $(call SQLITE3-WASMFS.xJS.RECIPE,esm) +$(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(SOAP.js.bld) ifeq (js,$(wasmfs.build.ext)) $(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.js) wasmfs: $(sqlite3-wasmfs.js) diff --git a/manifest b/manifest index e9f96d2eb9..83cc47a93d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\swork\son\sthe\swasmfs\sbuild.\sResolve\sthe\sinconsistent\sargument\stype\spassed\sto\ssqlite3InitModule()\sin\ssuch\sbuilds. -D 2023-07-13T10:41:41.226 +C Significant\ssurgery\son\sthe\swasm\sbuild\son\sthe\sway\sto\sincorporating\swasmfs\sas\sa\sfirst-class\sbuild\soption. +D 2023-07-13T14:08:30.624 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -482,7 +482,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile daedd26bdc97f705d72213733573630d38c3fbbec0ba722a93c5302a12e7685f +F ext/wasm/GNUmakefile fec1dd8ad46a35d817f273d470a4f062a58c2445bc9b7d022826fa578dbbeedb F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md ef39861aa21632fdbca0bdd469f78f0096f6449a720f3f39642594af503030e9 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api d6a5078f48a5301ed17b9a30331075d9b2506e1360c1f0dee0c7816c10acd9ab @@ -512,7 +512,7 @@ F ext/wasm/c-pp.c 6d80d8569d85713effe8b0818a3cf51dc779e3f0bf8dc88771b8998552ee25 F ext/wasm/common/SqliteTestUtil.js 7adaeffef757d8708418dc9190f72df22367b531831775804b31598b44f6aa51 F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15 F ext/wasm/common/testing.css 0ff15602a3ab2bad8aef2c3bd120c7ee3fd1c2054ad2ace7e214187ae68d926f -F ext/wasm/common/whwasmutil.js 03407d7b61b817fd135c82401987e56688a45ee4d6b9c0eced160c0000d6e4c2 +F ext/wasm/common/whwasmutil.js ae263dec9d7384f4c530f324b99d00516a4d6f26424372daee65031e00eb49b3 F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508 F ext/wasm/demo-123.js ebae30756585bca655b4ab2553ec9236a87c23ad24fc8652115dcedb06d28df6 @@ -547,12 +547,12 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js f09266873e1a34d9bdb6d3981ec8c9e382f31f215c9fd2f9016d2394b8ae9b7b F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js 439a1264bc3224b90bc722833568cc36fc77ed0ba6d2e4379b40ea7c417c97ab +F ext/wasm/tester1.c-pp.js 4420eb97b6b4fc79e4e156b4b8010dd9f373365f4230dd76d823fb04ce28ffde F ext/wasm/tests/opfs/concurrency/index.html 0802373d57034d51835ff6041cda438c7a982deea6079efd98098d3e42fbcbc1 F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 F ext/wasm/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd72273503ae7d5 -F ext/wasm/wasmfs.make 95e5ee1d67db75561872dfab9b2ebc65084eb807808d863308c405bba3e1a4e1 +F ext/wasm/wasmfs.make 6cfe6cb04859ca7aa611f71f6e770811d023a519a7fb4cc4de1419189594c2a8 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 @@ -2042,8 +2042,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f64477f21040c265061ad9b7f601e74159fd6141e7e4b122c80bf244ab6ddb76 -R 30150ab9b0833aa41ada6fa807ec2755 +P 4850a9e2d2b41b91e91b9ef99a6d26ddf11a161b4c970fc00d2d095606729a04 +R 68d56fe3eae005ed95f6c7df371b3baf U stephan -Z 8daba6a2f84ceed3306c658c6f269c02 +Z a358a57a699b604bd4cd582e774f0d4e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fd2bbe2705..4800ae6aca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4850a9e2d2b41b91e91b9ef99a6d26ddf11a161b4c970fc00d2d095606729a04 \ No newline at end of file +215c37fce38cf647e073480689b79d952af7eb8165ae08c7f5caed27003fecfc \ No newline at end of file