From: stephan Date: Tue, 21 Jul 2026 13:28:52 +0000 (+0000) Subject: This embeds sqlite3.wasm into sqlite3.js/mjs as base64 but is applied globally -... X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=bee0db8c602a30551633e8775988393163e14f7e;p=thirdparty%2Fsqlite.git This embeds sqlite3.wasm into sqlite3.js/mjs as base64 but is applied globally - it still needs to be made configurable. FossilOrigin-Name: 0467a0f826b5b7bb65d9c74df80c7443f01824c1cc8184417849a74791f491b7 --- diff --git a/ext/wasm/api/pre-js.c-pp.js b/ext/wasm/api/pre-js.c-pp.js index 5c2e7a921e..c2d2a2784b 100644 --- a/ext/wasm/api/pre-js.c-pp.js +++ b/ext/wasm/api/pre-js.c-pp.js @@ -124,15 +124,20 @@ return this.emscriptenInstantiateWasm(imports, onSuccess); } const sims = this; -//#if defined sqlite3.wasm.base64 +//#// \ +{/* + The following block uses //% as a directive delimiter and is + replaced in a second pass after compilation of sqlite3.js. +*/} +//%if defined sqlite3.wasm.base64 let b64Wasm = ` -//#base64 -//#include -raw [arg sqlite3.wasm.base64] -//#/base64 +//%base64 +//%include -raw [arg sqlite3.wasm.base64] +//%/base64 `; const bytes = Uint8Array.fromBase64(b64Wasm); b64Wasm = null; - const finalThen = (arg) => { + const finalThen = (arg)=>{ arg.imports = imports; sims.instantiateWasm = arg; /* used by sqlite3-api-prologue.c-pp.js */ onSuccess(arg.instance, arg.module); @@ -140,12 +145,14 @@ WebAssembly.instantiate(bytes.buffer, imports) .then(finalThen) - .catch((err) => { + .catch((err)=>{ console.error("Failed to instantiate embedded sqlite3.wasm", err); + throw err; }); - return {}/* Emscripten interprets this to wait on async instantiation */; -//#else + return {}/* Emscripten interprets this to wait on async instantiation + via onSuccess(). */; +//%else const uri = Module.locateFile( sims.wasmFilename, ( ('undefined'===typeof scriptDirectory/*var defined by Emscripten glue*/) @@ -169,7 +176,7 @@ .then(bytes => WebAssembly.instantiate(bytes, imports)) .then(finalThen) return loadWasm(); -//#/if sqlite3.wasm.base64 +//%/if sqlite3.wasm.base64 pass 2 }.bind(sIMS); //#/if Module.instantiateWasm and not wasmfs })(Module); diff --git a/ext/wasm/mkwasmbuilds.c b/ext/wasm/mkwasmbuilds.c index ba5e51b73a..bcec683e13 100644 --- a/ext/wasm/mkwasmbuilds.c +++ b/ext/wasm/mkwasmbuilds.c @@ -764,9 +764,13 @@ static void emit_api_js(char const *zBuildName){ static void mk_lib_mode(const char *zBuildName, const BuildDef * pB){ const char * zJsExt = BuildDef_jsext(pB); char const * const zBaseName = BuildDef_basename(pB); + char const * const zDotWasm = pB + ? (pB->zDotWasm ? pB->zDotWasm : zBaseName) + : 0; assert( oBuildDefs.vanilla.zEnv ); assert( zBaseName ); + assert( zDotWasm ); pf("%s# Begin build [%s%s]. flags=0x%02x\n", zBanner, pB->zEmo, zBuildName, pB->flags); @@ -879,6 +883,17 @@ static void mk_lib_mode(const char *zBuildName, const BuildDef * pB){ pf("\t@$(call b.do.wasm-opt,%s)\n", zBuildName); pf("\t@$(call b.strip-js-emcc-bindings,$(logtag.%s))\n", zBuildName); + if( 1 ){ + pf("\techo 'Embedding $(out.%s.wasm) into $@ ...'\n" + "\t@mv $@ $@.in\n" + "\t$(call b.c-pp.shcmd,%s,$@.in,$@," + "\"--delimiter=//%%\" " + "\"-Dsqlite3.wasm.base64=$(out.%s.wasm)\"" + ")\n", + zBuildName, zBuildName, zBuildName); + pf("\t@rm -f $@.in\n"); + } + if( CP_JS & pB->flags ){ /* ** $(bin.emcc) will write out $@ and will create a like-named diff --git a/manifest b/manifest index 267f72f9fa..4185927a08 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C An\sinitial\sattempt\sat\sembedding\ssqlite3.wasm\sinto\ssqlite3.js\susing\sbase64.\sThis\sproduces\sa\schicken-egg\ssituation\sin\sthe\sbuild\sbecause\sthe\sinput\sfile\swhere\sthe\sblob\sbelongs\sis\sinjested\sby\semscripten\s(which\sgenerates\sthe\swasm\sfile\sfrom\swhich\sthat\sblob\sis\sto\sbe\sgenerated),\sso\sit\sdoes\snot\swork\sas-is\sbut\sis\sbeing\sset\saside\sfor\slater.\sWe'll\sneed\sto\sadd\sa\ssecond\spreprocessing\sstep\swhich\suses\sa\sdifferent\s#directive\sdelimiter\sto\skeep\sit\shidden\sinside\sthe\sfirst\spass,\sthen\ssqueeze\sthe\swasm\sfile\sin\sthrough\sthere. -D 2026-07-21T12:57:48.902 +C This\sembeds\ssqlite3.wasm\sinto\ssqlite3.js/mjs\sas\sbase64\sbut\sis\sapplied\sglobally\s-\sit\sstill\sneeds\sto\sbe\smade\sconfigurable. +D 2026-07-21T13:28:52.549 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -598,7 +598,7 @@ F ext/wasm/api/opfs-common-inline.c-pp.js 496ca858af09b7fef2efaece467960611d35f5 F ext/wasm/api/opfs-common-shared.c-pp.js 9a9019bcc070d7c90829af5f5eb81d25135bf9543944a691631c0184f0c62416 F ext/wasm/api/post-js-footer.js a50c1a2c4d008aede7b2aa1f18891a7ee71437c2f415b8aeb3db237ddce2935b F ext/wasm/api/post-js-header.js f35d2dcf1ab7f22a93d565f8e0b622a2934fc4e743edf3b708e4dd8140eeff55 -F ext/wasm/api/pre-js.c-pp.js c50ae08280f3ba27f4a466e27b612f09adf86b46ae66040aebf49d1842d572b9 +F ext/wasm/api/pre-js.c-pp.js 35b2ae330c8098f585fe2bf2bb3404cfa0b12ff46671d825687b1c79c1ec4ac4 F ext/wasm/api/sqlite3-api-glue.c-pp.js 31a721ada7225838a61310a9f3f797fa5275353f8e9b0ae769d85b437be061f5 F ext/wasm/api/sqlite3-api-oo1.c-pp.js 35e4727010f15fd72ead0dd1eb4e3c2c9bb1cc60e51544cbdff1f7c14f209de2 F ext/wasm/api/sqlite3-api-prologue.js 0084e15d66fbcd75cacbaa58e3b473d5e57082c30f3122be7fdadff5589cf6b6 @@ -638,7 +638,7 @@ F ext/wasm/jaccwabyt/jaccwabyt.js 4e2b797dc170851c9c530c3567679f4aa509eec0fab73b F ext/wasm/jaccwabyt/jaccwabyt.md 6aa90fa1a973d0ad10d077088bea163b241d8470c75eafdef87620a1de1dea41 F ext/wasm/libcmpp.c 5296a720aa95795617335fa0b3b4da5ea48150132251b85ca131bc6f2a21b066 F ext/wasm/mkdist.sh f8883b077a2ca47cf92e6f0ce305fbf72ca648c3501810125056c4b09c2d5554 x -F ext/wasm/mkwasmbuilds.c 3402400b432f7bff5eb9f4c65e99636b9c928a92cec37d8a9b6790ed578e57bd +F ext/wasm/mkwasmbuilds.c 412296dad75252cfd3f4c71288aa4947ec2da93287b336bdc0cec958f784b11f F ext/wasm/module-symbols.html e54f42112e0aac2a31f850ab33e7f2630a2ea4f63496f484a12469a2501e07e2 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 @@ -2217,11 +2217,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P 06f3bbc5bddc2e763042f8b487a3deedf47c54b7fa785ba6fd6abd524b4cbe3a -R 17e18b90e1608e97dcf702df348ee49d -T *branch * wasm-base64 -T *sym-wasm-base64 * -T -sym-trunk * Cancelled\sby\sbranch. +P 538199cf62f07a2fe7ee5775c9f01aff1644d638bc0916cf631d61376462b5cb +R cfcfa8bc897c97c9b5ebf70867bb8fcf U stephan -Z 745a489ee2ca72e98a604082d182941a +Z 45cbe61cb9c192f82469f625e6cedbe8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index db956d6be1..61bd54f428 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -538199cf62f07a2fe7ee5775c9f01aff1644d638bc0916cf631d61376462b5cb +0467a0f826b5b7bb65d9c74df80c7443f01824c1cc8184417849a74791f491b7