2022-09-15 06:09:00 +03:00
|
|
|
#!/usr/bin/make
|
|
|
|
#^^^^ help emacs select makefile mode
|
|
|
|
#
|
|
|
|
# This is a sub-make for building a standalone wasmfs-based
|
|
|
|
# sqlite3.wasm. It is intended to be "include"d from the main
|
|
|
|
# GNUMakefile.
|
|
|
|
########################################################################
|
|
|
|
MAKEFILE.wasmfs := $(lastword $(MAKEFILE_LIST))
|
2023-07-13 07:26:13 +03:00
|
|
|
$(warning The WASMFS build is currently incomplete.)
|
2022-09-15 06:09:00 +03:00
|
|
|
|
2023-07-13 07:26:13 +03:00
|
|
|
#dir.wasmfs := $(dir.wasm)
|
|
|
|
dir.wasmfs := $(dir.dout)
|
2022-10-19 04:07:30 +03:00
|
|
|
sqlite3-wasmfs.js := $(dir.wasmfs)/sqlite3-wasmfs.js
|
2022-12-17 14:14:35 +03:00
|
|
|
sqlite3-wasmfs.mjs := $(dir.wasmfs)/sqlite3-wasmfs.mjs
|
2022-10-19 04:07:30 +03:00
|
|
|
sqlite3-wasmfs.wasm := $(dir.wasmfs)/sqlite3-wasmfs.wasm
|
2022-09-15 06:09:00 +03:00
|
|
|
|
2022-09-15 09:42:41 +03:00
|
|
|
CLEAN_FILES += $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.wasm) \
|
2022-12-17 14:14:35 +03:00
|
|
|
$(subst .js,.worker.js,$(sqlite3-wasmfs.js)) \
|
|
|
|
$(sqlite3-wasmfs.mjs) \
|
|
|
|
$(subst .mjs,.worker.mjs,$(sqlite3-wasmfs.mjs))
|
2022-09-15 06:09:00 +03:00
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# emcc flags for .c/.o.
|
2022-12-17 14:14:35 +03:00
|
|
|
cflags.sqlite3-wasmfs :=
|
|
|
|
cflags.sqlite3-wasmfs += -std=c99 -fPIC
|
|
|
|
cflags.sqlite3-wasmfs += -pthread
|
|
|
|
cflags.sqlite3-wasmfs += $(cflags.speedtest1)
|
|
|
|
cflags.sqlite3-wasmfs += $(SQLITE_OPT) -DSQLITE_ENABLE_WASMFS
|
2022-09-15 06:09:00 +03:00
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# emcc flags specific to building the final .js/.wasm file...
|
2022-12-17 14:14:35 +03:00
|
|
|
emcc.flags.sqlite3-wasmfs := -fPIC
|
|
|
|
emcc.flags.sqlite3-wasmfs += --no-entry
|
|
|
|
emcc.flags.sqlite3-wasmfs += --minify 0
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sMODULARIZE
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sEXPORT_NAME=$(sqlite3.js.init-func)
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sDYNAMIC_EXECUTION=0
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sNO_POLYFILL
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sWASM_BIGINT=$(emcc.WASM_BIGINT)
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sEXPORTED_FUNCTIONS=@$(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api)
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory,allocateUTF8OnStack
|
|
|
|
# wasmMemory ==> for -sIMPORTED_MEMORY
|
|
|
|
# allocateUTF8OnStack ==> wasmfs internals
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sUSE_CLOSURE_COMPILER=0
|
|
|
|
emcc.flags.sqlite3-wasmfs += -Wno-limited-postlink-optimizations
|
2022-09-15 06:09:00 +03:00
|
|
|
# ^^^^^ it likes to warn when we have "limited optimizations" via the -g3 flag.
|
2022-12-17 14:14:35 +03:00
|
|
|
emcc.flags.sqlite3-wasmfs += -sALLOW_TABLE_GROWTH
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sSTACK_SIZE=512KB
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sGLOBAL_BASE=4096 # HYPOTHETICALLY keep func table indexes from overlapping w/ heap addr.
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sMEMORY64=0
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sIMPORTED_MEMORY
|
|
|
|
emcc.flags.sqlite3-wasmfs += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.128)
|
2022-10-30 11:39:18 +03:00
|
|
|
# ^^^^ 64MB is not enough for WASMFS/OPFS test runs using batch-runner.js
|
2022-12-17 14:14:35 +03:00
|
|
|
sqlite3-wasmfs.fsflags := -pthread -sWASMFS \
|
|
|
|
-sPTHREAD_POOL_SIZE=2 -sENVIRONMENT=web,worker \
|
|
|
|
-sERROR_ON_UNDEFINED_SYMBOLS=0 -sLLD_REPORT_UNDEFINED
|
|
|
|
# ^^^^^ why undefined symbols are necessary for the wasmfs build is anyone's guess.
|
|
|
|
emcc.flags.sqlite3-wasmfs += $(sqlite3-wasmfs.fsflags)
|
|
|
|
#emcc.flags.sqlite3-wasmfs += -sALLOW_MEMORY_GROWTH
|
2022-09-15 06:09:00 +03:00
|
|
|
#^^^ using ALLOW_MEMORY_GROWTH produces a warning from emcc:
|
|
|
|
# USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly,
|
|
|
|
# see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]
|
2022-12-17 14:14:35 +03:00
|
|
|
# And, indeed, it runs slowly if memory is permitted to grow.
|
|
|
|
emcc.flags.sqlite3-wasmfs.vanilla :=
|
|
|
|
emcc.flags.sqlite3-wasmfs.esm := -sEXPORT_ES6 -sUSE_ES6_IMPORT_META
|
2023-07-13 07:26:13 +03:00
|
|
|
$(eval $(call call-make-pre-post,sqlite3-wasmfs,vanilla))
|
|
|
|
$(eval $(call call-make-pre-post,sqlite3-wasmfs,esm))
|
2022-12-17 14:14:35 +03:00
|
|
|
Xemcc.flags.sqlite3-wasmfs.vanilla += \
|
2022-11-19 08:26:45 +03:00
|
|
|
$(pre-post-common.flags.vanilla) \
|
|
|
|
$(pre-post-sqlite3-wasmfs.flags.vanilla)
|
2022-12-17 14:14:35 +03:00
|
|
|
Xemcc.flags.sqlite3-wasmfs.esm += \
|
|
|
|
$(pre-post-common.flags.esm) \
|
|
|
|
$(pre-post-sqlite3-wasmfs.flags.esm)
|
|
|
|
$(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(sqlite3-wasm.c) \
|
|
|
|
$(EXPORTED_FUNCTIONS.api) $(MAKEFILE) $(MAKEFILE.wasmfs)
|
|
|
|
$(sqlite3-wasmfs.js): $(pre-post-sqlite3-wasmfs.deps.vanilla)
|
|
|
|
$(sqlite3-wasmfs.mjs): $(pre-post-sqlite3-wasmfs.deps.esm)
|
|
|
|
# SQLITE3-WASMFS.xJS.RECIPE is the wasmfs-specific counterpart
|
|
|
|
# of SQLITE3.xJS.RECIPE from the main makefile.
|
|
|
|
define SQLITE3-WASMFS.xJS.RECIPE
|
2022-09-15 06:09:00 +03:00
|
|
|
@echo "Building $@ ..."
|
2022-09-29 20:35:25 +03:00
|
|
|
$(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \
|
2022-12-17 14:14:35 +03:00
|
|
|
$(cflags.sqlite3-wasmfs) \
|
|
|
|
$(emcc.flags.sqlite3-wasmfs) $(emcc.flags.sqlite3-wasmfs.$(1)) \
|
|
|
|
$(pre-post-sqlite3-wasmfs.flags.$(1)) \
|
2022-10-17 20:34:41 +03:00
|
|
|
$(sqlite3-wasm.c)
|
2023-07-13 07:26:13 +03:00
|
|
|
@$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,$(if $(filter %.mjs,$@),1,))
|
2022-09-15 09:42:41 +03:00
|
|
|
chmod -x $(sqlite3-wasmfs.wasm)
|
|
|
|
$(maybe-wasm-strip) $(sqlite3-wasmfs.wasm)
|
2023-07-13 07:26:13 +03:00
|
|
|
@ls -la $(sqlite3-wasmfs.wasm) $(dir.wasmfs)/sqlite3-wasmfs*js
|
2022-12-17 14:14:35 +03:00
|
|
|
endef
|
2023-07-13 07:26:13 +03:00
|
|
|
########################################################################
|
|
|
|
# Build quirk: we cannot build BOTH .js and .mjs with our current
|
|
|
|
# build infrastructure because the supplemental *.worker.js files get
|
|
|
|
# generated with the name of the main module file
|
|
|
|
# ($(sqlite3-wasmfs.{js,mjs})) hard-coded in them. Thus the last one
|
|
|
|
# to get built gets the *.worker.js files mapped to it. In order to
|
|
|
|
# build both modes they would need to have distinct base names or
|
|
|
|
# output directories.
|
|
|
|
#
|
|
|
|
wasmfs.build.ext := mjs
|
|
|
|
ifeq (js,$(wasmfs.build.mode))
|
2022-12-17 14:14:35 +03:00
|
|
|
$(sqlite3-wasmfs.js):
|
|
|
|
$(call SQLITE3-WASMFS.xJS.RECIPE,vanilla)
|
2022-10-17 20:34:41 +03:00
|
|
|
$(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.js)
|
2023-07-13 07:26:13 +03:00
|
|
|
wasmfs: $(sqlite3-wasmfs.js)
|
|
|
|
else
|
|
|
|
$(sqlite3-wasmfs.mjs): # $(sqlite3-wasmfs.js)
|
|
|
|
$(call SQLITE3-WASMFS.xJS.RECIPE,esm)
|
|
|
|
$(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.mjs)
|
|
|
|
wasmfs: $(sqlite3-wasmfs.mjs)
|
|
|
|
endif
|
2022-12-17 14:14:35 +03:00
|
|
|
#all: wasmfs
|
2022-09-15 09:42:41 +03:00
|
|
|
|
|
|
|
########################################################################
|
2022-10-30 12:47:33 +03:00
|
|
|
# speedtest1 for wasmfs.
|
2022-10-19 04:07:30 +03:00
|
|
|
speedtest1-wasmfs.js := $(dir.wasmfs)/speedtest1-wasmfs.js
|
2022-09-15 09:42:41 +03:00
|
|
|
speedtest1-wasmfs.wasm := $(subst .js,.wasm,$(speedtest1-wasmfs.js))
|
2022-12-17 14:14:35 +03:00
|
|
|
emcc.flags.speedtest1-wasmfs := $(sqlite3-wasmfs.fsflags)
|
|
|
|
emcc.flags.speedtest1-wasmfs += $(SQLITE_OPT) -DSQLITE_ENABLE_WASMFS
|
|
|
|
emcc.flags.speedtest1-wasmfs += -sALLOW_MEMORY_GROWTH=0
|
|
|
|
emcc.flags.speedtest1-wasmfs += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.128)
|
|
|
|
#$(eval $(call call-make-pre-js,speedtest1-wasmfs,vanilla))
|
2022-10-19 04:07:30 +03:00
|
|
|
$(speedtest1-wasmfs.js): $(speedtest1.cses) $(sqlite3-wasmfs.js) \
|
2022-09-30 01:08:22 +03:00
|
|
|
$(MAKEFILE) $(MAKEFILE.wasmfs) \
|
2022-12-17 14:14:35 +03:00
|
|
|
$(pre-post-sqlite3-wasmfs.deps) \
|
2022-10-19 04:07:30 +03:00
|
|
|
$(EXPORTED_FUNCTIONS.speedtest1)
|
2022-09-15 09:42:41 +03:00
|
|
|
@echo "Building $@ ..."
|
|
|
|
$(emcc.bin) \
|
2022-12-17 14:14:35 +03:00
|
|
|
$(emcc.speedtest1.common) $(emcc.flags.speedtest1-wasmfs) \
|
|
|
|
$(pre-post-sqlite3-wasmfs.flags.vanilla) \
|
|
|
|
$(cflags.sqlite3-wasmfs) \
|
2022-10-19 04:07:30 +03:00
|
|
|
-o $@ $(speedtest1.cses) -lm
|
2022-09-15 09:42:41 +03:00
|
|
|
$(maybe-wasm-strip) $(speedtest1-wasmfs.wasm)
|
|
|
|
ls -la $@ $(speedtest1-wasmfs.wasm)
|
|
|
|
|
2023-07-13 07:26:13 +03:00
|
|
|
#wasmfs: $(speedtest1-wasmfs.js)
|
2022-09-15 09:42:41 +03:00
|
|
|
CLEAN_FILES += $(speedtest1-wasmfs.js) $(speedtest1-wasmfs.wasm) \
|
|
|
|
$(subst .js,.worker.js,$(speedtest1-wasmfs.js))
|
|
|
|
# end speedtest1.js
|
|
|
|
########################################################################
|