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))
|
|
|
|
|
2022-09-15 09:42:41 +03:00
|
|
|
sqlite3-wasmfs.js := sqlite3-wasmfs.js
|
|
|
|
sqlite3-wasmfs.wasm := 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) \
|
|
|
|
$(subst .js,.worker.js,$(sqlite3-wasmfs.js))
|
2022-09-15 06:09:00 +03:00
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# emcc flags for .c/.o/.wasm.
|
2022-09-15 09:42:41 +03:00
|
|
|
sqlite3-wasmfs.flags =
|
|
|
|
#sqlite3-wasmfs.flags += -v # _very_ loud but also informative about what it's doing
|
2022-09-15 06:09:00 +03:00
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# emcc flags for .c/.o.
|
2022-09-15 09:42:41 +03:00
|
|
|
sqlite3-wasmfs.cflags :=
|
2022-09-30 01:08:22 +03:00
|
|
|
sqlite3-wasmfs.cflags += -std=c99 -fPIC
|
2022-09-15 09:42:41 +03:00
|
|
|
sqlite3-wasmfs.cflags += -pthread
|
|
|
|
sqlite3-wasmfs.cflags += -I. -I.. -I$(dir.top)
|
|
|
|
sqlite3-wasmfs.cflags += $(SQLITE_OPT) -DSQLITE_WASM_WASMFS
|
2022-09-15 06:09:00 +03:00
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# emcc flags specific to building the final .js/.wasm file...
|
2022-09-15 09:42:41 +03:00
|
|
|
sqlite3-wasmfs.jsflags := -fPIC
|
|
|
|
sqlite3-wasmfs.jsflags += --no-entry
|
|
|
|
sqlite3-wasmfs.jsflags += --minify 0
|
|
|
|
sqlite3-wasmfs.jsflags += -sMODULARIZE
|
|
|
|
sqlite3-wasmfs.jsflags += -sSTRICT_JS
|
|
|
|
sqlite3-wasmfs.jsflags += -sDYNAMIC_EXECUTION=0
|
|
|
|
sqlite3-wasmfs.jsflags += -sNO_POLYFILL
|
2022-10-17 20:34:41 +03:00
|
|
|
sqlite3-wasmfs.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api
|
2022-09-15 09:42:41 +03:00
|
|
|
sqlite3-wasmfs.jsflags += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory,allocateUTF8OnStack
|
2022-09-15 06:09:00 +03:00
|
|
|
# wasmMemory ==> for -sIMPORTED_MEMORY
|
|
|
|
# allocateUTF8OnStack ==> wasmfs internals
|
2022-09-15 09:42:41 +03:00
|
|
|
sqlite3-wasmfs.jsflags += -sUSE_CLOSURE_COMPILER=0
|
|
|
|
sqlite3-wasmfs.jsflags += -sIMPORTED_MEMORY
|
|
|
|
#sqlite3-wasmfs.jsflags += -sINITIAL_MEMORY=13107200
|
|
|
|
#sqlite3-wasmfs.jsflags += -sTOTAL_STACK=4194304
|
2022-09-29 16:17:50 +03:00
|
|
|
sqlite3-wasmfs.jsflags += -sEXPORT_NAME=$(sqlite3.js.init-func)
|
2022-09-15 09:42:41 +03:00
|
|
|
sqlite3-wasmfs.jsflags += -sGLOBAL_BASE=4096 # HYPOTHETICALLY keep func table indexes from overlapping w/ heap addr.
|
|
|
|
#sqlite3-wasmfs.jsflags += -sFILESYSTEM=0 # only for experimentation. sqlite3 needs the FS API
|
2022-09-15 06:09:00 +03:00
|
|
|
# Perhaps the wasmfs build doesn't?
|
2022-09-15 09:42:41 +03:00
|
|
|
#sqlite3-wasmfs.jsflags += -sABORTING_MALLOC
|
|
|
|
sqlite3-wasmfs.jsflags += -sALLOW_TABLE_GROWTH
|
|
|
|
sqlite3-wasmfs.jsflags += -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-09-15 09:42:41 +03:00
|
|
|
sqlite3-wasmfs.jsflags += -sERROR_ON_UNDEFINED_SYMBOLS=0
|
|
|
|
sqlite3-wasmfs.jsflags += -sLLD_REPORT_UNDEFINED
|
|
|
|
#sqlite3-wasmfs.jsflags += --import-undefined
|
|
|
|
sqlite3-wasmfs.jsflags += -sMEMORY64=0
|
|
|
|
sqlite3-wasmfs.jsflags += -sINITIAL_MEMORY=128450560
|
|
|
|
sqlite3-wasmfs.fsflags := -pthread -sWASMFS -sPTHREAD_POOL_SIZE=2 -sENVIRONMENT=web,worker
|
2022-09-30 01:08:22 +03:00
|
|
|
# -sPTHREAD_POOL_SIZE values of 2 or higher trigger that bug.
|
2022-09-15 09:42:41 +03:00
|
|
|
sqlite3-wasmfs.jsflags += $(sqlite3-wasmfs.fsflags)
|
|
|
|
#sqlite3-wasmfs.jsflags += -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-09-21 22:51:25 +03:00
|
|
|
sqlite3-wasmfs.jsflags += -sWASM_BIGINT=$(emcc_enable_bigint)
|
2022-09-30 01:08:22 +03:00
|
|
|
$(eval $(call call-make-pre-js,sqlite3-wasmfs))
|
|
|
|
sqlite3-wasmfs.jsflags += $(pre-post-common.flags) $(pre-post-sqlite3-wasmfs.flags)
|
2022-10-17 20:34:41 +03:00
|
|
|
$(sqlite3-wasmfs.js): $(sqlite3-wasm.c) \
|
2022-09-30 01:08:22 +03:00
|
|
|
EXPORTED_FUNCTIONS.api $(MAKEFILE) $(MAKEFILE.wasmfs) \
|
|
|
|
$(pre-post-sqlite3-wasmfs.deps)
|
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-09-30 01:08:22 +03:00
|
|
|
$(sqlite3-wasmfs.cflags) $(sqlite3-wasmfs.jsflags) \
|
2022-10-17 20:34:41 +03:00
|
|
|
$(sqlite3-wasm.c)
|
2022-09-15 09:42:41 +03:00
|
|
|
chmod -x $(sqlite3-wasmfs.wasm)
|
|
|
|
$(maybe-wasm-strip) $(sqlite3-wasmfs.wasm)
|
|
|
|
@ls -la $@ $(sqlite3-wasmfs.wasm)
|
2022-10-17 20:34:41 +03:00
|
|
|
$(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.js)
|
2022-09-15 09:42:41 +03:00
|
|
|
wasmfs: $(sqlite3-wasmfs.js)
|
2022-09-15 06:09:00 +03:00
|
|
|
all: wasmfs
|
2022-09-15 09:42:41 +03:00
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# speedtest1 for wasmfs. Re. sqlite3-wasm.o vs sqlite3-wasm.c:
|
|
|
|
# building against the latter (predictably) results in a slightly
|
|
|
|
# faster binary.
|
|
|
|
speedtest1-wasmfs.js := speedtest1-wasmfs.js
|
|
|
|
speedtest1-wasmfs.wasm := $(subst .js,.wasm,$(speedtest1-wasmfs.js))
|
2022-09-19 17:56:13 +03:00
|
|
|
speedtest1-wasmfs.eflags := $(sqlite3-wasmfs.fsflags)
|
2022-09-15 09:42:41 +03:00
|
|
|
speedtest1-wasmfs.eflags += $(SQLITE_OPT) -DSQLITE_WASM_WASMFS
|
2022-09-30 01:08:22 +03:00
|
|
|
$(eval $(call call-make-pre-js,speedtest1-wasmfs))
|
2022-09-19 17:56:13 +03:00
|
|
|
$(speedtest1-wasmfs.js): $(speedtest1.cs) $(sqlite3-wasmfs.js) \
|
2022-09-30 01:08:22 +03:00
|
|
|
$(MAKEFILE) $(MAKEFILE.wasmfs) \
|
|
|
|
$(pre-post-speedtest1-wasmfs.deps) \
|
2022-09-19 17:56:13 +03:00
|
|
|
EXPORTED_FUNCTIONS.speedtest1
|
2022-09-15 09:42:41 +03:00
|
|
|
@echo "Building $@ ..."
|
|
|
|
$(emcc.bin) \
|
|
|
|
$(speedtest1-wasmfs.eflags) $(speedtest1-common.eflags) \
|
2022-09-30 01:08:22 +03:00
|
|
|
$(pre-post-speedtest1-wasmfs.flags) \
|
2022-09-15 09:42:41 +03:00
|
|
|
$(speedtest1.cflags) \
|
|
|
|
$(sqlite3-wasmfs.cflags) \
|
2022-09-19 17:56:13 +03:00
|
|
|
-o $@ $(speedtest1.cs) -lm
|
2022-09-15 09:42:41 +03:00
|
|
|
$(maybe-wasm-strip) $(speedtest1-wasmfs.wasm)
|
|
|
|
ls -la $@ $(speedtest1-wasmfs.wasm)
|
|
|
|
|
|
|
|
speedtest1: $(speedtest1-wasmfs.js)
|
|
|
|
CLEAN_FILES += $(speedtest1-wasmfs.js) $(speedtest1-wasmfs.wasm) \
|
|
|
|
$(subst .js,.worker.js,$(speedtest1-wasmfs.js))
|
|
|
|
# end speedtest1.js
|
|
|
|
########################################################################
|