From: stephan Date: Wed, 24 Jun 2026 09:09:02 +0000 (+0000) Subject: Teach the JS build to filter out various APIs/VFSes when passed omit-api='api names... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bf98a1f6b6a3f6c143a79492bb3a518a5ae13eca;p=thirdparty%2Fsqlite.git Teach the JS build to filter out various APIs/VFSes when passed omit-api='api names...'. Fully trimmed this saves just shy of 300kb from the JS. Make loud=1 mode distinctly louder when preprocessing. FossilOrigin-Name: 2603c855795fc9466522b1e10433efd5e30975e68ee891680f27f06f3189390b --- diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 4bbdfa9fd8..0b32872e0d 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -208,6 +208,16 @@ b.cp = $(call b.mkdir@); \ echo '$(logtag.$(1)) $(emo.disk) $(2) ==> $3'; \ cp -f -p $(2) $(3) || exit +# D.common = flags to use for all $(bin.c-pp) invocations. These must +# passed before any input file names because c-pp's args are processed +# in their given order. +# +# Maintenance reminder: we cannot include -@policy=error here because +# of the @sqlite3.wasm@ placeholders in JS files, which trigger an +# error before we get to handle that filename juggling. Most JS files +# defensively set a file-local @policy. +D.common = + # # $(call b.c-pp.shcmd,LOGTAG,src,dest,-Dx=y...) # @@ -221,7 +231,9 @@ b.cp = $(call b.mkdir@); \ define b.c-pp.shcmd $(call b.mkdir@); \ $(call b.echo,$(1),$(emo.disk)$(emo.lock)[$(3)] $(4)); \ -rm -f $(3); $(bin.c-pp) -o $(3) $(4) $(2) || exit; \ +rm -f $(3); \ +if [ x1 = x$(loud.if) ]; then set -x; fi; \ +$(bin.c-pp) -o $(3) $(D.common) $(4) $(2) || exit; \ chmod -w $(3) endef @@ -234,7 +246,7 @@ endef define b.c-pp.target $(3): $$(MAKEFILE_LIST) $$(bin.c-pp) $(2) @$$(call b.mkdir@) - @$$(call b.c-pp.shcmd,$(1),$(2),$(3),$(4) $$(b.c-pp.target.flags)) + @$$(call b.c-pp.shcmd,$(1),$(2),$(3),$(4)) CLEAN_FILES += $(3) endef @@ -352,6 +364,7 @@ else SQLITE_C_IS_SEE = 0 else SQLITE_C_IS_SEE = 1 + D.common += -Denable-see $(info $(emo.lock)$(emo.lock)$(emo.lock) This is an SEE build $(emo.lock)$(emo.lock)$(emo.lock)) endif endif @@ -564,7 +577,7 @@ WASM_CUSTOM_INSTANTIATE = 1 # build. They are solely for use with $(bin.c-pp) itself. # # -D... flags which should be included in all invocations should be -# appended to $(b.c-pp.target.flags). +# appended to $(D.common) # bin.c-pp = ./c-pp $(bin.c-pp): libcmpp.c $(sqlite3.c) $(MAKEFILE) @@ -575,13 +588,26 @@ $(bin.c-pp): libcmpp.c $(sqlite3.c) $(MAKEFILE) '-DCMPP_DEFAULT_DELIM="//#"' -DCMPP_MAIN -DCMPP_OMIT_D_MODULE \ -DCMPP_OMIT_D_PIPE DISTCLEAN_FILES += $(bin.c-pp) -b.c-pp.target.flags ?= -ifeq (1,$(SQLITE_C_IS_SEE)) - b.c-pp.target.flags += -Denable-see -endif -api.oo1 ?= 1 -ifeq (0,$(api.oo1)) - b.c-pp.target.flags += -Domit-oo1 + +ifeq (0,$(MAKING_CLEAN)) + # omit-api="feature names..." disables various featuresw by name. + # Recognized names are: kvvfs oo1 opfs opfs-sahpool opfs-wl. The name + # OPFS is shorthand for all of the OPFS VFSes. For-nodejs builds + # filter out OPFS from withni the OPFS-using files so OPFS is implied + # for those builds. + D.omit = + ifneq (,$(omit-api)) + # Translate omit-api="X Y" into -Domit-X... + Xomit-api = $(subst OPFS,opfs opfs-sahpool opfs-wl,$(omit-api)) + $(foreach X,$(Xomit-api),$(eval D.omit += -Domit-$(X))) + endif + ifneq (,$(D.omit)) + D.common += $(D.omit) + $(info $(achtung): *******************************************************************) + $(info $(achtung): Be sure to do 'make clean' before using custom omit-api flags.) + $(info $(achtung): Omit flags: $(D.omit)) + $(info $(achtung): *******************************************************************) + endif endif # diff --git a/ext/wasm/api/opfs-common-shared.c-pp.js b/ext/wasm/api/opfs-common-shared.c-pp.js index f4cfe387eb..ce18647495 100644 --- a/ext/wasm/api/opfs-common-shared.c-pp.js +++ b/ext/wasm/api/opfs-common-shared.c-pp.js @@ -1,4 +1,4 @@ -//#if not target:node +//#if not target:node and (not omit-opfs or not omit-opfs-wl) /* 2026-03-04 @@ -1303,4 +1303,4 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }/*createVfsState()*/; }/*sqlite3ApiBootstrap.initializers*/); -//#/if target:node +//#/if global snip diff --git a/ext/wasm/api/pre-js.c-pp.js b/ext/wasm/api/pre-js.c-pp.js index fbb48f9eac..98ed6fa72d 100644 --- a/ext/wasm/api/pre-js.c-pp.js +++ b/ext/wasm/api/pre-js.c-pp.js @@ -17,9 +17,9 @@ /** This file was preprocessed using: -//#@ policy error +//#@ policy error << @c-pp::argv@ -//#@ policy off +//#/@ */ //#if unsupported-build /** diff --git a/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js index 4e94f3c8a4..dd54c960b5 100644 --- a/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js @@ -23,9 +23,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ /* These are JS plumbing, not part of the public API */ delete sqlite3.capi.sqlite3_kvvfs_methods; delete sqlite3.capi.KVVfsFile; -} +}); //#else -//#@ policy error +//#@ push policy error //#savepoint begin //#define kvvfs-v2-added-in "3.52.0" @@ -2095,4 +2095,5 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ })/*globalThis.sqlite3ApiBootstrap.initializers*/; //#savepoint rollback -//#/if not omit-kvvfs +//#@ pop policy +//#/if kvvfs disabled diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index 3df520c0e6..fff6b34e00 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -3006,6 +3006,13 @@ globalThis.sqlite3InitModule = sqlite3InitModule; //////////////////////////////////////////////////////////////////////// T.g('kvvfs') +//#if omit-kvvfs + .t({ + name: 'kvvfs', + predicate: ()=>'kvvfs disabled by omit-kvvfs', + test: ()=>{} + }) +//#else .t({ name: 'kvvfs v1 API availability', test: function(sqlite3){ @@ -3029,7 +3036,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; 'estimateSize', 'clear'] ){ T.assert( k[n] instanceof Function ); } - if( 0 ){ const scope = wasm.scopedAllocPush(); try{ @@ -3146,7 +3152,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; (new JDb(name)).close(); T.assert( sqlite3.kvvfs.unlink(name) ); } - sqlite3.kvvfs.clear(filename); let db = new JDb(filename); const sqlSetup = [ @@ -3176,7 +3181,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; }; T.assert(3 === db.selectValue('select count(*) from kvvfs')); close(); - const exportDb = sqlite3.kvvfs.export; db = new JDb(filename); db.exec('insert into kvvfs(a) values(4),(5),(6)'); @@ -3187,7 +3191,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; .assert( exp?.pages?.length > 0, "Missing db pages" ); console.debug("kvvfs to Object:",exp); close(); - const dbFileRaw = 'file:new-storage?vfs=kvvfs&delete-on-close=1'; db = new DB({ filename: dbFileRaw, @@ -3200,7 +3203,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; debug("kvvfs to Object:",exportDb(dbFilename)); const n = sqlite3.kvvfs.estimateSize( dbFilename ); T.assert( n>0, "Db size count failed" ); - if( 1 ){ // Concurrent open of that same name uses the same storage const x = new JDb(dbFilename); @@ -3239,7 +3241,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; 'insert into kvvfs(a) values(1),(2),(3)' ]; const sqlCount = 'select count(*) from kvvfs'; - try { const exportDb = sqlite3.kvvfs.export; const dbFileRaw = 'file:'+filename+'?vfs=kvvfs&delete-on-close=1'; @@ -3247,7 +3248,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; db = new DB(dbFileRaw); db.exec(sqlSetup); T.assert(3 === db.selectValue(sqlCount)); - duo = new JDb(filename); duo.exec('insert into kvvfs(a) values(4),(5),(6)'); T.assert(6 === db.selectValue(sqlCount)); @@ -3266,10 +3266,8 @@ globalThis.sqlite3InitModule = sqlite3InitModule; try{ddb.selectValue('select a from kvvfs')} finally{ddb.close()} }, /.*no such table: kvvfs.*/); - T.assert( kvvfs.unlink(filename) ) .assert( !kvvfs.exists(filename) ); - const importDb = sqlite3.kvvfs.import; duo = new JDb(dbFileRaw); T.mustThrowMatching(()=>importDb(exp,true), /.*in use.*/); @@ -3289,10 +3287,8 @@ globalThis.sqlite3InitModule = sqlite3InitModule; .assert(expectRows === duo.selectValue(sqlCount), "Unexpected row count after rollback"); duo.close(); - T.assert( kvvfs.unlink(filename) ) .assert( !kvvfs.exists(filename) ); - importDb(exp, true); db = new JDb({ filename, @@ -3326,7 +3322,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; "Unexpected record count."); q1.finalize(); q2.finalize(); - if( 1 ){ debug("Begin vacuum/page size test..."); const defaultPageSize = 1024 * 8 /* build-time default */; @@ -3374,7 +3369,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; }else{ expectRows = 6; } - db.close(); duo.close(); T.assert( kvvfs.unlink(exp.name) ) @@ -3385,7 +3379,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; //debug("column count after export",db.selectValue(sqlCount)); T.assert(expectRows === db.selectValue(sqlCount), "Unexpected record count."); - /* TODO: more advanced concurrent use tests, e.g. looping over a query in one connection while writing from @@ -3402,7 +3395,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; } } }/*concurrent transient kvvfs*/) - .t({ name: 'kvvfs listeners (experiment)', test: function(sqlite3){ @@ -3434,7 +3426,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; throw e; } }; - const listener = { storage: filename, reserve: true, @@ -3515,7 +3506,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; } } }; - kvvfs.listen(listener); const dbFileRaw = 'file:'+filename+'?vfs=kvvfs&delete-on-close=1'; const expOpt = { @@ -3584,7 +3574,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; } } })/*kvvfs listeners */ - .t({ name: 'kvvfs vtab', predicate: (sqlite3)=>!!sqlite3.kvvfs.create_module, @@ -3614,7 +3603,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; } } })/* kvvfs vtab */ - //#if enable-see .t({ name: 'kvvfs SEE encryption in sessionStorage', @@ -3630,6 +3618,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; } })/*kvvfs with SEE*/ //#/if enable-see +//#/if kvvfs ;/* end kvvfs tests */ //////////////////////////////////////////////////////////////////////// diff --git a/manifest b/manifest index 884ae40c1b..452eee73e8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\spreprocessor\sguards\sto\svarious\sJS\sfiles\sworking\stowards\sthe\sability\sto\sbuild,\se.g.,\swith\sonly\sone\sof\svarious\sVFSes\sincluded.\sThe\smakefile\sdoes\snot\syet\sintegrate\sthese\s-\sthis\sis\san\sincremental\sstep\stowards\saddressing\sthe\sdiscussion\sin\s[https://github.com/sqlite/sqlite-wasm/pull/168|the\sdownstream\snpm\sproject's\sPR#168]. -D 2026-06-23T20:42:48.622 +C Teach\sthe\sJS\sbuild\sto\sfilter\sout\svarious\sAPIs/VFSes\swhen\spassed\somit-api='api\snames...'.\sFully\strimmed\sthis\ssaves\sjust\sshy\sof\s300kb\sfrom\sthe\sJS.\sMake\sloud=1\smode\sdistinctly\slouder\swhen\spreprocessing. +D 2026-06-24T09:09:02.369 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -577,7 +577,7 @@ F ext/session/sessionwor.test 6fd9a2256442cebde5b2284936ae9e0d54bde692d0f5fd009e F ext/session/sqlite3session.c ce9f2ce2cc6b17f46854788e47016ba9be1b59ca4037728b6c025397b98edb12 F ext/session/sqlite3session.h ca7c4422c1514a95056cc8d333217df6b1829d39058126b1de85d10cd62d7a9c F ext/session/test_session.c d3275da24b8d362e3c2b393c00d5248f75f1cd474dadf29d8c4683f75cb52e6d -F ext/wasm/GNUmakefile 1d76d4017ed0b7bd2a8cc079c437cd09d20a0f0fb99f488d2466703c38409cb2 +F ext/wasm/GNUmakefile 04971634a5e107963e7dc097255eb621ba6a6a393a6f6953994d9cb0676d68c1 F ext/wasm/README-dist.txt f01081a850ce38a56706af6b481e3a7878e24e42b314cfcd4b129f0f8427066a F ext/wasm/README.md 2e87804e12c98f1d194b7a06162a88441d33bb443efcfe00dc6565a780d2f259 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -590,10 +590,10 @@ F ext/wasm/api/README.md a905d5c6bfc3e2df875bd391d6d6b7b48d41b43bdee02ad115b4724 F ext/wasm/api/extern-post-js.c-pp.js 80accc53cc6ea1e61c721595f42ba95baa7c7ea636807d9507e69403301f8c54 F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 F ext/wasm/api/opfs-common-inline.c-pp.js 496ca858af09b7fef2efaece467960611d35f57254078424bcdeac42ded9e85d -F ext/wasm/api/opfs-common-shared.c-pp.js d0a62a1d367d850d8e07c06e82499a5006f347e4025dbd59a8623048d858e7a1 +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 d6bf82f83f60caa2904bddb95a29cb738b310f672d2796cdc5fe54463ab0d6cd +F ext/wasm/api/pre-js.c-pp.js 949c1a9bdee2457d2a8d9ba9b362634b19d3aa71241fad348aab01ba2cde0c1a 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 @@ -601,7 +601,7 @@ F ext/wasm/api/sqlite3-api-worker1.c-pp.js 1fa34e9b0e3b90a8898e4f700d7125e44c818 F ext/wasm/api/sqlite3-license-version-header.js 98d90255a12d02214db634e041c8e7f2f133d9361a8ebf000ba9c9af4c6761cc F ext/wasm/api/sqlite3-opfs-async-proxy.c-pp.js 25e31482b04293a33d7599f1459eb552b3eb36ca10c02c816122d3308bf80cb2 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d -F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js 021e6b07d12d93b061de2681a225cd709eccb7e59271342ef7731b637cb714a2 +F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js 2d41f4d4ddf4cfd4e46717dba2ce3a92e72f28061db3dc690acfe8cb9ff8e447 F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 91f864f95c7195378b968cd4612e54b294e2e0445125a15f8626139de39c0462 F ext/wasm/api/sqlite3-vfs-opfs-wl.c-pp.js 60fa106fc11d31adb1773ac16dd60fc9335a35496b0ca7bab8b4032cb61a441b F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 5dd8410121acf623ce53005a4aab2c7b2b7f5d1ad072f69ebc208882bc7b7236 @@ -649,7 +649,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.c-pp.html 7171022e7f4da8f46e5f50ea81dd6ce840b9235c47653a5deeb3764ccc2fe472 F ext/wasm/tester1.c-pp.html bd927ccf51ddd65e924660a0487add99e1b044afe03950e49d87ccf44efdddb6 -F ext/wasm/tester1.c-pp.js 273f98ed9423c428e582e741b8097567fb6581c34f3c22427d7e02d400aa5743 +F ext/wasm/tester1.c-pp.js 996e0b0cd2d8fa1c69898b9ac4c3621cc8413154e3bf8f2c4804bc099c9a5abd F ext/wasm/tests/opfs/concurrency/index.html 706eab6308343c04ac2360aba6001af4ffaf46d8f33a0ccd02c64d93e3216a43 F ext/wasm/tests/opfs/concurrency/test.js 6919778fceaac1b7cc78caf41d796f545d2c4433b31188aa9689f05b5ad28828 F ext/wasm/tests/opfs/concurrency/worker.js 704d82c5e287e47f612349e027765943a58ad967dcf178fb5a1c3a8eaafb09af @@ -2208,12 +2208,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P e458ed9cc9d46dfdade3b4e99eb209d8aefd40a245e002d68df1813f9f99e2d7 -Q +9b9b0b733a1f61ea78954f264da5030dc54f8f6a31f99561de79dcb9493d936a -R 56e66b420bb94f9a8595833d5a976eba -T *branch * js-omit-pieces -T *sym-js-omit-pieces * -T -sym-trunk * Cancelled\sby\sbranch. +P f6618a693b7b71f4b846fac257100d3a516dcda687b039d24bcaf29dd1c7454b +R b422235db3953ae7fcd502a39dc5f1c5 U stephan -Z 97e3f1d01d9e7b9975baf540f221c2f1 +Z 210f113079ad31e99cab5029ed6f532d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 929ab908a6..68539356f4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f6618a693b7b71f4b846fac257100d3a516dcda687b039d24bcaf29dd1c7454b +2603c855795fc9466522b1e10433efd5e30975e68ee891680f27f06f3189390b