]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
More build restructuring.
authorstephan <stephan@noemail.net>
Tue, 23 Sep 2025 08:23:23 +0000 (08:23 +0000)
committerstephan <stephan@noemail.net>
Tue, 23 Sep 2025 08:23:23 +0000 (08:23 +0000)
FossilOrigin-Name: 7bee8ee76380b2c1beb320b55042f149c22f872c70b58461652fa5bcbf6ad3c7

ext/wasm/GNUmakefile
ext/wasm/mkwasmbuilds.c
manifest
manifest.uuid

index dd18137e2557d2f725b8d87ac037063603c8f5fa..7d6d254f98ddffc68512a43869db717aaa4b37eb 100644 (file)
@@ -210,10 +210,18 @@ endif
 ########################################################################@
 # It's important that sqlite3.h be built to completion before any
 # other parts of the build run, thus we use .NOTPARALLEL to disable
-# parallel build of that file and its dependants.
+# parallel build of that file and its dependants. However, that makes
+# the whole build non-parallelizable because everything has a dep on
+# sqlite3.h/c. The alternative is to force the user to run (make
+# sqlite3.c) from the top of the tree before running this build.
+#
 #.NOTPARALLEL: $(sqlite3.h)
 $(sqlite3.h):
-       $(MAKE) -C $(dir.top) sqlite3.c
+       @echo "$(sqlite3.h) is out of date. "; \
+       echo "To avoid problems with parallel builds, we're exiting now. Please do:"; \
+       echo "  $(MAKE) -C $(dir.top) sqlite3.c"; \
+       echo "and try again."; exit 1
+#      $(MAKE) -C $(dir.top) sqlite3.c
 $(sqlite3.c): $(sqlite3.h)
 
 ########################################################################
@@ -367,7 +375,6 @@ endif
 # info from $(bin.version-info) which differ from their runtime-emitted
 # version info (e.g. from sqlite3_libversion()).
 bin.version-info = $(dir.top)/version-info
-#.NOTPARALLEL: $(bin.version-info)
 $(bin.version-info): $(dir.tool)/version-info.c $(sqlite3.h) $(dir.top)/Makefile
        $(MAKE) -C $(dir.top) version-info
 
@@ -394,7 +401,7 @@ WASM_CUSTOM_INSTANTIATE = 0
 ########################################################################
 # SQLITE.CALL.C-PP.FILTER: a $(call)able to transform $(1) to $(2) via:
 #
-#   ./c-pp -f $(1) -o $(2) $(3)
+#   cat $(1) | ./c-pp -o $(2) $(3)
 #
 # Historical notes:
 #
@@ -500,10 +507,10 @@ endif
 # This snippet is intended to be used in makefile targets which
 # generate an Emscripten module and where $@ is the module's .js/.mjs
 # file.
-SQLITE.strip-createExportWrapper = \
+SQLITE.strip-emcc-js-cruft = \
   sed -i -e '/^.*= \(_sqlite3\|_fiddle\)[^=]*=.*createExportWrapper/d' \
   -e '/^var \(_sqlite3\|_fiddle\)[^=]*=.*makeInvalidEarlyAccess/d' $@ || exit; \
-  echo '(Probably) stripped out createExportWrapper() and makeInvalidEarlyAccess() parts.'
+  echo '[$@]: (Probably) stripped out createExportWrapper() and makeInvalidEarlyAccess() parts.'
 
 # When passing emcc_opt from the CLI, += and re-assignment have no
 # effect, so emcc_opt+=-g3 doesn't work. So...
@@ -829,7 +836,8 @@ sqlite3-wasmfs.cfiles = $(sqlite3-wasm.cfiles)
 # use awk instead of sed for this.
 define SQLITE.CALL.xJS.ESM-EXPORT-DEFAULT
 if [ x1 = x$(1) ]; then \
-               echo "Fragile workaround for emscripten/issues/18237. See SQLITE.CALL.xJS.ESM-EXPORT-DEFAULT."; \
+               echo "[$@]: Fragile workaround for emscripten/issues/18237." \
+               "See SQLITE.CALL.xJS.ESM-EXPORT-DEFAULT."; \
                {\
                        awk '/^export default/ && !f{f=1; next} 1' $@ > $@.tmp && mv $@.tmp $@; \
                } || exit $$?; \
@@ -1070,7 +1078,7 @@ $(speedtest1.js): $(MAKEFILE) $(speedtest1.cfiles) \
         -o $@ $(speedtest1.cfiles) -lm
        @chmod -x $(basename $@).wasm
        @$(maybe-wasm-strip) $(basename $@).wasm
