]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Further minor cleanups in the JS build related to vanilla vs ESM.
authorstephan <stephan@noemail.net>
Sun, 20 Nov 2022 05:36:52 +0000 (05:36 +0000)
committerstephan <stephan@noemail.net>
Sun, 20 Nov 2022 05:36:52 +0000 (05:36 +0000)
FossilOrigin-Name: 100a596800eca61477d9880092465d594c22be3707f2a11aaf6eb9e234fc6f2d

ext/wasm/GNUmakefile
ext/wasm/api/extern-post-js.js
ext/wasm/dist.make
ext/wasm/tester1-esm.html [deleted file]
ext/wasm/tester1-worker.html
ext/wasm/tester1.c-pp.html [moved from ext/wasm/tester1.html with 69% similarity]
manifest
manifest.uuid

index f803696c6e2909a654656e3aa891dc842a5fb1ea..647044665cfb6aeb8dc7a22a6f714e1cd1351d86 100644 (file)
@@ -24,7 +24,8 @@
 # Required tools beyond those needed for the canonical builds:
 #
 # - Emscripten SDK: https://emscripten.org/docs/getting_started/downloads.html
-# - GNU make, GNU sed, GNU awk, GNU grep
+# - The bash shell
+# - GNU make, GNU sed, GNU awk, GNU grep (all in the $PATH)
 # - wasm-strip for release builds: https://github.com/WebAssembly/wabt
 # - InfoZip for 'dist' zip file
 ########################################################################
@@ -426,7 +427,7 @@ endef
 ########################################################################
 # emcc flags for .c/.o/.wasm/.js.
 emcc.flags :=
-ifeq (1,$(verbose))
+ifeq (1,$(emcc.verbose))
 emcc.flags += -v
 # -v is _very_ loud but also informative about what it's doing
 endif
@@ -490,10 +491,19 @@ emcc.jsflags += $(emcc.environment)
 ########################################################################
 # $(sqlite3.js.init-func) is the name Emscripten assigns our exported
 # module init/load function. This symbol name is hard-coded in
-# $(extern-post-js.js) as well as in numerous docs. If changed, it
-# needs to be globally modified in *.js and all related documentation.
-# Note that changing it will break client applications, so never
-# change it unless you're creating a custom deliverable.
+# $(extern-post-js.js) as well as in numerous docs.
+#
+# "sqlite3InitModule" is the symbol we document for client use, so
+# that's the symbol name which must be exported, whether it comes from
+# Emscripten or our own code in extern-post-js.js.
+#
+# That said... we can change $(sqlite3.js.init-func) as long as the
+# name "sqlite3InitModule" is the one which gets exposed via the
+# resulting JS files. That can be accomplished via
+# extern-post-js.js. However...  using a temporary symbol name here
+# and then adding sqlite3InitModule() ourselves results in 2 global
+# symbols: we cannot "delete" the Emscripten-defined
+# $(sqlite3.js.init-func) because it's declared with "var".
 sqlite3.js.init-func := sqlite3InitModule
 emcc.jsflags += -sEXPORT_NAME=$(sqlite3.js.init-func)
 emcc.jsflags += -sGLOBAL_BASE=4096 # HYPOTHETICALLY keep func table indexes from overlapping w/ heap addr.
@@ -562,8 +572,23 @@ $(sqlite3.js) $(sqlite3.mjs): $(MAKEFILE) $(sqlite3.wasm.obj) \
     $(EXPORTED_FUNCTIONS.api)
 $(sqlite3.js):  $(pre-post-sqlite3.deps.vanilla)
 $(sqlite3.mjs): $(pre-post-sqlite3.deps.esm)
+########################################################################
 # SQLITE3.xJS.RECIPE = the $(call)able recipe body for $(sqlite3.js)
 # and $(sqlite3.mjs). $1 = one of (vanilla, esm).
