diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index a99513bfa8..85a5ef5054 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -655,7 +655,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). +# 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. # # Reminder for ESM builds: even if we use -sEXPORT_ES6=0, emcc _still_ # adds: @@ -673,9 +674,11 @@ define SQLITE3.xJS.ESM-EXPORT-DEFAULT if [ x1 = x$(1) ]; then \ echo "Fragile workaround for an Emscripten annoyance. See SQLITE3.xJS.RECIPE."; \ sed -i -e '0,/^export default/{/^export default/d;}' $@ || exit $$?; \ - if ! grep -q '^export default' $@; then \ - echo "Cannot find export default." 1>&2; \ - exit 1; \ + if [ x != x$(2) ]; then \ + if ! grep -q '^export default' $@; then \ + echo "Cannot find export default." 1>&2; \ + exit 1; \ + fi; \ fi; \ fi endef @@ -981,6 +984,8 @@ include fiddle.make ifneq (,$(filter wasmfs,$(MAKECMDGOALS))) wasmfs.enable ?= 1 else +# Unconditionally enable wasmfs for [dist]clean so that the wasmfs +# sub-make can clean up. wasmfs.enable ?= $(if $(filter %clean,$(MAKECMDGOALS)),1,0) endif ifeq (1,$(wasmfs.enable)) diff --git a/ext/wasm/api/extern-post-js.c-pp.js b/ext/wasm/api/extern-post-js.c-pp.js index 927bf64f9e..6b544fe1cd 100644 --- a/ext/wasm/api/extern-post-js.c-pp.js +++ b/ext/wasm/api/extern-post-js.c-pp.js @@ -23,10 +23,7 @@ const toExportForESM = impls which Emscripten installs at some point in the file above this. */ - const originalInit = - /* Maintenance reminder: DO NOT use `self.` here. It's correct - for non-ES6 Module cases but wrong for ES6 modules because those - resolve this symbol differently. */ sqlite3InitModule; + const originalInit = sqlite3InitModule; if(!originalInit){ throw new Error("Expecting globalThis.sqlite3InitModule to be defined by the Emscripten build."); } @@ -124,5 +121,5 @@ const toExportForESM = return globalThis.sqlite3InitModule /* required for ESM */; })(); //#if target=es6-module -export default toExportForESM; +export { toExportForESM as default, toExportForESM as sqlite3InitModule } //#endif diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index 77739db57d..98e97355c7 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -92,8 +92,8 @@ currently work due to incompatible Emscripten-side changes made in the WASMFS+OPFS combination. This option is currently ignored. - [^1] = This property may optionally be a function, in which case this - function re-assigns calls that function to fetch the value, + [^1] = This property may optionally be a function, in which case + this function calls that function to fetch the value, enabling delayed evaluation. The returned object is the top-level sqlite3 namespace object. @@ -149,11 +149,6 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( config[k] = config[k](); } }); - config.wasmOpfsDir = - /* 2022-12-17: WASMFS+OPFS can no longer be activated from the - main thread (aborts via a failed assert() if it's attempted), - which eliminates any(?) benefit to supporting it. */ false; - /** The main sqlite3 binding API gets installed into this object, mimicking the C API as closely as we can. The numerous members @@ -1200,8 +1195,6 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( if(undefined !== __wasmfsOpfsDir) return __wasmfsOpfsDir; // If we have no OPFS, there is no persistent dir const pdir = config.wasmfsOpfsDir; - console.error("sqlite3_wasmfs_opfs_dir() can no longer work due "+ - "to incompatible WASMFS changes. It will be removed."); if(!pdir || !globalThis.FileSystemHandle || !globalThis.FileSystemDirectoryHandle diff --git a/ext/wasm/scratchpad-wasmfs-main.html b/ext/wasm/scratchpad-wasmfs-main.html index 91f61526cd..f78b412885 100644 --- a/ext/wasm/scratchpad-wasmfs-main.html +++ b/ext/wasm/scratchpad-wasmfs-main.html @@ -33,8 +33,16 @@

All stuff on this page happens in the dev console.