-       @$(SQLITE.strip-createExportWrapper)
+       @$(SQLITE.strip-emcc-js-cruft)
        @ls -la $@ $(speedtest1.wasm)
 
 speedtest1: $(speedtest1.js)
index 985cbc8d4d16a67a710327e389bc6f84987b10ce..23dd7daccf0588bebf4373a1b339685c1c686cc3 100644 (file)
 #define pf printf
 #define ps puts
 
-/*
-** Valid build names. Each build is a combination of one of these and
-** one of JS_BUILD_MODES, but only certain combinations are legal.
-** This macro and JS_BUILD_MODES exist solely for documentation
-** purposes: they are not expanded into code anywhere.
-*/
-#define JS_BUILD_NAMES sqlite3 sqlite3-wasmfs
-
 /* Separator to help eyeballs find the different output sections */
 #define zBanner \
   "\n########################################################################\n"
 ** mk_pre_post().
 **
 ** Maintenance reminder: do not combine flags within this enum,
-** e.g. LIBMODE_BUNDLER_FRIENDLY=0x02|LIBMODE_ESM, as that will lead
+** e.g. F_BUNDLER_FRIENDLY=0x02|F_ESM, as that will lead
 ** to breakage in some of the flag checks.
 */
-enum LibModeFlags {
+enum {
   /* Indicates an ESM module build. */
-  LIBMODE_ESM = 0x01,
+  F_ESM              = 0x01,
   /* Indicates a "bundler-friendly" build mode. */
-  LIBMODE_BUNDLER_FRIENDLY = 0x02,
+  F_BUNDLER_FRIENDLY = 1<<1,
   /* Indicates that this build is unsupported. Such builds are not
   ** added to the 'all' target. The unsupported builds exist primarily
   ** for experimentation's sake. */
-  LIBMODE_UNSUPPORTED = 0x04,
+  F_UNSUPPORTED      = 1<<2,
   /* Elide this build from the 'all' target. */
-  LIBMODE_NOT_IN_ALL = 0x08,
-  LIBMODE_64BIT = 0x10,
+  F_NOT_IN_ALL       = 1<<3,
+  F_64BIT            = 1<<4,
   /* Indicates a node.js-for-node.js build (untested and
   ** unsupported). */
-  LIBMODE_NODEJS = 0x20,
+  F_NODEJS           = 1<<5,
   /* Indicates a wasmfs build (untested and unsupported). */
-  LIBMODE_WASMFS = 0x40
+  F_WASMFS           = 1<<6,
+
+
+  /**
+     Which compiled files from $(dir.dout)/buildName/*.{js,mjs,wasm}
+     to copy to $(dir.dout) after creating them.
+  */
+  CP_JS              = 1 << 30,
+  CP_WASM            = 1 << 31,
+  CP_ALL             = CP_JS | CP_WASM
 };
 
 /*
-** Info needed for building one combination of JS_BUILD_NAMES and
-** JS_BUILD_MODE, noting that only a subset of those combinations are
-** legal/sensical.
+** Info needed for building one concrete JS/WASM combination..
 */
 struct BuildDef {
   /**
      Base name of output JS and WASM files.
   */
   const char *zBaseName;
-  const char *zReuseThis;
+  const char *zDotWasm;
   const char *zCmppD;     /* Extra -D... flags for c-pp */
   const char *zEmcc;      /* Extra flags for emcc */
   const char *zEnv;       /* emcc -sENVIRONMENT=X flag */
@@ -104,11 +103,11 @@ typedef struct BuildDef BuildDef;
 #endif
 
 /* List of distinct library builds. See next comment block. */
-#define BuildDefs_map(E) \
-  E(vanilla) E(vanilla64) E(esm) E(esm64)
+#define BuildDefs_map(E)  \
+  E(vanilla) E(vanilla64) \
+  E(esm) E(esm64)         \
+  E(bundler) E(bundler64)
 /*
-  E(bundler) \
-  E(bundler64) \
   E(node) \
   E(wasmfs)
 */
@@ -132,88 +131,83 @@ const BuildDefs oBuildDefs = {
     /* This one's zBaseName and zEnv MUST be non-NULL so it can be
        used as a default for all others. */
     .zBaseName   ="sqlite3",
-    .zReuseThis  = 0,
+    .zDotWasm    = 0,
     .zCmppD      = 0,
     .zEmcc       = 0,
     .zEnv        = "web,worker",
-    .flags       = 0
+    .flags       = CP_ALL
   },
 
   .vanilla64 = {
-    .zBaseName   = "sqlite3",
-    .zReuseThis  = 0,
+    .zBaseName   = "sqlite3-64bit",
+    .zDotWasm    = 0,
     .zCmppD      = 0,
     .zEmcc       = "-sMEMORY64=1",
     .zEnv        = 0,
-    .flags       = LIBMODE_64BIT // | LIBMODE_NOT_IN_ALL
+    .flags       = CP_ALL | F_64BIT // | F_NOT_IN_ALL
   },
 
   .esm = {
     .zBaseName   = "sqlite3",
-    .zReuseThis  = 0,
+    .zDotWasm    = 0,
     .zCmppD      = "-Dtarget=es6-module",
     .zEmcc       = 0,
     .zEnv        = 0,
-    .flags       = LIBMODE_ESM
+    .flags       = CP_JS | F_ESM
   },
 
   .esm64 = {
-    .zBaseName   = 0,
-    .zReuseThis  = 0,
+    .zBaseName   = "sqlite3-64bit",
+    .zDotWasm    = 0,
     .zCmppD      = "-Dtarget=es6-module",
     .zEmcc       = "-sMEMORY64=1",
     .zEnv        = 0,
-    .flags       = LIBMODE_ESM | LIBMODE_64BIT // | LIBMODE_NOT_IN_ALL
+    .flags       = CP_JS | F_ESM | F_64BIT // | F_NOT_IN_ALL
   },
 
-#if 0
-
   .bundler = {
     /* Core bundler-friendly build. Untested and "not really"
     ** supported, but required by the downstream npm subproject.
     ** Testing these would require special-purpose node-based tools and
     ** custom test apps. Or we can pass them off as-is to the npm
     ** subproject and they spot failures pretty quickly ;). */
-    .zBaseName="sqlite3",
-    .zReuseThis=0,
-    .zCmppD="$(c-pp.D.sqlite3-esm) -Dtarget=es6-bundler-friendly",
-    .zEmcc=0,
-    .zEnv = 0,
-    .flags=LIBMODE_BUNDLER_FRIENDLY | LIBMODE_ESM
+    .zBaseName   = "sqlite3-bundler-friendly",
+    .zDotWasm    = "sqlite3",
+    .zCmppD      = "$(c-pp.D.esm) -Dtarget=es6-bundler-friendly",
+    .zEmcc       = 0,
+    .zEnv        = 0,
+    .flags       = CP_JS | F_BUNDLER_FRIENDLY | F_ESM
   },
 
   .bundler64 = {
-    .zBaseName="sqlite3",
-    .zReuseThis=0,
-    .zCmppD="$(c-pp.D.sqlite3-esm) -Dtarget=es6-bundler-friendly",
-    .zEmcc="-sMEMORY64=1",
-    .zEnv = 0,
-    .flags= LIBMODE_BUNDLER_FRIENDLY | LIBMODE_ESM
+    .zBaseName   = "sqlite3",
+    .zDotWasm    = 0,
+    .zCmppD      = "$(c-pp.D.bundler)",
+    .zEmcc       = "-sMEMORY64=1",
+    .zEnv        = 0,
+    .flags       = CP_JS | F_ESM | F_BUNDLER_FRIENDLY
   },
 
+#if 0
+
   /* Entirely unsupported. */
   .node = {
-    .zBaseName="sqlite3-node",
-    .zReuseThis=0,
-    .zCmppD="$(c-pp.D.sqlite3-bundler-friendly) -Dtarget=node",
-    .zEmcc=0,
-    .zEnv = "node"
-    /* Adding ",node" to the list for the other -sENVIRONMENT values
-       causes Emscripten to generate code which confuses node: it
-       cannot reliably determine whether the build is for a browser or
-       for node. We neither build nor test node builds on a regular
-       basis. They are fully unsupported. */,
-    .flags= LIBMODE_UNSUPPORTED | LIBMODE_NODEJS
+    .zBaseName   = "sqlite3-node",
+    .zDotWasm    = 0,
+    .zCmppD      = "$(c-pp.D.bundler)",
+    .zEmcc       = 0,
+    .zEnv        = "node",
+    .flags       = CP_BOTH | F_UNSUPPORTED | F_NODEJS
   },
 
   /* Entirely unsupported. */
   .wasmfs = {
-    .zBaseName="sqlite3-wasmfs",
-    .zReuseThis=0,
-    .zCmppD="$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs",
-    .zEmcc="-sEXPORT_ES6 -sUSE_ES6_IMPORT_META",
-    .zEnv = 0,
-    .flags= LIBMODE_UNSUPPORTED | LIBMODE_WASMFS | LIBMODE_ESM
+    .zBaseName   = "sqlite3-wasmfs",
+    .zDotWasm    = 0,
+    .zCmppD      = "$(c-pp.D.bundler)",
+    .zEmcc       = 0,
+    .zEnv        = "-sEXPORT_ES6 -sUSE_ES6_IMPORT_META",
+    .flags       = CP_BOTH | F_UNSUPPORTED | F_WASMFS
   }
 #endif
 };
@@ -392,20 +386,25 @@ static void mk_prologue(void){
     }
     ps("else");
     {
-      ps("define SQLITE.CALL.WASM-OPT");
-      pf("echo -n 'Before wasm-opt:'; ls -l $(1);\\\n"
-         "\trm -f wasm-opt-tmp.wasm;\\\n"
-         /* It's very likely that the set of wasm-opt flags varies from
-         ** version to version, so we'll ignore any errors here. */
-         "\tif $(bin.wasm-opt) $(1) -o wasm-opt-tmp.wasm \\\n"
-         "\t\t%s; then \\\n"
-         "\t\tmv wasm-opt-tmp.wasm $(1); \\\n"
-         "\t\techo -n 'After wasm-opt: '; \\\n"
-         "\t\tls -l $(1); \\\n"
-         "\telse \\\n"
-         "\t\techo 'WARNING: ignoring wasm-opt failure for $(1)'; \\\n"
-         "\tfi\n",
-         zOptFlags
+      ps("define SQLITE.CALL.WASM-OPT"
+         /* $1 = $@, $2 = build name*/
+      );
+      pf(
+        "echo '[$@]: Applying $(bin.wasm-opt)';\\\n"
+        "\trm -f wasm-opt-tmp.$(2).wasm;\\\n"
+        /* It's very likely that the set of wasm-opt flags varies from
+        ** version to version, so we'll ignore any errors here. */
+        "\tif $(bin.wasm-opt) $(1) -o wasm-opt-tmp.$(2).wasm \\\n"
+        "\t\t%s; then \\\n"
+        "\t\tmv wasm-opt-tmp.$(2).wasm $(1); \\\n"
+#if 0
+        "\t\techo -n 'After wasm-opt: '; \\\n"
+        "\t\tls -l $(1); \\\n"
+#endif
+        "\telse \\\n"
+        "\t\techo 'WARNING: ignoring wasm-opt failure for $(1)'; \\\n"
+        "\tfi\n",
+        zOptFlags
       );
       ps("endef");
     }
@@ -433,13 +432,13 @@ static void mk_pre_post(char const *zBuildName,
   if( 0==WASM_CUSTOM_INSTANTIATE ){
     pf("$(eval $(call SQLITE.CALL.C-PP.FILTER,$(pre-js.js.in),"
        "$(pre-js.%s.js),"
-       C_PP_D_CUSTOM_INSTANTIATE "$(c-pp.D.%s)))\n",
+       "$(c-pp.D.%s)))\n",
        zBuildName, zBuildName);
   }else{
 #if 0
     fixme;
     /* This part is needed for builds which have to rename the wasm file
-       in zReuseThis so that the loader can find it. */
+       in zDotWasm so that the loader can find it. */
     pf("pre-js.%s.js.intermediary = "
        "$(dir.tmp)/pre-js.%s.intermediary.js\n",
        zBuildName, zBuildName);
@@ -522,7 +521,7 @@ static void mk_fiddle(void){
        zTail);
     ps("\t@chmod -x $(basename $@).wasm");
     ps("\t@$(maybe-wasm-strip) $(basename $@).wasm");
-    ps("\t@$(SQLITE.strip-createExportWrapper)");
+    ps("\t@$(SQLITE.strip-emcc-js-cruft)");
     pf("\t@cp -p $(SOAP.js) $(dir $@)\n");
     if( 1==i ){/*fiddle.debug*/
       pf("\tcp -p $(dir.fiddle)/index.html "
@@ -559,7 +558,7 @@ void mk_lib_mode(const char *zBuildName, const BuildDef * pB){
     /* The various targets named X.js or X.mjs also generate X.wasm,
     ** and we need that part of the name to perform some
     ** post-processing after Emscripten generates X.wasm. */;
-  const char * zJsExt = (LIBMODE_ESM & pB->flags)
+  const char * zJsExt = (F_ESM & pB->flags)
     ? ".mjs" : ".js";
   char const * const zBaseName = pB->zBaseName
     ? pB->zBaseName : oBuildDefs.vanilla.zBaseName;
@@ -569,8 +568,7 @@ void mk_lib_mode(const char *zBuildName, const BuildDef * pB){
 
   pf("%s# Begin build [%s]. flags=0x%02x\n", zBanner, zBuildName, pB->flags);
   pf("# zCmppD=%s\n# zBaseName=%s\n",
-     pB->zCmppD ? pB->zCmppD : "<none>",
-     zBaseName);
+     pB->zCmppD ? pB->zCmppD : "", zBaseName);
 
   pf("dir.dout.%s ?= $(dir.dout)/%s\n", zBuildName, zBuildName);
   pf("out.%s.base = $(dir.dout.%s)/%s\n",
@@ -584,98 +582,108 @@ void mk_lib_mode(const char *zBuildName, const BuildDef * pB){
      pB->zEnv ? pB->zEnv : oBuildDefs.vanilla.zEnv);
   pf("emcc.flags.%s = %s\n", zBuildName, pB->zEmcc ? pB->zEmcc : "");
 
-  pf("sqlite3-api.%s.c-pp.js = $(dir.tmp)/sqlite3-api.%s.c-pp%s\n",
-     zBuildName, zBuildName, zJsExt);
+  { /* Create sqlite3-api.*.js */
+    pf("sqlite3-api.%s.c-pp.js = $(dir.tmp)/sqlite3-api.%s.c-pp%s\n",
+       zBuildName, zBuildName, zJsExt);
+
+    pf("sqlite3-api.%s.js = $(dir.tmp)/sqlite3-api.%s%s\n",
+       zBuildName, zBuildName, zJsExt);
+    pf("c-pp.D.%s = %s\n", zBuildName, pB->zCmppD ? pB->zCmppD: "" );
+
+    pf("$(sqlite3-api.%s.c-pp.js): $(sqlite3-api.jses)\n"
+       "\t@echo 'Making $@ ...'; \\\n"
+       "\tmkdir -p $(dir.dout.%s); \\\n"
+       "\tfor i in $(sqlite3-api.jses); do \\\n"
+       "\t\techo \"/* BEGIN FILE: $$i */\"; \\\n"
+       "\t\tcat $$i; \\\n"
+       "\t\techo \"/* END FILE: $$i */\"; \\\n"
+       "\tdone > $@\n",
+       zBuildName, zBuildName);
 
-  pf("sqlite3-api.%s.js = $(dir.tmp)/sqlite3-api.%s%s\n",
-     zBuildName, zBuildName, zJsExt);
-  if( pB->zCmppD ){
-    pf("c-pp.D.%s = %s\n", zBuildName, pB->zCmppD );
+    pf("$(sqlite3-api.%s.js): $(sqlite3-api.%s.c-pp.js)\n",
+       zBuildName, zBuildName);
+    pf("$(eval $(call SQLITE.CALL.C-PP.FILTER,"
+       "$(sqlite3-api.%s.c-pp.js), " /* $1 = src(es) */
+       "$(sqlite3-api.%s.js), "      /* $2 = tgt */
+       "$(c-pp.D.%s)"                /* $3 = c-pp -Dx=Y flags */
+       "))\n",
+       zBuildName, zBuildName, zBuildName);
   }
-  pf("$(sqlite3-api.%s.c-pp.js): $(sqlite3-api.jses)\n"
-     "\t@echo 'Making $@ ...'; \\\n"
-     "\tmkdir -p $(dir.dout.%s); \\\n"
-     "\tfor i in $(sqlite3-api.jses); do \\\n"
-     "\t\techo \"/* BEGIN FILE: $$i */\"; \\\n"
-     "\t\tcat $$i; \\\n"
-     "\t\techo \"/* END FILE: $$i */\"; \\\n"
-     "\tdone > $@\n",
-     zBuildName, zBuildName);
-
-  pf("$(sqlite3-api.%s.js): $(sqlite3-api.%s.c-pp.js)\n",
-     zBuildName, zBuildName);
-  pf("$(eval $(call SQLITE.CALL.C-PP.FILTER,"
-     "$(sqlite3-api.%s.c-pp.js), " /* $1 = src */
-     "$(sqlite3-api.%s.js), "     /* $2 = tgt */
-     "$(c-pp.D.%s)"           /* $3 = c-pp -Dx=Y flags */
-     "))\n",
-     zBuildName, zBuildName, zBuildName);
 
   mk_pre_post(zBuildName, pB);
 
-  /* target pB->zReuseThis */
-  pf(zBanner
-     "# Build $(out.%s.js)\n"
-     "$(out.%s.js): $(MAKEFILE_LIST) $(sqlite3-wasm.cfiles) $(EXPORTED_FUNCTIONS.api) "
-     "$(bin.mkwb) "
-     "$(pre-post.%s.deps) "
-     "$(sqlite3-api.ext.jses)"
-     /* ^^^ maintenance reminder: we set these as deps so that they
-     ** get copied into place early. That allows the developer to
-     ** reload the base-most test pages while the later-stage builds
-     ** are still compiling, which is especially helpful when running
-     ** builds with long build times (like -Oz). */
-     "\n",
-     zBuildName, zBuildName, zBuildName);
-  pf("\t@echo \"Building $@ ...\"\n");
-  if( LIBMODE_UNSUPPORTED & pB->flags ){
-    ps("\t@echo 'ACHTUNG: $@ is an unsupported build. "
-       "Use at your own risk.'");
-  }
-  pf("\t$(bin.emcc) -o $@ $(emcc_opt_full) $(emcc.flags) \\\n");
-  pf("\t\t$(emcc.jsflags) -sENVIRONMENT=$(emcc.environment.%s) \\\n",
-     zBuildName);
-  pf("\t\t$(pre-post.%s.flags) \\\n", zBuildName);
-  if( pB->zEmcc ){
-    pf("\t\t$(emcc.%s.flags) \\\n", zBuildName);
-  }
-  pf("\t\t$(cflags.common) $(cflags.%s) \\\n"
-     "\t\t$(SQLITE_OPT) \\\n"
-     "\t\t$(cflags.wasm_extra_init) $(sqlite3-wasm.cfiles)\n",
-     zBuildName);
-  if( (LIBMODE_ESM & pB->flags) || (LIBMODE_NODEJS & pB->flags) ){
-    /* TODO? Replace this $(call) with the corresponding makefile
-    ** code.  OTOH, we also use this $(call) in the speedtest1-wasmfs
-    ** build, which is not part of the rules emitted by this
-    ** program. */
-    pf("\t@$(call SQLITE.CALL.xJS.ESM-EXPORT-DEFAULT,1,%d)\n",
-       (LIBMODE_WASMFS & pB->flags) ? 1 : 0);
-  }
-  pf("\t@chmod -x %s\n", zWasmOut);
-  pf("\t@$(maybe-wasm-strip) %s\n", zWasmOut);
-  pf("\t@$(call SQLITE.CALL.WASM-OPT,%s)\n", zWasmOut);
-  ps("\t@$(SQLITE.strip-createExportWrapper)");
-  /*
-  ** The above $(bin.emcc) call will write out $@, and will create a
-  ** like-named .wasm file. That .wasm file name gets hard-coded into
-  ** $@ so we need to, for some cases, patch zReuseThis to use the name
-  ** sqlite3.wasm instead.  The resulting .wasm file is identical for
-  ** all builds for which pB->zEmcc is empty.
-  */
-  if( (LIBMODE_BUNDLER_FRIENDLY & pB->flags) ){
-#if 1
-    pf("\t@echo 'FIXME: missing build pieces for build %s'; exit 1\n",
+  { /* build it... */
+    pf(zBanner
+       "# Build $(out.%s.js)\n"
+       "$(out.%s.js): $(MAKEFILE_LIST) $(sqlite3-wasm.cfiles) $(EXPORTED_FUNCTIONS.api)"
+       " $(bin.mkwb) $(pre-post.%s.deps) $(sqlite3-api.ext.jses)"
+       /* maintenance reminder: we set these ^^^^ as deps so that they
+       ** get copied into place early. That allows the developer to
+       ** reload the base-most test pages while the later-stage builds
+       ** are still compiling, which is especially helpful when
+       ** running builds with long build times (like -Oz). */
+       "\n",
+       zBuildName, zBuildName, zBuildName);
+    pf("\t@echo '[$@]: building ...'\n");
+    if( F_UNSUPPORTED & pB->flags ){
+      ps("\t@echo '[$@]: ACHTUNG: unsupported build type. "
+         "Use at your own risk.'");
+    }
+    pf("\t$(bin.emcc) -o $@ $(emcc_opt_full) $(emcc.flags) \\\n");
+    pf("\t\t$(emcc.jsflags) -sENVIRONMENT=$(emcc.environment.%s) \\\n",
        zBuildName);
-#else
-    fixme;
-    pf("\t@echo 'Patching $@ for %s.wasm...'; \\\n", zBaseName);
-    pf("\t\trm -f %s; \\\n", zWasmOut);
-    pf("\t\tsed -i -e 's/\"%s.wasm\"/\"%s.wasm\"/g' $@ || exit;\n",
-       /* ^^^^^^ reminder: Mac/BSD sed has no -i flag but this
-       ** build process explicitly requires a Linux system. */
-       zNM, zBaseName);
-    pf("\t@ls -la $@\n");
-    if( LIBMODE_BUNDLER_FRIENDLY & pB->flags ){
+    pf("\t\t$(pre-post.%s.flags) \\\n", zBuildName);
+    if( pB->zEmcc ){
+      pf("\t\t$(emcc.flags.%s) \\\n", zBuildName);
+    }
+    pf("\t\t$(cflags.common) $(cflags.%s) \\\n"
+       "\t\t$(SQLITE_OPT) \\\n"
+       "\t\t$(cflags.wasm_extra_init) $(sqlite3-wasm.cfiles)\n",
+       zBuildName);
+    if( (F_ESM & pB->flags) || (F_NODEJS & pB->flags) ){
+      /* TODO? Replace this $(call) with the corresponding makefile
+      ** code.  OTOH, we also use this $(call) in the speedtest1-wasmfs
+      ** build, which is not part of the rules emitted by this
+      ** program. */
+      pf("\t@$(call SQLITE.CALL.xJS.ESM-EXPORT-DEFAULT,1,%d)\n",
+         (F_WASMFS & pB->flags) ? 1 : 0);
+    }
+    pf("\t@chmod -x %s\n", zWasmOut);
+    pf("\t@$(maybe-wasm-strip) %s\n", zWasmOut);
+    pf("\t@$(call SQLITE.CALL.WASM-OPT,%s,%s)\n", zWasmOut, zBuildName);
+    ps("\t@$(SQLITE.strip-emcc-js-cruft)");
+    if( CP_JS & pB->flags && !(pB->zDotWasm/*handled below*/) ){
+      ps("\t@cp -f $@ $(dir.dout)/. || exit; \\\n"
+         "echo '[$@]: ==> $(dir.dout)/$(notdir $@).'"
+      );
+    }
+    if( CP_WASM & pB->flags ){
+      pf("\t@cp -f %s $(dir.dout)/. || exit; \\\n"
+         "echo '[%s]: ==> $(dir.dout)/$(notdir %s)'\n",
+         zWasmOut, zWasmOut, zWasmOut);
+    }
+    /*
+    ** The above $(bin.emcc) call will write out $@, and will create a
+    ** like-named .wasm file. The resulting .wasm and .js/.mjs files
+    ** are identical across all builds which have the same pB->zEmcc.
+    **
+    ** We copy one or both of those files to $(dir.dout) (the top-most
+    ** build target dir), but: that .wasm file name gets hard-coded
+    ** into $@ so we need, for some cases, to patch the name to
+    ** pB->zDotWasm when copying to $(dir.dout).
+    */
+    if( pB->zDotWasm && (CP_JS & pB->flags) ){
+      pf("\t@echo '[$@]: Replacing \"%s.wasm\" in "
+         "$(dir.dout)/$(notdir $@) with \"%s.wasm\"'; \\\n"
+         "sed "
+         "-e 's/\"%s.wasm\"/\"%s.wasm\"/g' "
+         "-e \"s/'%s.wasm'/'%s.wasm'/g\" "
+         "$@ > $(dir.dout)/$(notdir $@)\n"
+         "\t@ls -la $(dir.dout)/$(notdir $@)\n",
+         zBaseName, pB->zDotWasm,
+         zBaseName, pB->zDotWasm,
+         zBaseName, pB->zDotWasm);
+
       /* Avoid a 3rd occurrence of the bug fixed by 65798c09a00662a3,
       ** which was (in two cases) caused by makefile refactoring and
       ** not recognized until after a release was made with the broken
@@ -684,19 +692,21 @@ void mk_lib_mode(const char *zBuildName, const BuildDef * pB){
       pf("\t@if grep -e '^ *importScripts(' $@; "
          "then echo 'ERROR: bug fixed in 65798c09a00662a3 has re-appeared'; "
          "exit 1; fi;\n");
+    }else{
+      pf("\t@ls -la %s $@\n", zWasmOut);
     }
-#endif
-  }else{
-    pf("\t@ls -la %s $@\n", zWasmOut);
   }
 
-  if( LIBMODE_64BIT & pB->flags ){
-    pf("64bit: $(out.%s.js)\n", zBuildName);
-  }
-  if( 0==(LIBMODE_NOT_IN_ALL & pB->flags)
-      && 0==(LIBMODE_UNSUPPORTED & pB->flags) ){
+  pf("\n%dbit: $(out.%s.js)\n"
+     "b-%s: $(out.%s.js)\n",
+     (F_64BIT & pB->flags) ? 64 : 32,
+     zBuildName, zBuildName, zBuildName);
+
+  if( 0==(F_NOT_IN_ALL & pB->flags)
+      && 0==(F_UNSUPPORTED & pB->flags) ){
     pf("all: $(out.%s.js)\n", zBuildName);
   }
+
   pf("# End build [%s]%s", zBuildName, zBanner);
 }
 
index c7b31394808294f2f3f716d870f951d3c775ad1b..51f60caf88360d52e60c580b8ddcc23d8a5faa8d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Create\seach\sdistinct\swasm\sbuild\sinto\sits\sown\sdir,\sinstead\sof\sall\sgoing\sto\sin\sjswasm/sqlite3.wasm,\sso\sthat\sthe\sbuild\scan\snow\srun\sin\sparallel.
-D 2025-09-23T06:31:24.072
+C More\sbuild\srestructuring.
+D 2025-09-23T08:23:23.789
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -578,7 +578,7 @@ F ext/session/sqlite3session.c 9cd47bfefb23c114b7a5d9ee5822d941398902f30516bf0dd
 F ext/session/sqlite3session.h 7404723606074fcb2afdc6b72c206072cdb2b7d8ba097ca1559174a80bc26f7a
 F ext/session/test_session.c 8766b5973a6323934cb51248f621c3dc87ad2a98f023c3cc280d79e7d78d36fb
 F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c
-F ext/wasm/GNUmakefile c3ed2f1449f6c9eb8a291c96b4e0b454d1c27bfa17ea416eacd09d48a01a840f
+F ext/wasm/GNUmakefile 0ecf7ff692887d55d1fa37f1f6615c782f87c93c3cb0de264aefa2786ebd93f3
 F ext/wasm/README-dist.txt f01081a850ce38a56706af6b481e3a7878e24e42b314cfcd4b129f0f8427066a
 F ext/wasm/README.md 66ace67ae98a45e4116f2ca5425b716887bcee4d64febee804ff6398e1ae9ec7
 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff
@@ -639,7 +639,7 @@ F ext/wasm/index-dist.html 56132399702b15d70c474c3f1952541e25cb0922942868f70daf1
 F ext/wasm/index.html bcaa00eca521b372a6a62c7e7b17a870b0fcdf3e418a5921df1fd61e5344080d
 F ext/wasm/jaccwabyt/jaccwabyt.js bbac67bc7a79dca34afe6215fd16b27768d84e22273507206f888c117e2ede7d
 F ext/wasm/jaccwabyt/jaccwabyt.md 167fc0b624c9bc2c477846e336de9403842d81b1a24fc4d3b24317cb9eba734f
-F ext/wasm/mkwasmbuilds.c 21535d1742777a76dd00b53ec0e9566782318d0a9aec08f54eed0aa49b6423bc
+F ext/wasm/mkwasmbuilds.c 6bf9f22a62874a053ff8383b89497864a1a385f3dae43deea525953b2f65e50c
 F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337
 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96
 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63
@@ -2175,8 +2175,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 102c4a35b86405273d1f7e9e34466c9deed7831099a8207b6f48746b998193f9
-R 507652776b7fcff767cc0772a4c41fe1
+P 47526a75f2ad85100b1eae7ab1cf9a9dddd4430a99f7a30aa0c16548d1db9d33
+R 022960e7710c43f7a03c044d401495dc
 U stephan
-Z aefc81491b4816a018bbebce8587a431
+Z cdedef3da028fd2a488e8188a24209ae
 # Remove this line to create a well-formed Fossil manifest.
index 36951945a9e4011d7bccf4cc04caf61a027f0590..88dd0cc38b70df97236c0b17e604dc66de168d9f 100644 (file)
@@ -1 +1 @@
-47526a75f2ad85100b1eae7ab1cf9a9dddd4430a99f7a30aa0c16548d1db9d33
+7bee8ee76380b2c1beb320b55042f149c22f872c70b58461652fa5bcbf6ad3c7