From: stephan Date: Wed, 24 Sep 2025 04:58:14 +0000 (+0000) Subject: Move some of the generated wasm makefile utility code out of C and into util.make. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e779baa099dceff743d825a1073060f9f5840eee;p=thirdparty%2Fsqlite.git Move some of the generated wasm makefile utility code out of C and into util.make. FossilOrigin-Name: a2935758f534b51cac3d2e5ece74b369c806e3a994781744708e1590b9c32542 --- diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index fbf0e5dd6e..4041283a63 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -51,6 +51,8 @@ clean: distclean: clean -rm -f $(DISTCLEAN_FILES) +more: all +include util.make ######################################################################## # Special-case builds for which we require certain pre-conditions @@ -169,10 +171,6 @@ dir.dout = $(dir.wasm)/jswasm dir.tmp = $(dir.wasm)/bld dir.wasmfs = $(dir.dout) -MKDIR.bld = $(dir.tmp) -$(MKDIR.bld): - @mkdir -p $@ $(dir.dout) - CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ $(dir.fiddle)/*~ \ ######################################################################## @@ -415,7 +413,7 @@ WASM_CUSTOM_INSTANTIATE = 0 # JS/WASM build. They are solely for use with $(bin.c-pp) itself. # # -D... flags which should be included in all invocations should be -# appended to $(SQLITE.CALL.C-PP.FILTER.global). +# appended to $(b.eval.c-pp.flags). bin.c-pp = ./c-pp $(bin.c-pp): c-pp.c $(sqlite3.c) # $(MAKEFILE) $(CC) -O0 -o $@ c-pp.c $(sqlite3.c) '-DCMPP_DEFAULT_DELIM="//#"' -I$(dir.top) \ @@ -423,9 +421,9 @@ $(bin.c-pp): c-pp.c $(sqlite3.c) # $(MAKEFILE) -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_WAL -DSQLITE_THREADSAFE=0 \ -DSQLITE_TEMP_STORE=3 DISTCLEAN_FILES += $(bin.c-pp) -SQLITE.CALL.C-PP.FILTER.global ?= +b.eval.c-pp.flags ?= ifeq (1,$(SQLITE_C_IS_SEE)) - SQLITE.CALL.C-PP.FILTER.global += -Denable-see + b.eval.c-pp.flags += -Denable-see endif define SQLITE.CALL.C-PP.FILTER # Create $2 from $1 using $(bin.c-pp) @@ -433,8 +431,8 @@ define SQLITE.CALL.C-PP.FILTER # $2 = Output file: c-pp -o $(2).js # $3 = optional c-pp -D... flags $(2): $(1) $$(MAKEFILE_LIST) $$(bin.c-pp) - @mkdir -p $$(dir $$@) - cat $(1) | $$(bin.c-pp) -o $$@ $(3) $(SQLITE.CALL.C-PP.FILTER.global) + @$$(call b.call.mkdir@) + cat $(1) | $$(bin.c-pp) -o $$@ $(3) $(b.eval.c-pp.flags) CLEAN_FILES += $(2) endef # /end SQLITE.CALL.C-PP.FILTER @@ -458,7 +456,7 @@ ifneq (0,$(emcc.MEMORY64)) emcc.WASM_BIGINT = 1 # -sMEMORY64=1+ assumes -sWASM_BIGINT=1, so we'll make it explicit - # SQLITE.CALL.C-PP.FILTER.global += -D64bit + # b.eval.c-pp.flags += -D64bit # ^^ We no longer need build-time code filtering for 64-bit but if # we ever do again, just uncomment that line or, if it's just needed # in specific builds, update that build's -D flags in @@ -482,23 +480,8 @@ else emcc_opt ?= -Oz endif -# Our JS code installs bindings of each sqlite3_...() WASM export. The -# generated Emscripten JS file does the same using its own framework, -# but we don't use those results and can speed up lib init, and reduce -# memory cost a bit, by stripping them out. Emscripten-side changes -# can "break" this, causing this to be a no-op, but the worst that can -# happen in that case is that it doesn't actually strip anything, -# leading to slightly larger JS files. -# -# This snippet is intended to be used in makefile targets which -# generate an Emscripten module and where $@ is the module's .js/.mjs -# file. -# -# $1 = an optional log message prefix -SQLITE.strip-emcc-js-cruft = \ - sed -i -e '/^.*= \(_sqlite3\|_fiddle\)[^=]*=.*createExportWrapper/d' \ - -e '/^var \(_sqlite3\|_fiddle\)[^=]*=.*makeInvalidEarlyAccess/d' $@ || exit; \ - echo '$(1) $(emo.garbage) (Probably) /createExportWrapper()/d and /makeInvalidEarlyAccess()/d' +# old name - to remove +SQLITE.strip-emcc-js-cruft = $(b.call.strip-emcc-js-cruft) # When passing emcc_opt from the CLI, += and re-assignment have no # effect, so emcc_opt+=-g3 doesn't work. So... @@ -542,22 +525,23 @@ ifeq (0,$(wasm-bare-bones)) EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras endif EXPORTED_FUNCTIONS.api = $(dir.tmp)/EXPORTED_FUNCTIONS.api -$(EXPORTED_FUNCTIONS.api): $(MKDIR.bld) $(EXPORTED_FUNCTIONS.api.in) $(sqlite3.c) $(MAKEFILE) +$(EXPORTED_FUNCTIONS.api): $(EXPORTED_FUNCTIONS.api.in) $(sqlite3.c) $(MAKEFILE) + @$(call b.call.mkdir@) cat $(EXPORTED_FUNCTIONS.api.in) > $@ ######################################################################## # SOAP.js is an external API file which is part of our distribution # but not part of the sqlite3-api.js amalgamation. It's a component of # the first OPFS VFS and necessarily an external file. -SOAP.js = $(dir.api)/sqlite3-opfs-async-proxy.js -SOAP.js.out = $(dir.dout)/sqlite3-opfs-async-proxy.js +SOAP.js.in = $(dir.api)/sqlite3-opfs-async-proxy.js +SOAP.js = $(dir.dout)/sqlite3-opfs-async-proxy.js +$(SOAP.js): $(SOAP.js.in) + @$(call b.call.cp,@,$<,$@) # -# $(sqlite3-api.ext.jses) = API-related files which are standalone files, -# not part of the amalgamation. +# $(sqlite3-api.ext.jses) = API-related files which are standalone +# files, not part of the amalgamation. # -sqlite3-api.ext.jses = $(SOAP.js.out) -$(SOAP.js.out): $(SOAP.js) - cp $< $@ +sqlite3-api.ext.jses = $(SOAP.js) ######################################################################## # emcc flags for .c/.o/.wasm/.js. @@ -856,34 +840,6 @@ endif # /wasmfs ######################################################################## - -# This block MUST come between the above definitions of -# sqlite3-...js/mjs and the $(eval) calls below this block which use -# SQLITE.CALL.C-PP.FILTER. -######################################################################## -# bin.mkwb is used for generating much of the makefile code for the -# various wasm builds. It used to be generated in this makefile via a -# difficult-to-read/maintain block of $(eval)'d code. Attempts were -# made to generate it from tcl and bash (shell) but having to escape -# the $ references in those languages made it just as illegible as the -# native makefile code. Somewhat surprisingly, moving that code generation -# to C makes it slightly less illegible than the previous 3 options. -# -# Maintenance note: the various $(c-pp.D.XYZ) vars are defined via -# $(bin.mkwb). -bin.mkwb = ./mkwasmbuilds -ifneq (1,$(MAKING_CLEAN)) -$(bin.mkwb): $(bin.mkwb).c $(MAKEFILE) - $(CC) -g -std=c99 -o $@ $< -DWASM_CUSTOM_INSTANTIATE=$(WASM_CUSTOM_INSTANTIATE) - -.wasmbuilds.make: $(bin.mkwb) - @rm -f $@ - $(bin.mkwb) > $@ - @chmod -w $@ --include .wasmbuilds.make -endif -CLEAN_FILES += .wasmbuilds.make $(bin.mkwb) - ######################################################################## # We need separate copies of certain supplementary JS files for the # bundler-friendly build. Concretely, any supplemental JS files which @@ -894,37 +850,36 @@ CLEAN_FILES += .wasmbuilds.make $(bin.mkwb) # code analyzers and cannot cope with the former. # # Most of what follows is the generation of those copies. - -$(eval $(call SQLITE.CALL.C-PP.FILTER,$(dir.api)/sqlite3-worker1.c-pp.js,\ +$(eval $(call b.eval.c-pp,@,$(dir.api)/sqlite3-worker1.c-pp.js,\ $(dir.dout)/sqlite3-worker1.js)) sqlite3-api.ext.jses += $(dir.dout)/sqlite3-worker1.js -$(eval $(call SQLITE.CALL.C-PP.FILTER,$(dir.api)/sqlite3-worker1-promiser.c-pp.js,\ +$(eval $(call b.eval.c-pp,@,$(dir.api)/sqlite3-worker1-promiser.c-pp.js,\ $(dir.dout)/sqlite3-worker1-promiser.mjs,\ -Dtarget=es6-module -Dtarget=es6-bundler-friendly)) sqlite3-api.ext.jses += $(dir.dout)/sqlite3-worker1-promiser.mjs -$(eval $(call SQLITE.CALL.C-PP.FILTER,$(dir.api)/sqlite3-worker1-promiser.c-pp.js,\ +$(eval $(call b.eval.c-pp,@,$(dir.api)/sqlite3-worker1-promiser.c-pp.js,\ $(dir.dout)/sqlite3-worker1-promiser.js)) sqlite3-api.ext.jses += $(dir.dout)/sqlite3-worker1-promiser.js -$(eval $(call SQLITE.CALL.C-PP.FILTER,demo-worker1-promiser.c-pp.js,demo-worker1-promiser.js)) -$(eval $(call SQLITE.CALL.C-PP.FILTER,demo-worker1-promiser.c-pp.js,demo-worker1-promiser.mjs,\ +$(eval $(call b.eval.c-pp,@,demo-worker1-promiser.c-pp.js,demo-worker1-promiser.js)) +$(eval $(call b.eval.c-pp,@,demo-worker1-promiser.c-pp.js,demo-worker1-promiser.mjs,\ -Dtarget=es6-module)) -$(eval $(call SQLITE.CALL.C-PP.FILTER,demo-worker1-promiser.c-pp.html,demo-worker1-promiser.html)) -$(eval $(call SQLITE.CALL.C-PP.FILTER,demo-worker1-promiser.c-pp.html,demo-worker1-promiser-esm.html,\ +$(eval $(call b.eval.c-pp,@,demo-worker1-promiser.c-pp.html,demo-worker1-promiser.html)) +$(eval $(call b.eval.c-pp,@,demo-worker1-promiser.c-pp.html,demo-worker1-promiser-esm.html,\ -Dtarget=es6-module)) demo-worker1-promiser.html: $(dir.dout)/sqlite3-worker1-promiser.js demo-worker1-promiser.js demo-worker1-promiser-esm.html: $(sqlite3-worker1-promiser.mjs) demo-worker1-promiser.mjs all: demo-worker1-promiser.html demo-worker1-promiser-esm.html ifeq (0,1) -$(eval $(call SQLITE.CALL.C-PP.FILTER,$(dir.api)/sqlite3-worker1.c-pp.js,\ +$(eval $(call b.eval.c-pp,@,$(dir.api)/sqlite3-worker1.c-pp.js,\ $(dir.dout)/sqlite3-worker1-bundler-friendly.mjs,\ $(c-pp.D.sqlite3-bundler-friendly))) sqlite3-api.ext.jses += $(dir.dout)/sqlite3-worker1-bundler-friendly.mjs -$(eval $(call SQLITE.CALL.C-PP.FILTER,$(dir.api)/sqlite3-worker1-promiser.c-pp.js,\ +$(eval $(call b.eval.c-pp,@,$(dir.api)/sqlite3-worker1-promiser.c-pp.js,\ $(dir.dout)/sqlite3-worker1-promiser-bundler-friendly.js,\ $(c-pp.D.sqlite3-bundler-friendly))) sqlite3-api.ext.jses += $(dir.dout)/sqlite3-promiser-bundler-friendly.js @@ -935,6 +890,31 @@ $(dir.dout)/sqlite3-bundler-friendly.mjs: \ endif +######################################################################## +# bin.mkwb is used for generating much of the makefile code for the +# various wasm builds. It used to be generated in this makefile via a +# difficult-to-read/maintain block of $(eval)'d code. Attempts were +# made to generate it from tcl and bash (shell) but having to escape +# the $ references in those languages made it just as illegible as the +# native makefile code. Somewhat surprisingly, moving that code generation +# to C makes it slightly less illegible than the previous 3 options. +# +# Maintenance note: the various $(c-pp.D.XYZ) vars are defined via +# $(bin.mkwb). +bin.mkwb = ./mkwasmbuilds +ifneq (1,$(MAKING_CLEAN)) +$(bin.mkwb): $(bin.mkwb).c $(MAKEFILE) + $(CC) -g -std=c99 -o $@ $< -DWASM_CUSTOM_INSTANTIATE=$(WASM_CUSTOM_INSTANTIATE) + +.wasmbuilds.make: $(bin.mkwb) + @rm -f $@ + $(bin.mkwb) > $@ + @chmod -w $@ +-include .wasmbuilds.make +endif +CLEAN_FILES += .wasmbuilds.make $(bin.mkwb) + +#$(error sqlite3-api.ext.jses=$(sqlite3-api.ext.jses)) all quick: $(sqlite3-api.ext.jses) q: quick 64bit: # populated by $(bin.mkwb) @@ -1011,8 +991,9 @@ speedtest1.exit-runtime1 = -sEXIT_RUNTIME=1 # -sEXIT_RUNTIME=1 but we need EXIT_RUNTIME=0 for the worker-based app # which runs speedtest1 multiple times. -$(EXPORTED_FUNCTIONS.speedtest1): $(MKDIR.bld) $(EXPORTED_FUNCTIONS.api.core) +$(EXPORTED_FUNCTIONS.speedtest1): $(EXPORTED_FUNCTIONS.api.core) @echo "$(emo.compile) Making $@ ..." + @$(call b.call.mkdir@) @{ echo _wasm_main; cat $(EXPORTED_FUNCTIONS.api.core); } > $@ speedtest1.js = $(dir.dout)/speedtest1.js emcc.flags.speedtest1-vanilla = $(cflags.common) -DSQLITE_SPEEDTEST1_WASM @@ -1056,10 +1037,10 @@ speedtest1: $(speedtest1.js) # tester1.mjs: cases 3 and 4 # # To create those, we filter tester1.c-pp.js with $(bin.c-pp)... -$(eval $(call SQLITE.CALL.C-PP.FILTER,tester1.c-pp.js,tester1.js,$(c-pp.D.vanilla))) -$(eval $(call SQLITE.CALL.C-PP.FILTER,tester1.c-pp.js,tester1.mjs,$(c-pp.D.esm))) -$(eval $(call SQLITE.CALL.C-PP.FILTER,tester1.c-pp.html,tester1.html,$(c-pp.D.vanilla))) -$(eval $(call SQLITE.CALL.C-PP.FILTER,tester1.c-pp.html,tester1-esm.html,$(c-pp.D.esm))) +$(eval $(call b.eval.c-pp,@,tester1.c-pp.js,tester1.js,$(c-pp.D.vanilla))) +$(eval $(call b.eval.c-pp,@,tester1.c-pp.js,tester1.mjs,$(c-pp.D.esm))) +$(eval $(call b.eval.c-pp,@,tester1.c-pp.html,tester1.html,$(c-pp.D.vanilla))) +$(eval $(call b.eval.c-pp,@,tester1.c-pp.html,tester1-esm.html,$(c-pp.D.esm))) tester1: tester1.js tester1.mjs tester1.html tester1-esm.html # We do not include $(dir.dout)/sqlite3-bundler-friendly.mjs in this # because bundlers are client-specific. We don't use any of them. diff --git a/ext/wasm/fiddle.make b/ext/wasm/fiddle.make index 35718e8348..0ee196bb45 100644 --- a/ext/wasm/fiddle.make +++ b/ext/wasm/fiddle.make @@ -63,9 +63,11 @@ fiddle.EXPORTED_FUNCTIONS.in = \ $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-core \ $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras -$(EXPORTED_FUNCTIONS.fiddle): $(MKDIR.bld) $(fiddle.EXPORTED_FUNCTIONS.in) \ +$(EXPORTED_FUNCTIONS.fiddle): $(fiddle.EXPORTED_FUNCTIONS.in) \ $(MAKEFILE.fiddle) - sort -u $(fiddle.EXPORTED_FUNCTIONS.in) > $@ + @$(b.call.mkdir@) + @sort -u $(fiddle.EXPORTED_FUNCTIONS.in) > $@ + @echo $(logtag.@) $(emo.disk) fiddle.cses = $(dir.top)/shell.c $(sqlite3-wasm.c) diff --git a/ext/wasm/mkwasmbuilds.c b/ext/wasm/mkwasmbuilds.c index 7ceb8ad91d..210275b3c0 100644 --- a/ext/wasm/mkwasmbuilds.c +++ b/ext/wasm/mkwasmbuilds.c @@ -288,74 +288,35 @@ static void mk_prologue(void){ } ps(zBanner - "more: all\n" - "emoji ?= 1\n" - "ifneq (0,$(emoji))\n" - "emo.disk = 💾\n" - "emo.fire = 🔥\n" - "emo.done = 🏆\n" /*🏁*/ - "emo.bug = 🐞\n" - "emo.megaphone = 📣\n" - "emo.mute = 🔇\n" - "emo.tool = 🔨\n" - "emo.compile = ⏳\n" - "emo.info =\n" - "emo.stop =🛑\n" - "emo.strip =🪚\n" /*🔪*/ - "emo.garbage =🗑\n" - "emo.folder = 📁\n" - "endif\n" ); - ps("logtag.@ = [$@]:"); - ps("b.do.strip-js-cruft = $(SQLITE.strip-emcc-js-cruft)"); ps("b.echo = echo '$(logtag.$(1))' '$(2)'"); +#if 0 ps(zBanner /** $1 = build name. */ - "b.do.mkdir@ = " + "b.call.mkdir@ = " "if [ ! -d $(dir $@) ]; then" " echo '[$(emo.folder)+] $(if $(1),$(logtag.$(1)),[$(dir $@)])';" " mkdir -p $(dir $@) || exit $$?;" "fi" ); - - ps(zBanner - /** $1 = build name - $2 = Input file(s): cat $(2) | c-pp ... - $3 = Output file: c-pp -o $(3) - $4 = optional c-pp -D... flags */ - "define b.do.c-pp\n" - "$(3): $$(MAKEFILE_LIST) $$(bin.c-pp) $(2)\n" - "\t@$$(call b.do.mkdir@); \\\n" - "\techo '$$(logtag.$(1)) $$(emo.disk) $(4)'; \\\n" - "\tcat $(2) | $$(bin.c-pp) -o $(3) $(4) $$(SQLITE.CALL.C-PP.FILTER.global) || exit $$$$?\n" - "\nCLEAN_FILES += $(2)\n" - "endef\n" - ); +#endif ps(zBanner /** $1 = build name */ - "b.do.wasm-strip = " + "b.call.wasm-strip = " "echo '$(logtag.$(1)) $(emo.strip) wasm-strip $(out.$(1).wasm)'; " "$(bin.wasm-strip) $(out.$(1).wasm)\n" ); - ps(zBanner - /** $1 = build name, $2 = src file(s). $3 = dest dir */ - "b.do.cp = " - "echo '$(logtag.$(1)) $(emo.disk) $(2) ==> $3'; " - "cp -p $(2) $(3) || exit $$$$?\n" - ); - ps(zBanner "# Inputs/outputs for the sqlite3-api.js family.\n" "#\n" "sqlite3-license-version.js = $(dir.tmp)/sqlite3-license-version.js\n" "sqlite3-api-build-version.js = $(dir.tmp)/sqlite3-api-build-version.js\n" "# sqlite3-api.jses = the list of JS files which make up\n" - "# $(sqlite3-api.js.in), in the order they need to be assembled.\n" - "sqlite3-api.js.in = $(dir.tmp)/sqlite3-api.c-pp.js\n" + "# sqlite3-api.js, in the order they need to be assembled.\n" "sqlite3-api.jses = $(sqlite3-license-version.js)\n" "sqlite3-api.jses += $(dir.api)/sqlite3-api-prologue.js\n" "sqlite3-api.jses += $(dir.common)/whwasmutil.js\n" @@ -379,7 +340,7 @@ static void mk_prologue(void){ "#\n" "# Maintenance reminder: there are awk binaries out there which do not\n" "# support -e SCRIPT.\n" - "$(sqlite3-license-version.js): $(MKDIR.bld) $(sqlite3.h) " + "$(sqlite3-license-version.js): $(sqlite3.h) " "$(dir.api)/sqlite3-license-version-header.js $(MAKEFILE)\n" "\t@echo '$(logtag.@) $(emo.disk)'; { \\\n" "\t\tcat $(dir.api)/sqlite3-license-version-header.js || exit $$?; \\\n" @@ -407,6 +368,7 @@ static void mk_prologue(void){ "\t} > $@" ); +#if 0 ps(zBanner "$(sqlite3-api.js.in): $(MKDIR.bld) $(sqlite3-api.jses) $(MAKEFILE)\n" "\t@echo 'Making $@ ...'\n" @@ -416,6 +378,7 @@ static void mk_prologue(void){ "echo \"/* END FILE: $$i */\"; \\\n" "\tdone > $@\n" ); +#endif ps(zBanner "# extern-post-js* and extern-pre-js* are files for use with\n" @@ -430,19 +393,6 @@ static void mk_prologue(void){ "$(extern-pre-js.js) $(sqlite3-license-version.js)" ); - ps(zBanner - "loud ?= 0\n" - "ifeq (1,$(loud))\n" - "$(info $(emo.megaphone) Emitting loud build info." - " Pass loud=0 to disable it.)\n" - "cmd.loud =\n" - "else\n" - "$(info $(emo.mute) Eliding loud build info." - " Pass emcc.loud=1 to enable it.)\n" - "cmd.loud = @\n" - "endif\n" - ); - ps(zBanner "# --post-js and --pre-js are emcc flags we use to append/prepend JS to\n" "# the generated emscripten module file. These rules set up the core\n" @@ -455,7 +405,7 @@ static void mk_prologue(void){ "post-js.in.js = $(dir.tmp)/post-js.c-pp.js\n" "post-jses.js =" " $(dir.api)/post-js-header.js" - " $(sqlite3-api.js.in)" + " $(sqlite3-api.jses)" " $(dir.api)/post-js-footer.js\n" "$(post-js.in.js): $(MKDIR.bld) $(post-jses.js) $(MAKEFILE)\n" " @echo '$(logtag.@) $(emo.disk)'\n" @@ -465,6 +415,7 @@ static void mk_prologue(void){ " echo \"/* END FILE: $$i */\"; \\n" " done > $@\n" ); + pf(zBanner "define b.do.emcc\n" /* $1 = build name */ @@ -611,7 +562,7 @@ static void mk_pre_post(char const *zBuildName){ " $(sqlite3-api.%s.js)" " $(dir.api)/post-js-footer.js\n", zBuildName, zBuildName); - pf("$(eval $(call b.do.c-pp," + pf("$(eval $(call b.eval.c-pp," "%s," "$(post-js.%s.in)," "$(post-js.%s.js)," @@ -622,7 +573,7 @@ static void mk_pre_post(char const *zBuildName){ ps("\n# --extern-post-js=..."); pf("extern-post-js.%s.js = $(dir.tmp)/extern-post-js.%s.js\n", zBuildName, zBuildName); - pf("$(eval $(call b.do.c-pp," + pf("$(eval $(call b.eval.c-pp," "%s," "$(extern-post-js.in.js)," "$(extern-post-js.%s.js)," @@ -656,8 +607,8 @@ static char const * BuildDef_basename(const BuildDef * pB){ return pB->zBaseName ? pB->zBaseName : oBuildDefs.vanilla.zBaseName; } -static void emit_target_start(char const *zBuildName){ - pf("\t@$(call b.do.mkdir@);" +static void emit_compile_start(char const *zBuildName){ + pf("\t@$(call b.call.mkdir@);" " $(call b.echo,%s,$(emo.compile) building ...)\n", zBuildName); } @@ -668,9 +619,9 @@ static void emit_api_js(char const *zBuildName, "sqlite3-api.%s.js = $(dir.tmp)/sqlite3-api.%s.js\n", zBuildName, zCmppD ? zCmppD: "", zBuildName, zBuildName); - pf("$(eval $(call b.do.c-pp," + pf("$(eval $(call b.eval.c-pp," "%s," - "$(sqlite3-api.js.in)," + "$(sqlite3-api.jses)," "$(sqlite3-api.%s.js)," "$(c-pp.D.%s) %s" "))\n", @@ -682,10 +633,7 @@ static void emit_api_js(char const *zBuildName, /* ** Emits makefile code for one build of the library. */ -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. */; +static void mk_lib_mode(const char *zBuildName, const BuildDef * pB){ const char * zJsExt = BuildDef_jsext(pB); char const * const zBaseName = BuildDef_basename(pB); @@ -733,24 +681,25 @@ void mk_lib_mode(const char *zBuildName, const BuildDef * pB){ { /* 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)" + "$(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); + zBuildName, zBuildName); - emit_target_start(zBuildName); + emit_compile_start(zBuildName); if( F_UNSUPPORTED & pB->flags ){ pf("\t@echo '$(logtag.%s) $(emo.fire)$(emo.fire)$(emo.fire): " "unsupported build. Use at your own risk.'\n", zBuildName); } - pf("\t$(cmd.loud)$(call b.do.emcc,%s)\n", zBuildName); + pf("\t$(b.cmd.loud)$(call b.do.emcc,%s)\n", zBuildName); { /* Post-compilation transformations and copying to $(dir.dout)... */ @@ -769,18 +718,18 @@ void mk_lib_mode(const char *zBuildName, const BuildDef * pB){ /* althttpd will automatically try to execute wasm files if they have the +x bit set. Why that bit is set at all is a mystery. */); - pf("\t@$(call b.do.wasm-strip,%s)\n", zBuildName); + pf("\t@$(call b.call.wasm-strip,%s)\n", zBuildName); pf("\t@$(call b.do.wasm-opt,%s)\n", zBuildName); - pf("\t@$(call b.do.strip-js-cruft,$(logtag.%s))\n", zBuildName); + pf("\t@$(call b.call.strip-js-cruft,$(logtag.%s))\n", zBuildName); if( CP_JS & pB->flags && !(pB->zDotWasm/*handled below*/) ){ - pf("\t@$(call b.do.cp,%s,$@,$(dir.dout)/.)\n", + pf("\t@$(call b.call.cp,%s,$@,$(dir.dout)/.)\n", zBuildName ); } if( CP_WASM & pB->flags ){ - pf("\t@$(call b.do.cp,%s,$(out.%s.wasm),$(dir.dout)/.)\n", + pf("\t@$(call b.call.cp,%s,$(out.%s.wasm),$(dir.dout)/.)\n", zBuildName, zBuildName //"\techo '[%s $(out.%s.wasm)] $(emo.disk) $(dir.dout)/$(notdir $(out.%s.wasm))' //pB->zEmo, zBuildName @@ -855,6 +804,16 @@ void mk_lib_mode(const char *zBuildName, const BuildDef * pB){ } +static void emit_gz(char const *zBuildName, + char const *zOutDotSExt){ + pf("\n$(out.%s.%s).gz: $(out.%s.%s)\n" + "\t@$(call b.echo,%s,$(emo.disk))\n" + "\t@gzip < $< > $@\n", + zBuildName, zOutDotSExt, + zBuildName, zOutDotSExt, + zBuildName); +} + /* ** Emits rules for the fiddle builds. */ @@ -894,19 +853,19 @@ static void mk_fiddle(void){ "$(pre-post.%s.deps) " "$(SOAP.js)\n", zBuildName, zBuildName); - emit_target_start(zBuildName); - pf("\t$(cmd.loud)$(bin.emcc) -o $@" + emit_compile_start(zBuildName); + pf("\t$(b.cmd.loud)$(bin.emcc) -o $@" " $(emcc.flags.%s)" /* set in fiddle.make */ " $(pre-post.%s.flags)" " $(fiddle.cses)" "\n", zBuildName, zBuildName); pf("\t@chmod -x $(out.%s.wasm)\n", zBuildName); - pf("\t@$(call b.do.wasm-strip,%s)\n", zBuildName); - pf("\t@$(call b.do.strip-js-cruft,$(logtag.%s))\n", zBuildName); - pf("\t@$(call b.do.cp,%s,$(SOAP.js),$(dir $@))\n", zBuildName); + pf("\t@$(call b.call.wasm-strip,%s)\n", zBuildName); + pf("\t@$(call b.call.strip-js-cruft,$(logtag.%s))\n", zBuildName); + pf("\t@$(call b.call.cp,%s,$(SOAP.js),$(dir $@))\n", zBuildName); if( isDebug ){ - pf("\t@$(call b.do.cp,%s," + pf("\t@$(call b.call.cp,%s," "$(dir.fiddle)/index.html " "$(dir.fiddle)/fiddle.js " "$(dir.fiddle)/fiddle-worker.js," @@ -923,10 +882,8 @@ static void mk_fiddle(void){ avoid that hand-edited files, like fiddle-worker.js, do not end up with stale .gz files (which althttpd will then serve instead of the up-to-date uncompressed one). */ - pf("\n$(out.%s.js).gz: $(out.%s.js)\n" - "\tgzip < $< > $@\n", zBuildName, zBuildName); - pf("\n$(out.%s.wasm).gz: $(out.%s.wasm)\n" - "\tgzip < $< > $@\n", zBuildName, zBuildName); + emit_gz(zBuildName, "js"); + emit_gz(zBuildName, "wasm"); pf("\n%s: $(out.%s.js).gz $(out.%s.wasm).gz\n" "b-%s: %s\n", @@ -934,6 +891,8 @@ static void mk_fiddle(void){ zBuildName, zBuildName); if( isDebug ){ ps("fiddle-debug: fiddle.debug"); + }else{ + ps("all: b-fiddle"); } pf("# End %s" zBanner, zBuildName); } diff --git a/ext/wasm/util.make b/ext/wasm/util.make new file mode 100644 index 0000000000..704299346d --- /dev/null +++ b/ext/wasm/util.make @@ -0,0 +1,93 @@ +# +# Common vars and utilities for the SQLite WASM build. +# +# The "b." prefix on some APIs is for "build". It was initially used +# only for build-specific features, but that's no longer the came, but +# the naming convention has stuck. +# + +loud ?= 0 +ifeq (1,$(loud)) + $(info $(emo.megaphone) Emitting loud build info. Pass loud=0 to disable it.) + b.cmd.loud = +else + $(info $(emo.mute) Eliding loud build info. Pass loud=1 to enable it.) + b.cmd.loud = @ +endif + +# +# Emoji for log messages. +# +emo.bug = 🐞 +emo.compile = ⏳ +emo.disk = 💾 +emo.done = 🏆 +emo.fire = 🔥 +emo.folder = 📁 +emo.garbage =🗑 +emo.megaphone = 📣 +emo.mute = 🔇 +emo.stop =🛑 +emo.strip =🪚 +emo.tool = 🔨 + +# +# logtag.X value for log context labeling. longtag.OTHERX can be +# assigned to customize it for a given X. +# +logtag.@ = [$@] + +# +# $(call b.call.mkdir@) +# +# $1 = optional build name +# +b.call.mkdir@ = if [ ! -d $(dir $@) ]; then \ + echo '[$(emo.folder)+] $(if $(1),$(logtag.$(1)),[$(dir $@)])'; \ + mkdir -p $(dir $@) || exit $$?; fi + +# +# $(call b.call.cp,@,src,dest) +# +# $1 = build name, $2 = src file(s). $3 = dest dir +b.call.cp = $(call b.call.mkdir@); \ + echo '$(logtag.$(1)) $(emo.disk) $(2) ==> $3'; \ + cp -p $(2) $(3) || exit $$$$? + +# +# $(eval $(call b.eval.c-pp,@,src,dest,-Dx=y...)) +# +# $1 = build name +# $2 = Input file(s): cat $(2) | $(bin.c-pp) ... +# $3 = Output file: $(bin.c-pp) -o $(3) +# $4 = optional $(bin.c-pp) -D... flags */ +# +define b.eval.c-pp +$(3): $$(MAKEFILE_LIST) $$(bin.c-pp) $(2) + @$$(call b.call.mkdir@); \ + echo '$$(logtag.$(1)) $$(emo.disk) $(4)'; \ + cat $(2) | $$(bin.c-pp) -o $(3) $(4) $$(SQLITE.CALL.C-PP.FILTER.global) \ + || exit $$$$?\n +CLEAN_FILES += $(3) +endef + +# +# $(call b.call.strip-emcc-js-cruft) +# +# Our JS code installs bindings of each sqlite3_...() WASM export. The +# generated Emscripten JS file does the same using its own framework, +# but we don't use those results and can speed up lib init, and reduce +# memory cost a bit, by stripping them out. Emscripten-side changes +# can "break" this, causing this to be a no-op, but the worst that can +# happen in that case is that it doesn't actually strip anything, +# leading to slightly larger JS files. +# +# This snippet is intended to be used in makefile targets which +# generate an Emscripten module and where $@ is the module's .js/.mjs +# file. +# +# $1 = an optional log message prefix +b.call.strip-emcc-js-cruft = \ + sed -i -e '/^.*= \(_sqlite3\|_fiddle\)[^=]*=.*createExportWrapper/d' \ + -e '/^var \(_sqlite3\|_fiddle\)[^=]*=.*makeInvalidEarlyAccess/d' $@ || exit; \ + echo '$(1) $(emo.garbage) (Probably) /createExportWrapper()/d and /makeInvalidEarlyAccess()/d' diff --git a/manifest b/manifest index d35561097d..abf6fee1d8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Generic\sbuild\ssimplifications. -D 2025-09-24T03:05:31.667 +C Move\ssome\sof\sthe\sgenerated\swasm\smakefile\sutility\scode\sout\sof\sC\sand\sinto\sutil.make. +D 2025-09-24T04:58:14.025 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 87fac98d2dbca42c8361aa7951b951f9e5b6084ce78f8e56b81bd9a594c74c73 +F ext/wasm/GNUmakefile 613f0baf08b905dfeb67f0f405be8b466870e72040970c7b631d0d3483aed329 F ext/wasm/README-dist.txt f01081a850ce38a56706af6b481e3a7878e24e42b314cfcd4b129f0f8427066a F ext/wasm/README.md 66ace67ae98a45e4116f2ca5425b716887bcee4d64febee804ff6398e1ae9ec7 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -631,7 +631,7 @@ F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2 F ext/wasm/demo-worker1.js 08720227e98fa5b44761cf6e219269cee3e9dd0421d8d91459535da776950314 F ext/wasm/dist.make 57f5da2f0de5a297b5a0bc39ffec736380050578240ab24d864c2ff1b3634a3b F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f -F ext/wasm/fiddle.make c3ecfae3328526c8048cbd2e71888bebe2a438077268e9a8f2e302d33db91e4d +F ext/wasm/fiddle.make 6875473b9fc25e8ba35d62341fdf8bc0980aa52de637daf5b9cfd864cfe43161 F ext/wasm/fiddle/fiddle-worker.js 7798af02e672e088ff192716f80626c8895e19301a65b8af6d5d12b2d13d2451 F ext/wasm/fiddle/fiddle.js 84fd75967e0af8b69d3dd849818342227d0f81d13db92e0dcbc63649b31a4893 F ext/wasm/fiddle/index.html a27b8127ef9ecf19612da93b2a6a73bdb3777b5c56b5450bb7200a94bc108ff9 @@ -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 87ee81ce0f78d31ca1e8ce58a1bc74ac6a0cecf6494612f093951197bab80462 +F ext/wasm/mkwasmbuilds.c 4bd08e7d51d6981a1c5915251b8ed2ed02bca88ab4d33395d97deb757d4c672a F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 @@ -664,6 +664,7 @@ F ext/wasm/tests/opfs/sahpool/digest.html 206d08a34dc8bd570b2581d3d9ab3ecad3201b F ext/wasm/tests/opfs/sahpool/index.html be736567fd92d3ecb9754c145755037cbbd2bca01385e2732294b53f4c842328 F ext/wasm/tests/opfs/sahpool/sahpool-pausing.js f264925cfc82155de38cecb3d204c36e0f6991460fff0cb7c15079454679a4e2 F ext/wasm/tests/opfs/sahpool/sahpool-worker.js bd25a43fc2ab2d1bafd8f2854ad3943ef673f7c3be03e95ecf1612ff6e8e2a61 +F ext/wasm/util.make a500a5e82b8df9918a2fe5933be20684063b130783e45653d81c07cc3cd3bb92 F ext/wasm/wasmfs.make 5de02751b3e9e79b81a52ab4fe0ed6aa6a23311a90db58fea98c1c4e2845e562 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 F main.mk 20fe7a151708fc6b1f8cd0fdcc73622701cff5959131cfb73e1f75d33e687bf8 @@ -2175,8 +2176,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 85fe9c6155f72583cea46d38bf5e040623d71fb5317ff9373421dbfdb179b2b0 -R 98bc100816e0f8dda14ba297aca98894 +P 61648610c3e454fce77b78e6f6be1b71e27bb9587af03ae5c0e083eac7158a64 +R d5aba8b9559a3ddbff76cbd26aca8857 U stephan -Z 7161ecf91dac252ddb71b18b364e931a +Z fb9bb507dc672f8ae32e129d4eb47e84 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a802384b39..b2a6b1a919 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -61648610c3e454fce77b78e6f6be1b71e27bb9587af03ae5c0e083eac7158a64 +a2935758f534b51cac3d2e5ece74b369c806e3a994781744708e1590b9c32542