diff options
author | stephan <stephan@noemail.net> | 2022-08-13 13:56:00 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-08-13 13:56:00 +0000 |
commit | 9a4c63b0fc85a019d3183abbd7939b081f45d025 (patch) | |
tree | c99980c7709d23ac40373a422066b1a1eaf9a3aa | |
parent | 90218aec7a0991199b3e06faf723dd482bf970f6 (diff) | |
download | sqlite-9a4c63b0fc85a019d3183abbd7939b081f45d025.tar.gz sqlite-9a4c63b0fc85a019d3183abbd7939b081f45d025.zip |
Cleanups in the wasmfs/opfs integration but disable it in order to get the build into a known-working state before continuing with experimentation.
FossilOrigin-Name: 41045be752a5bd7966849638f3ca56f4905308df70f79f2cb6196ca7dce9d525
-rw-r--r-- | ext/wasm/GNUmakefile | 27 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-api-prologue.js | 49 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-wasm.c | 27 | ||||
-rw-r--r-- | ext/wasm/testing1.js | 5 | ||||
-rw-r--r-- | ext/wasm/testing2.js | 2 | ||||
-rw-r--r-- | manifest | 20 | ||||
-rw-r--r-- | manifest.uuid | 2 |
7 files changed, 103 insertions, 29 deletions
diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index e32febbfc..dad77dba0 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -127,9 +127,9 @@ sqlite3-api.jses := \ $(dir.jacc)/jaccwabyt.js \ $(dir.api)/sqlite3-api-glue.js \ $(dir.api)/sqlite3-api-oo1.js \ - $(dir.api)/sqlite3-api-worker.js \ - $(dir.api)/sqlite3-api-opfs.js \ - $(dir.api)/sqlite3-api-cleanup.js + $(dir.api)/sqlite3-api-worker.js +#sqlite3-api.jses += $(dir.api)/sqlite3-api-opfs.js +sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js sqlite3-api.js := $(dir.api)/sqlite3-api.js CLEAN_FILES += $(sqlite3-api.js) @@ -174,7 +174,6 @@ emcc.cflags += -pthread # emcc flags specific to building the final .js/.wasm file... emcc.jsflags := -fPIC emcc.jsflags += --no-entry -emcc.jsflags += -sENVIRONMENT=web,worker emcc.jsflags += -sMODULARIZE emcc.jsflags += -sSTRICT_JS emcc.jsflags += -sDYNAMIC_EXECUTION=0 @@ -183,7 +182,12 @@ emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.api emcc.jsflags += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory # wasmMemory==>for -sIMPORTED_MEMORY emcc.jsflags += -sUSE_CLOSURE_COMPILER=0 emcc.jsflags += -sIMPORTED_MEMORY -emcc.jsflags += -pthread -sWASMFS +emcc.environment := -sENVIRONMENT=web +ifeq (0,1) + emcc.jsflags += -pthread -sWASMFS -sPTHREAD_POOL_SIZE=2 + emcc.environment := $(emcc.environment),worker +endif +emcc.jsflags += $(emcc.environment) #emcc.jsflags += -sINITIAL_MEMORY=13107200 #emcc.jsflags += -sTOTAL_STACK=4194304 emcc.jsflags += -sEXPORT_NAME=sqlite3InitModule @@ -235,11 +239,14 @@ $(dir.api)/sqlite3-wasm.o: $(dir.top)/sqlite3.c $(dir.api)/wasm_util.o: emcc.cflags += $(SQLITE_OPT) sqlite3.wasm.c := $(dir.api)/sqlite3-wasm.c \ $(dir.jacc)/jaccwabyt_test.c -# ^^^ FIXME (how?): jaccwabyt_test.c is only needed for the test -# apps. However, we want to test the release builds with those apps, -# so we cannot simply elide that file in release builds. That -# component is critical to the VFS bindings so needs to be tested -# along with the core APIs. +# ^^^ FIXME (how?): jaccwabyt_test.c is only needed for the test apps, +# so we don't really want to include it in release builds. However, we +# want to test the release builds with those apps, so we cannot simply +# elide that file in release builds. That component is critical to the +# VFS bindings so needs to be tested along with the core APIs. +ifneq (,$(filter -sWASMFS,$(emcc.jsflags))) + $(dir.api)/sqlite3-wasm.o: emcc.cflags+=-DSQLITE_WASM_OPFS +endif define WASM_C_COMPILE $(1).o := $$(subst .c,.o,$(1)) sqlite3.wasm.obj += $$($(1).o) diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index 60ed61477..08e3ebf6e 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -576,6 +576,55 @@ self.sqlite3ApiBootstrap = function(config){ ["sqlite3_total_changes64", "i64", ["sqlite3*"]] ]; + /** State for sqlite3_web_persistent_dir(). */ + let __persistentDir; + /** + An experiment. Do not use. + + If the wasm environment has a persistent storage directory, + its path is returned by this function. If it does not then + it returns one of: + + - `undefined` if initIfNeeded is false and this function has + never been called before. + + - `""` if no persistent storage is available. + + Note that in both cases the return value is falsy. + */ + capi.sqlite3_web_persistent_dir = function(initIfNeeded=true){ + if(undefined !== __persistentDir) return __persistentDir; + else if(!initIfNeeded) return; + // If we have no OPFS, there is no persistent dir + if(!self.FileSystemHandle || !self.FileSystemDirectoryHandle + || !self.FileSystemFileHandle){ + return __persistentDir = ""; + } + try{ + if(0===this.wasm.xCall('sqlite3_wasm_init_opfs')){ + /** OPFS does not support locking and will trigger errors if + we try to lock. We don't _really_ want to + _unconditionally_ install a non-locking sqlite3 VFS as the + default, but we do so here for simplicy's sake for the + time being. That said: locking is a no-op on all of the + current WASM storage, so this isn't (currently) as bad as + it may initially seem. */ + const pVfs = this.sqlite3_vfs_find("unix-none"); + if(pVfs){ + this.sqlite3_vfs_register(pVfs,1); + //warn("Installed 'unix-none' as the default sqlite3 VFS."); + } + return __persistentDir = + "/persistent" /* name is hard-coded in sqlite3_wasm_init_opfs()!*/; + }else{ + return __persistentDir = ""; + } + }catch(e){ + // sqlite3_wasm_init_opfs() is not available + return __persistentDir = ""; + } + }.bind(capi); + /* The remainder of the API will be set up in later steps. */ return { capi, diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index 30a9dafeb..487baecf1 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -430,7 +430,7 @@ int sqlite3_wasm_vfs_unlink(const char * zName){ return rc; } -#ifdef __EMSCRIPTEN__ +#if defined(__EMSCRIPTEN__) && defined(SQLITE_WASM_OPFS) #include <emscripten/wasmfs.h> #include <emscripten/console.h> /* @@ -443,17 +443,34 @@ int sqlite3_wasm_vfs_unlink(const char * zName){ ** WASMFS backend impl for OPFS. On success, subsequent calls are ** no-ops. ** -** Returns 0 on success, SQLITE_NOMEM if intantiation of the backend -** object fails. +** Returns 0 on success, SQLITE_NOMEM if instantiation of the backend +** object fails, SQLITE_IOERR if mkdir() of the "/persistent" dir in +** the virtual FS fails. In builds compiled without SQLITE_WASM_OPFS +** defined, SQLITE_NOTFOUND is returned without side effects. */ int sqlite3_wasm_init_opfs(void){ static backend_t pOpfs = 0; + static const char * zDir = "/persistent"; if( !pOpfs ){ pOpfs = wasmfs_create_opfs_backend(); if( pOpfs ){ - emscripten_console_log("Created OPFS WASMFS backend."); + emscripten_console_log("Created WASMFS OPFS backend."); } } + /** It's not enough to instantiate the backend. We have to create a + mountpoint in the VFS and attach the backend to it. */ + if( pOpfs && 0!=access(zDir, F_OK) ){ + /* mkdir() simply hangs when called from fiddle app. Cause is + not yet determined but the hypothesis is an init-order + issue. */ + const int rc = wasmfs_create_directory(zDir, 0777, pOpfs); + emscripten_console_log(rc ? "OPFS mkdir failed." : "OPFS mkdir ok."); + if(rc) return SQLITE_IOERR; + } return pOpfs ? 0 : SQLITE_NOMEM; } -#endif /* __EMSCRIPTEN__ */ +#else +int sqlite3_wasm_init_opfs(void){ + return SQLITE_NOTFOUND; +} +#endif /* __EMSCRIPTEN__ && SQLITE_WASM_OPFS */ diff --git a/ext/wasm/testing1.js b/ext/wasm/testing1.js index a733156e7..779e0bd72 100644 --- a/ext/wasm/testing1.js +++ b/ext/wasm/testing1.js @@ -19,7 +19,8 @@ const toss = function(...args){throw new Error(args.join(' '))}; const debug = console.debug.bind(console); const eOutput = document.querySelector('#test-output'); - const log = console.log.bind(console) + const log = console.log.bind(console), + warn = console.warn.bind(console); const logHtml = function(...args){ log.apply(this, args); const ln = document.createElement('div'); @@ -1012,7 +1013,7 @@ wasm = capi.wasm; log("Loaded module:",capi.sqlite3_libversion(), capi.sqlite3_sourceid()); log("Build options:",wasm.compileOptionUsed()); - + capi.sqlite3_web_persistent_dir()/*will install OPFS if available, plus a and non-locking VFS*/; if(1){ /* Let's grab those last few lines of test coverage for sqlite3-api.js... */ diff --git a/ext/wasm/testing2.js b/ext/wasm/testing2.js index 3a279513f..f6792955f 100644 --- a/ext/wasm/testing2.js +++ b/ext/wasm/testing2.js @@ -20,7 +20,7 @@ id: undefined }; const eOutput = document.querySelector('#test-output'); - const log = console.log.bind(console) + const log = console.log.bind(console); const logHtml = function(cssClass,...args){ log.apply(this, args); const ln = document.createElement('div'); @@ -1,5 +1,5 @@ -C Remove\sOPFS\sfrom\sthe\sfiddle\sbuild\sfor\sthe\stime\sbeing\s-\swill\sre-enable\sonce\sthe\sbreakage\sis\sfigured\sout\svia\stesting\swith\sthe\score\sAPI. -D 2022-08-13T13:51:56.967 +C Cleanups\sin\sthe\swasmfs/opfs\sintegration\sbut\sdisable\sit\sin\sorder\sto\sget\sthe\sbuild\sinto\sa\sknown-working\sstate\sbefore\scontinuing\swith\sexperimentation. +D 2022-08-13T13:56:00.886 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -474,7 +474,7 @@ F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle db7a4602f043cf4a5e4135be3609a487f9f1c83f05778bfbdf93766be4541b96 F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle a004bd5eeeda6d3b28d16779b7f1a80305bfe009dfc7f0721b042967f0d39d02 -F ext/wasm/GNUmakefile c354ad5ce3ecec80c28ed4314827adc10cbbc0ef47e028b0cfbdf336c4a98fa4 +F ext/wasm/GNUmakefile 15ee5d1e182bcee23f0a5fa8062697f4135606c642efe600fa2d5e794ad71588 F ext/wasm/README.md 4b00ae7c7d93c4591251245f0996a319e2651361013c98d2efb0b026771b7331 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 77ef4bcf37e362b9ad61f9c175dfc0f1b3e571563fb311b96581cf422ee6a8ec F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 @@ -485,10 +485,10 @@ F ext/wasm/api/sqlite3-api-cleanup.js 149fd63a0400cd1d69548887ffde2ed89c13283384 F ext/wasm/api/sqlite3-api-glue.js 82c09f49c69984009ba5af2b628e67cc26c5dd203d383cd3091d40dab4e6514b F ext/wasm/api/sqlite3-api-oo1.js a3469bbb217b9787ba9aa6216423ec55cf9457fecefb9698e433d0e1cc4cc918 F ext/wasm/api/sqlite3-api-opfs.js c93cdd14f81a26b3a64990515ee05c7e29827fbc8fba4e4c2fef3a37a984db89 -F ext/wasm/api/sqlite3-api-prologue.js 0fb0703d2d8ac89fa2d4dd8f9726b0ea226b8708ac34e5b482df046e147de0eb +F ext/wasm/api/sqlite3-api-prologue.js c0f335bf8b44071da0204b8fa95ce78fd737033b155e7bcfdaee6ae64600802f F ext/wasm/api/sqlite3-api-worker.js 1124f404ecdf3c14d9f829425cef778cd683911a9883f0809a463c3c7773c9fd F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 -F ext/wasm/api/sqlite3-wasm.c 0b3f56078f3e3806fb6dfbc756198d1634d3bfdbf3677c77702cf453c4ed336a +F ext/wasm/api/sqlite3-wasm.c 0e78035045e3328fb050ec9580c6bfb714c756a1d3b917259e58baf9b0332c98 F ext/wasm/api/sqlite3-worker.js 1325ca8d40129a82531902a3a077b795db2eeaee81746e5a0c811a04b415fa7f F ext/wasm/common/SqliteTestUtil.js e41a1406f18da9224523fad0c48885caf995b56956a5b9852909c0989e687e90 F ext/wasm/common/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f @@ -503,9 +503,9 @@ F ext/wasm/jaccwabyt/jaccwabyt.md 447cc02b598f7792edaa8ae6853a7847b8178a18ed356a F ext/wasm/jaccwabyt/jaccwabyt_test.c 39e4b865a33548f943e2eb9dd0dc8d619a80de05d5300668e9960fff30d0d36f F ext/wasm/jaccwabyt/jaccwabyt_test.exports 5ff001ef975c426ffe88d7d8a6e96ec725e568d2c2307c416902059339c06f19 F ext/wasm/testing1.html 0bf3ff224628c1f1e3ed22a2dc1837c6c73722ad8c0ad9c8e6fb9e6047667231 -F ext/wasm/testing1.js cba7134901a965743fa9289d82447ab71de4690b1ee5d06f6cb83e8b569d7943 +F ext/wasm/testing1.js a25069e20d5f8dc548cc98bcf7002cec812084421a1f7f70ffae2c706d1167b2 F ext/wasm/testing2.html 73e5048e666fd6fb28b6e635677a9810e1e139c599ddcf28d687c982134b92b8 -F ext/wasm/testing2.js d37433c601f88ed275712c1cfc92d3fb36c7c22e1ed8c7396fb2359e42238ebc +F ext/wasm/testing2.js 1cd14be666e40da41d7eea5723b1953ce54f1077c199887a73d3d5cfb71dbd05 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 @@ -1999,8 +1999,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 e37dddc1dd9c0530e4b1c6cb0ca7cba7451caa37734d383c9b47f378d7222242 -R 988d3478699d43ef2ce9b5c2bc8119e6 +P 3bc510a614973eafa60960a99bedb063594a693bdbfd80d7eb480b293b4ab811 +R a2b4eef7c61958031f6931d9df602912 U stephan -Z c96da5568e2699a3b63963443a07c191 +Z 3b291cb3c0f3e97625538cf3bb7fa23a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f61125d96..91690836d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3bc510a614973eafa60960a99bedb063594a693bdbfd80d7eb480b293b4ab811
\ No newline at end of file +41045be752a5bd7966849638f3ca56f4905308df70f79f2cb6196ca7dce9d525
\ No newline at end of file |