- + - + + + diff --git a/ext/wasm/scratchpad-wasmfs-main.js b/ext/wasm/scratchpad-wasmfs-main.js index 56f9325de5..3fb8d6af06 100644 --- a/ext/wasm/scratchpad-wasmfs-main.js +++ b/ext/wasm/scratchpad-wasmfs-main.js @@ -14,6 +14,9 @@ main JS thread and sqlite3.js must have been loaded before it. */ 'use strict'; +//importScripts('jswasm/sqlite3-wasmfs.js'); +import sqlite3InitModule from './jswasm/sqlite3-wasmfs.mjs'; +//console.log('sqlite3InitModule =',sqlite3InitModule); (function(){ const toss = function(...args){throw new Error(args.join(' '))}; const log = console.log.bind(console), @@ -38,6 +41,7 @@ const capi = sqlite3.capi, oo = sqlite3.oo1, wasm = sqlite3.wasm; + stdout("Loaded module:",sqlite3); stdout("Loaded sqlite3:",capi.sqlite3_libversion(), capi.sqlite3_sourceid()); const persistentDir = capi.sqlite3_wasmfs_opfs_dir(); if(persistentDir){ @@ -66,5 +70,15 @@ stdout("Total test time:",(performance.now() - startTime),"ms"); }; - sqlite3InitModule(self.sqlite3TestModule).then(runTests); + sqlite3InitModule(globalThis.sqlite3TestModule).then((X)=>{ + /* + 2023-07-13: we're passed the Emscripten Module object here + instead of the sqlite3 object. This differs from the canonical + build and is a side effect of WASMFS's requirement + that the module init function (i.e. sqlite3InitModule()) + return its initial arrgument (the Emscripten Module). + */ + stdout("then() got",X.sqlite3,X); + runTests(X.sqlite3 || X); + }); })(); diff --git a/ext/wasm/speedtest1-wasmfs.html b/ext/wasm/speedtest1-wasmfs.html index 4c4db32bca..3c69285a18 100644 --- a/ext/wasm/speedtest1-wasmfs.html +++ b/ext/wasm/speedtest1-wasmfs.html @@ -91,7 +91,7 @@ }; const runTests = function(sqlite3){ - console.log("Module inited."); + console.log("Module inited.",sqlite3); const wasm = sqlite3.wasm; const __unlink = wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["*","string"]); const unlink = (fn)=>__unlink(0,fn); diff --git a/ext/wasm/wasmfs.make b/ext/wasm/wasmfs.make index 020014f3e8..791f7ba839 100644 --- a/ext/wasm/wasmfs.make +++ b/ext/wasm/wasmfs.make @@ -6,14 +6,10 @@ # GNUMakefile. ######################################################################## MAKEFILE.wasmfs := $(lastword $(MAKEFILE_LIST)) +$(warning The WASMFS build is currently incomplete.) -# 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. Similarly, they cannot be loaded from a -# Worker to an Emscripten quirk regarding loading nested Workers. -dir.wasmfs := $(dir.wasm) +#dir.wasmfs := $(dir.wasm) +dir.wasmfs := $(dir.dout) sqlite3-wasmfs.js := $(dir.wasmfs)/sqlite3-wasmfs.js sqlite3-wasmfs.mjs := $(dir.wasmfs)/sqlite3-wasmfs.mjs sqlite3-wasmfs.wasm := $(dir.wasmfs)/sqlite3-wasmfs.wasm @@ -38,7 +34,6 @@ 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 += -sSTRICT_JS emcc.flags.sqlite3-wasmfs += -sDYNAMIC_EXECUTION=0 emcc.flags.sqlite3-wasmfs += -sNO_POLYFILL emcc.flags.sqlite3-wasmfs += -sWASM_BIGINT=$(emcc.WASM_BIGINT) @@ -68,8 +63,8 @@ emcc.flags.sqlite3-wasmfs += $(sqlite3-wasmfs.fsflags) # 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-js,sqlite3-wasmfs,vanilla)) -$(eval $(call call-make-pre-js,sqlite3-wasmfs,esm)) +$(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) @@ -89,17 +84,32 @@ define SQLITE3-WASMFS.xJS.RECIPE $(emcc.flags.sqlite3-wasmfs) $(emcc.flags.sqlite3-wasmfs.$(1)) \ $(pre-post-sqlite3-wasmfs.flags.$(1)) \ $(sqlite3-wasm.c) - @$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,$(1)) + @$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,$(if $(filter %.mjs,$@),1,)) chmod -x $(sqlite3-wasmfs.wasm) $(maybe-wasm-strip) $(sqlite3-wasmfs.wasm) - @ls -la $(sqlite3-wasmfs.wasm) sqlite3-wasmfs*js + @ls -la $(sqlite3-wasmfs.wasm) $(dir.wasmfs)/sqlite3-wasmfs*js endef +######################################################################## +# Build quirk: we cannot build BOTH .js and .mjs with our current +# build infrastructure because the supplemental *.worker.js files get +# generated with the name of the main module file +# ($(sqlite3-wasmfs.{js,mjs})) hard-coded in them. Thus the last one +# to get built gets the *.worker.js files mapped to it. In order to +# build both modes they would need to have distinct base names or +# output directories. +# +wasmfs.build.ext := mjs +ifeq (js,$(wasmfs.build.mode)) $(sqlite3-wasmfs.js): $(call SQLITE3-WASMFS.xJS.RECIPE,vanilla) -$(sqlite3-wasmfs.mjs): $(sqlite3-wasmfs.js) - $(call SQLITE3-WASMFS.xJS.RECIPE,esm) $(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.js) -wasmfs: $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs) +wasmfs: $(sqlite3-wasmfs.js) +else +$(sqlite3-wasmfs.mjs): # $(sqlite3-wasmfs.js) + $(call SQLITE3-WASMFS.xJS.RECIPE,esm) +$(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.mjs) +wasmfs: $(sqlite3-wasmfs.mjs) +endif #all: wasmfs ######################################################################## @@ -124,8 +134,7 @@ $(speedtest1-wasmfs.js): $(speedtest1.cses) $(sqlite3-wasmfs.js) \ $(maybe-wasm-strip) $(speedtest1-wasmfs.wasm) ls -la $@ $(speedtest1-wasmfs.wasm) -#speedtest1: $(speedtest1-wasmfs.js) -wasmfs: $(speedtest1-wasmfs.js) +#wasmfs: $(speedtest1-wasmfs.js) CLEAN_FILES += $(speedtest1-wasmfs.js) $(speedtest1-wasmfs.wasm) \ $(subst .js,.worker.js,$(speedtest1-wasmfs.js)) # end speedtest1.js diff --git a/manifest b/manifest index 39db92f161..c99cedfe6a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Replace\s'self'\swith\s'globalThis'\sin\ssome\sJS\stest\scode. -D 2023-07-13T03:46:43.944 +C Get\swasmfs\sbuild\sand\sits\sbare-bones\stest\sapp\sworking\sagain,\salbeit\scurrently\sin\sES6\smode\sonly. +D 2023-07-13T04:26:13.675 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -482,14 +482,14 @@ 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 38700d5074af690f004e4e5f3533164ab49693b9d0832929c4ecf97a0bc09494 +F ext/wasm/GNUmakefile 319505a36ceb8debffd5f0d3243e6396ee5f623a68529d205fb0c7155df832cf F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md ef39861aa21632fdbca0bdd469f78f0096f6449a720f3f39642594af503030e9 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api d6a5078f48a5301ed17b9a30331075d9b2506e1360c1f0dee0c7816c10acd9ab F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-see fb29e62082a658f0d81102488414d422c393c4b20cc2f685b216bc566237957b F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 F ext/wasm/api/README.md 77a2f1f2fc60a35def7455dffc8d3f2c56385d6ac5c6cecc60fa938252ea2c54 -F ext/wasm/api/extern-post-js.c-pp.js 393ab78b807da94096eae1a68bfddb999a2299936a185d910162fe87a57a9a3a +F ext/wasm/api/extern-post-js.c-pp.js a91c73765b8909d0fddad72328f9396fee1f5fb58435e73cff20ef713e67d014 F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1 F ext/wasm/api/post-js-header.js 47b6b281f39ad59fa6e8b658308cd98ea292c286a68407b35ff3ed9cfd281a62 @@ -497,7 +497,7 @@ F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057af F ext/wasm/api/sqlite3-api-cleanup.js 23ceec5ef74a0e649b19694ca985fd89e335771e21f24f50df352a626a8c81bf F ext/wasm/api/sqlite3-api-glue.js f1b2dcb944de5138bb5bd9a1559d2e76a4f3ec25260963d709e8237476688803 F ext/wasm/api/sqlite3-api-oo1.js 9678dc4d9a5d39632b6ffe6ea94a023119260815bf32f265bf5f6c36c9516db8 -F ext/wasm/api/sqlite3-api-prologue.js 9608d7844f1ffa50add1d8a3138219d9cba87a6515067120dafe37e0d009deec +F ext/wasm/api/sqlite3-api-prologue.js b20856fb72a07a99de2bea24cf66dd8fc7dbf6514280884e0ff91e3d0859ed3b F ext/wasm/api/sqlite3-api-worker1.js 9f32af64df1a031071912eea7a201557fe39b1738645c0134562bb84e88e2fec F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 961bbc3ccc1fa4e91d6519a96e8811ad7ae60173bd969fee7775dacb6eee1da2 @@ -534,9 +534,9 @@ F ext/wasm/index.html bba92ca0c173b579356533226a85a28797d1789e893c9b483fc0623842 F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 37911f00db12cbcca73aa1ed72594430365f30aafae2fa9c886961de74e5e0eb F ext/wasm/module-symbols.html 841de62fc198988b8330e238c260e70ec93028b096e1a1234db31b187a899d10 -F ext/wasm/scratchpad-wasmfs-main.html 20cf6f1a8f368e70d01e8c17200e3eaa90f1c8e1029186d836d14b83845fbe06 -F ext/wasm/scratchpad-wasmfs-main.js 4c140457f4d6da9d646a49addd91edb6e9ad1643c6c48e3258b5bce24725dc18 -F ext/wasm/speedtest1-wasmfs.html 7a301f4f5b6ad4f5d37fd6e7ca03a2f5d5547fd289da60a39075a93d7646d354 +F ext/wasm/scratchpad-wasmfs-main.html a70452766ed8dd88f7c4b3603dbf8de34c76b734614fd67729f0961a82af19c3 +F ext/wasm/scratchpad-wasmfs-main.js 59cbc259921f3ff521cdfafdbe278df885b5f92e0e279aacacf6fb12ff3be5eb +F ext/wasm/speedtest1-wasmfs.html 3493c46b24bad00e9f6ebe14804143ae67a880f6c59c16ee13bf5f06e7dc4313 F ext/wasm/speedtest1-worker.html 97c2bf5f8534091ce718de05801090d5a80c3f13575996f095ba23638e1bdca0 F ext/wasm/speedtest1-worker.js 13b57c4a41729678a1194014afec2bd5b94435dcfc8d1039dfa9a533ac819ee1 F ext/wasm/speedtest1.html ff048b4a623aa192e83e143e48f1ce2a899846dd42c023fdedc8772b6e3f07da @@ -552,7 +552,7 @@ F ext/wasm/tests/opfs/concurrency/index.html 0802373d57034d51835ff6041cda438c7a9 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 cf9a68162d92ca2bcb0b9528b244cb36d5cc2d84ccc9c2d398461927d6e75aea +F ext/wasm/wasmfs.make 4d34310493108e297b46084959ae06f634ac21446898fc464223ca33cd05a508 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 @@ -2042,8 +2042,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a061a43e36b8f3cb7c465fd2e54cfcd9dceb07e232ee78602bbdd1818acd05ea -R e5f9c2b543ee2e3a15f3537a9d58e252 +P 53eeffc9b1ea8c3ee7d7cdcc220997ed893403e45b35d8ea10805ea3b0435587 +R 6632e735d7b6678fb19e864586c8977f +T *branch * wasmfs-2023 +T *sym-wasmfs-2023 * +T -sym-trunk * Cancelled\sby\sbranch. U stephan -Z c5917bb24dee9d73dec2b26ad6758a4f +Z 18788228280efa16edd900f1ed072054 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2830c84e4a..269dc636d7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -53eeffc9b1ea8c3ee7d7cdcc220997ed893403e45b35d8ea10805ea3b0435587 \ No newline at end of file +647761ed422f196f94facc88bbddd7219a2c1a6301a5f847b0a32d3e405233a7 \ No newline at end of file