+#
+# Reminder for ESM builds: even if we use -sEXPORT_ES6=0, emcc _still_
+# adds:
+#
+#   export default $(sqlite3.js.init-func);
+#
+# when building *.mjs, which is bad because we need to export an
+# overwritten version of that function and cannot "export default"
+# twice. Because of this, we have to sed $(sqlite3.mjs) to remove the
+# _first_ instance (only) of /^export default/.
+#
+# Upstream RFE:
+# https://github.com/emscripten-core/emscripten/issues/18237
+########################################################################
 define SQLITE3.xJS.RECIPE
        @echo "Building $@ ..."
        $(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \
@@ -584,26 +609,19 @@ define SQLITE3.xJS.RECIPE
 endef
 emcc.flags.sqlite3.vanilla :=
 emcc.flags.sqlite3.esm := -sEXPORT_ES6 -sUSE_ES6_IMPORT_META
-# Reminder for ESM build: even if we use -sEXPORT_ES6=0, emcc _still_
-# adds:
-#
-#   export default $(sqlite3.js.init-func);
-#
-# when building *.mjs, which is bad because we need to export an
-# overwritten version of that function and cannot "export default"
-# twice. Because of this, we have to sed $(sqlite3.mjs) to remove the
-# _first_ instance (only) of /^export default/.
 $(sqlite3.js):
        $(call SQLITE3.xJS.RECIPE,vanilla)
 $(sqlite3.mjs):
        $(call SQLITE3.xJS.RECIPE,esm)
-$(sqlite3.wasm): $(sqlite3.js)
-$(sqlite3.mjs): $(sqlite3.js)
+########################################################################
 # We have to ensure that we do not build both $(sqlite3.js) and
-# $(sqlite3.mjs) in parallel because both result in the build of
+# $(sqlite3.mjs) in parallel because both result in the creation of
 # $(sqlite3.wasm). We have no(?) way to build just the .mjs file
 # without also building the .wasm file. i.e.  we're building
-# $(sqlite3.wasm) twice, but that's apparently unavoidable.
+# $(sqlite3.wasm) twice, but that's apparently unavoidable (and
+# harmless, just a waste of build time).
+$(sqlite3.wasm): $(sqlite3.js)
+$(sqlite3.mjs): $(sqlite3.js)
 CLEAN_FILES += $(sqlite3.js) $(sqlite3.mjs) $(sqlite3.wasm)
 all: $(sqlite3.mjs)
 wasm: $(sqlite3.mjs)
@@ -717,12 +735,14 @@ CLEAN_FILES += $(speedtest1.js) $(speedtest1.wasm)
 # To that end, we require two separate builds of tester1.js:
 # 
 #  tester1.js: cases 1 and 2
-#  tester1-esm.js: cases 3 and 4
+#  tester1.mjs: cases 3 and 4
 #
 # 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-esm.js,$(c-pp.D.esm)))
-tester1: tester1.js tester1-esm.js
+$(eval $(call C-PP.FILTER,tester1.c-pp.js,tester1.mjs,$(c-pp.D.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)))
+tester1: tester1.js tester1.mjs tester1.html tester1-esm.html
 all: tester1
 
 ########################################################################
@@ -794,8 +814,8 @@ endif
 
 ########################################################################
 # Push files to public wasm-testing.sqlite.org server
-wasm-testing.include = $(dir.dout) *.js *.html \
-    batch-runner.list $(dir.sql) $(dir.common) $(dir.fiddle) $(dir.jacc)
+wasm-testing.include = *.js *.html batch-runner.list \
+  $(dir.dout) $(dir.sql) $(dir.common) $(dir.fiddle) $(dir.jacc)
 wasm-testing.exclude = sql/speedtest1.sql
 wasm-testing.dir     = /jail/sites/wasm-testing
 wasm-testing.dest   ?= wasm-testing:$(wasm-testing.dir)
index acf7068fefb8c9eccb9549ba0a4f5d875fd85991..cace6ed51c5bd17f16c4b8b1a5c681e2d140dc54 100644 (file)
@@ -13,19 +13,20 @@ const toExportForES6 =
 //#endif
 (function(){
   /**
-     In order to hide the sqlite3InitModule()'s resulting Emscripten
-     module from downstream clients (and simplify our documentation by
-     being able to elide those details), we rewrite
-     sqlite3InitModule() to return the sqlite3 object.
+     In order to hide the sqlite3InitModule()'s resulting
+     Emscripten module from downstream clients (and simplify our
+     documentation by being able to elide those details), we hide that
+     function and expose a hand-written sqlite3InitModule() to return
+     the sqlite3 object (most of the time).
 
      Unfortunately, we cannot modify the module-loader/exporter-based
      impls which Emscripten installs at some point in the file above
      this.
   */
   const originalInit =
-        /*Maintenance reminde: 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;
+        /* 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;
   if(!originalInit){
     throw new Error("Expecting self.sqlite3InitModule to be defined by the Emscripten build.");
   }
@@ -104,10 +105,11 @@ const toExportForES6 =
   }
   /* Replace the various module exports performed by the Emscripten
      glue... */
-  if (typeof exports === 'object' && typeof module === 'object')
+  if (typeof exports === 'object' && typeof module === 'object'){
     module.exports = sqlite3InitModule;
-  else if (typeof exports === 'object')
+  }else if (typeof exports === 'object'){
     exports["sqlite3InitModule"] = sqlite3InitModule;
+  }
   /* AMD modules get injected in a way we cannot override,
      so we can't handle those here. */
   return self.sqlite3InitModule /* required for ESM */;
index b64663c105211d65fead4625f157a4b3e8a8c564..6cd4e48e6b300308cb51382cff1497f20c64a87e 100644 (file)
@@ -6,6 +6,10 @@
 # 'make dist' rules for creating a distribution archive of the WASM/JS
 # pieces, noting that we only build a dist of the built files, not the
 # numerous pieces required to build them.
+#
+# Use 'make snapshot' to create "snapshot" releases. They use a
+# distinctly different zip file and top directory name to distinguish
+# them from release builds.
 #######################################################################
 MAKEFILE.dist := $(lastword $(MAKEFILE_LIST))
 
diff --git a/ext/wasm/tester1-esm.html b/ext/wasm/tester1-esm.html
deleted file mode 100644 (file)
index 498a1ab..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<!doctype html>
-<html lang="en-us">
-  <head>
-    <meta charset="utf-8">
-    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-    <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
-    <link rel="stylesheet" href="common/emscripten.css"/>
-    <link rel="stylesheet" href="common/testing.css"/>
-    <title>sqlite3 tester #1: ES6 Module in UI thread</title>
-    <style>
-      body {
-          font-family: monospace;
-      }
-    </style>
-  </head>
-  <body>
-    <h1 id='color-target'>sqlite3 tester #1: ES6 Module in UI thread</h1>
-    <div class='input-wrapper'>
-      <input type='checkbox' id='cb-log-reverse'>
-      <label for='cb-log-reverse'>Reverse log order?</label>
-    </div>
-    <div id='test-output'></div>
-    <script src="tester1-esm.js" type="module"></script>
-  </body>
-</html>
index b750df9169320ac4c9aade786a0e37b00bcf8dc0..33ffa641866c0f57de232d25ef50158e0c458591 100644 (file)
@@ -46,7 +46,7 @@
           logHtml('warning',"Attempting to run an ES6 Worker Module, "+
                   "which is not supported by all browsers! "+
                   "e.g. Firefox (as of 2022-11) cannot do this.");
-        workerArgs.push("tester1-esm.js",{type:"module"});
+        workerArgs.push("tester1.mjs",{type:"module"});
         document.querySelectorAll('title,#color-target').forEach((e)=>{
           e.innerText = "sqlite3 tester #1: ES6 Worker Module";
         });
similarity index 69%
rename from ext/wasm/tester1.html
rename to ext/wasm/tester1.c-pp.html
index f7a2fba4af6ba9cd92520136e5c7c2017a140eb3..b1b68e486e202aed7892eba2ed7f7dc5b15c273f 100644 (file)
@@ -6,7 +6,13 @@
     <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
     <link rel="stylesheet" href="common/emscripten.css"/>
     <link rel="stylesheet" href="common/testing.css"/>
-    <title>sqlite3 tester #1 (UI thread)</title>
+    <title>sqlite3 tester #1:
+//#if target=es6-module
+ES6 Module in UI thread
+//#else
+UI thread
+//#endif
+    </title>
     <style>
       body {
           font-family: monospace;
@@ -14,7 +20,7 @@
     </style>
   </head>
   <body>
-    <h1 id='color-target'>sqlite3 WASM/JS tester #1 (UI thread)</h1>
+    <h1 id='color-target'></h1>
     <div>See <a href='tester1-worker.html' target='tester1-worker.html'>tester1-worker.html</a>
       for the Worker-thread variant.</div>
     <div class='input-wrapper'>
       <label for='cb-log-reverse'>Reverse log order?</label>
     </div>
     <div id='test-output'></div>
+    <script>(function(){
+      document.querySelector('h1').innerHTML =
+        document.querySelector('title').innerHTML;
+    })();</script>
+//#if target=es6-module
+    <script src="tester1.mjs" type="module"></script>
+//#else
     <script src="jswasm/sqlite3.js"></script>
     <script src="tester1.js"></script>
+//#endif
   </body>
 </html>
index 8aaeeb13dfdc922601386c26c05fe7cb7d6245cc..85775d3bfd75dd4e77b1778b3f4df4fe40596e9e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\san\sobsolete\sreference\sto\sWASMFS\sfrom\sext/wasm/index.html.
-D 2022-11-20T04:14:29.454
+C Further\sminor\scleanups\sin\sthe\sJS\sbuild\srelated\sto\svanilla\svs\sESM.
+D 2022-11-20T05:36:52.173
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -488,13 +488,13 @@ 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 003235fe1156e208d66cefe43ff20248e190dd8e4a6d58c3bcf12039af514dce
+F ext/wasm/GNUmakefile 712795c4893ea65f8d30fe414937a33b677a194dd58372b4074aee17039c845e
 F ext/wasm/README-dist.txt 2d670b426fc7c613b90a7d2f2b05b433088fe65181abead970980f0a4a75ea20
 F ext/wasm/README.md ef39861aa21632fdbca0bdd469f78f0096f6449a720f3f39642594af503030e9
 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 9120c2f8f51fa85f46dcf4dcb6b12f4a807d428f6089b99cdb08d8ddfcfd88b2
 F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287
 F ext/wasm/api/README.md 29276a845e57004e82efba61fa5866fd05f9137380a1dc26dc4c6d65264cd81c
-F ext/wasm/api/extern-post-js.js 5a92c0afe8edbdfffc6831e60d7fd108594e37c4a364507035e7d3296589b153
+F ext/wasm/api/extern-post-js.js 59e52f579cd3a332d73dae94c91b9579daafb10dd6ada03803f1afa6bdad7689
 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 d6ab3dfef4a06960d28a7eaa338d4e2a1a5981e9b38718168bbde8fdb2a439b8
@@ -527,7 +527,7 @@ F ext/wasm/demo-worker1-promiser.html 1de7c248c7c2cfd4a5783d2aa154bce62d74c6de98
 F ext/wasm/demo-worker1-promiser.js b85a2bb1b918db4f09dfa24419241cb3edad7791389425c2505092e9b715017d
 F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d
 F ext/wasm/demo-worker1.js a619adffc98b75b66c633b00f747b856449a134a9a0357909287d80a182d70fa
-F ext/wasm/dist.make ff970852dbf879c8e29a3b060b4451d54ea309cc5373feb746bce96a256cfce8
+F ext/wasm/dist.make c9f06b520390fc5ab354b4b124e69c1cc648f97daf52df9de36a852fbdd7a4ea
 F ext/wasm/fiddle.make 2812c44c9bafb5be9c8767963d1b9f374d77af7795fcaa06483c03e7059dea74
 F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f
 F ext/wasm/fiddle/fiddle-worker.js b4a0c8ab6c0983218543ca771c45f6075449f63a1dcf290ae5a681b2cba8800d
@@ -549,10 +549,9 @@ F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d826
 F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5
 F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555e685bce3da8c3f
 F ext/wasm/test-opfs-vfs.js 44363db07b2a20e73b0eb1808de4400ca71b703af718d0fa6d962f15e73bf2ac
-F ext/wasm/tester1-esm.html aef2e711655660ece4f726ff88332238da2811b9fe7e4987d621f35f9f41d6b6
-F ext/wasm/tester1-worker.html 84d56db05bcea2b294a89ca13c21b76fa0521ca4ac240f0055f1819934c713fc
+F ext/wasm/tester1-worker.html 5ef353348c37cf2e4fd0b23da562d3275523e036260b510734e9a3239ba8c987
+F ext/wasm/tester1.c-pp.html 74aa9b31c75f12490653f814b53c3dd39f40cd3f70d6a53a716f4e8587107399 w ext/wasm/tester1.html
 F ext/wasm/tester1.c-pp.js 0c129495d057c77788b59715152d51f9bf9002ebbcce759ef8b028272ce3519d
-F ext/wasm/tester1.html 624ec41cd9f78a1f2b6d7df70aaa7a6394396b1f2455ecbd6de5775c1275b121
 F ext/wasm/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd72273503ae7d5
 F ext/wasm/wasmfs.make 8fea9b4f3cde06141de1fc4c586ab405bd32c3f401554f4ebb18c797401a678d
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
@@ -2057,8 +2056,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 d10f385e36ee7fe3077d80d8d6e7ce55732d20ef73e2a63533d8d2932ec8bf62
-R 37857805b3b6071fa9b37ce0a0873f80
+P 51ff681864ec19844f8e7a46aef132e8a8601a1b64e1f5a243a53c6413f2a61a
+R b4563c289dd01589021977b3acf0c574
 U stephan
-Z f1048ad4ae84ec54ea82e7fb7b483cf6
+Z ab7f6de1db50f486d71ae6e36cd71c04
 # Remove this line to create a well-formed Fossil manifest.
index 6db9a839dcfaf7710f7e7fb18fe24b2f8211915d..3140f0d9ea6f0757a198fb25dabd3f481c6e36b2 100644 (file)
@@ -1 +1 @@
-51ff681864ec19844f8e7a46aef132e8a8601a1b64e1f5a243a53c6413f2a61a
\ No newline at end of file
+100a596800eca61477d9880092465d594c22be3707f2a11aaf6eb9e234fc6f2d
\ No newline at end of file