Snapshot of upstream SQLite 3.43.2
[sqlcipher.git] / ext / wasm / wasmfs.make
blob71c0fe75a82509f1e67c86ed030ec59bc9196226
1 #!/usr/bin/make
2 #^^^^ help emacs select makefile mode
4 # This is a sub-make for building a standalone wasmfs-based
5 # sqlite3.wasm. It is intended to be "include"d from the main
6 # GNUMakefile.
7 ########################################################################
8 MAKEFILE.wasmfs := $(lastword $(MAKEFILE_LIST))
9 $(warning The WASMFS build is currently incomplete.)
11 #dir.wasmfs := $(dir.wasm)
12 dir.wasmfs := $(dir.dout)
13 sqlite3-wasmfs.js := $(dir.wasmfs)/sqlite3-wasmfs.js
14 sqlite3-wasmfs.mjs := $(dir.wasmfs)/sqlite3-wasmfs.mjs
15 sqlite3-wasmfs.wasm := $(dir.wasmfs)/sqlite3-wasmfs.wasm
17 CLEAN_FILES += $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.wasm) \
18 $(subst .js,.worker.js,$(sqlite3-wasmfs.js)) \
19 $(sqlite3-wasmfs.mjs) \
20 $(subst .mjs,.worker.mjs,$(sqlite3-wasmfs.mjs))
22 ########################################################################
23 # emcc flags for .c/.o.
24 cflags.sqlite3-wasmfs :=
25 cflags.sqlite3-wasmfs += -std=c99 -fPIC
26 cflags.sqlite3-wasmfs += -pthread
27 cflags.sqlite3-wasmfs += -DSQLITE_ENABLE_WASMFS
29 ########################################################################
30 # emcc flags specific to building the final .js/.wasm file...
31 emcc.flags.sqlite3-wasmfs :=
32 emcc.flags.sqlite3-wasmfs += \
33 -sEXPORTED_RUNTIME_METHODS=wasmMemory,allocateUTF8OnStack,stringToUTF8OnStack
34 # wasmMemory ==> for -sIMPORTED_MEMORY
35 # *OnStack ==> wasmfs internals (leaky abstraction)
36 emcc.flags.sqlite3-wasmfs += -sUSE_CLOSURE_COMPILER=0
37 emcc.flags.sqlite3-wasmfs += -Wno-limited-postlink-optimizations
38 # ^^^^^ it likes to warn when we have "limited optimizations" via the -g3 flag.
39 emcc.flags.sqlite3-wasmfs += -sMEMORY64=0
40 emcc.flags.sqlite3-wasmfs += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.128)
41 # ^^^^ 64MB is not enough for WASMFS/OPFS test runs using batch-runner.js
42 sqlite3-wasmfs.fsflags := -pthread -sWASMFS \
43 -sPTHREAD_POOL_SIZE=1 \
44 -sERROR_ON_UNDEFINED_SYMBOLS=0 -sLLD_REPORT_UNDEFINED
45 # ^^^^^ why undefined symbols are necessary for the wasmfs build is anyone's guess.
46 emcc.flags.sqlite3-wasmfs += $(sqlite3-wasmfs.fsflags)
47 emcc.flags.sqlite3-wasmfs += -sALLOW_MEMORY_GROWTH=0
48 #^^^ using ALLOW_MEMORY_GROWTH produces a warning from emcc:
49 # USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly,
50 # see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]
51 # And, indeed, it runs slowly if memory is permitted to grow.
52 #emcc.flags.sqlite3-wasmfs.vanilla :=
53 #emcc.flags.sqlite3-wasmfs.esm := -sEXPORT_ES6 -sUSE_ES6_IMPORT_META
54 sqlite3-api.mjs.wasmfs := $(dir.tmp)/sqlite3-api-wasmfs.mjs
55 $(eval $(call SETUP_LIB_BUILD_MODE,sqlite3-wasmfs,esm,1,\
56 $(sqlite3-api.mjs.wasmfs), $(sqlite3-wasmfs.mjs),\
57 $(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs,\
58 -sEXPORT_ES6 -sUSE_ES6_IMPORT_META\
60 $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(MAKEFILE.wasmfs)
61 ########################################################################
62 # Build quirk: we cannot build BOTH .js and .mjs with our current
63 # build infrastructure because the supplemental *.worker.js files get
64 # generated with the name of the main module file
65 # ($(sqlite3-wasmfs.{js,mjs})) hard-coded in them. Thus the last one
66 # to get built gets the *.worker.js files mapped to it. In order to
67 # build both modes they would need to have distinct base names or
68 # output directories. "The problem" with giving them distinct base
69 # names is that it means that the corresponding .wasm file is also
70 # built/saved multiple times.
72 wasmfs.build.ext := mjs
73 $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(SOAP.js.bld)
74 ifeq (js,$(wasmfs.build.ext))
75 $(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.js)
76 wasmfs: $(sqlite3-wasmfs.js)
77 else
78 $(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.mjs)
79 wasmfs: $(sqlite3-wasmfs.mjs)
80 endif
81 #all: wasmfs
83 ########################################################################
84 # speedtest1 for wasmfs.
85 speedtest1-wasmfs.mjs := $(dir.wasmfs)/speedtest1-wasmfs.mjs
86 speedtest1-wasmfs.wasm := $(subst .mjs,.wasm,$(speedtest1-wasmfs.mjs))
87 emcc.flags.speedtest1-wasmfs := $(sqlite3-wasmfs.fsflags)
88 emcc.flags.speedtest1-wasmfs += $(SQLITE_OPT)
89 emcc.flags.speedtest1-wasmfs += -sALLOW_MEMORY_GROWTH=0
90 emcc.flags.speedtest1-wasmfs += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.128)
91 #$(eval $(call call-make-pre-js,speedtest1-wasmfs,ems))
92 $(speedtest1-wasmfs.mjs): $(speedtest1.cfiles) $(sqlite3-wasmfs.js) \
93 $(MAKEFILE) $(MAKEFILE.wasmfs) \
94 $(pre-post-sqlite3-wasmfs-esm.deps) \
95 $(EXPORTED_FUNCTIONS.speedtest1)
96 @echo "Building $@ ..."
97 $(emcc.bin) \
98 $(pre-post-sqlite3-wasmfs-esm.flags) \
99 $(cflags.common) \
100 $(cflags.sqlite3-wasmfs) \
101 $(emcc.speedtest1.common) \
102 $(emcc.flags.speedtest1-vanilla) \
103 $(emcc.flags.sqlite3-wasmfs) \
104 $(emcc.flags.speedtest1-wasmfs) \
105 -o $@ $(speedtest1.cfiles) -lm
106 @$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,1)
107 $(maybe-wasm-strip) $(speedtest1-wasmfs.wasm)
108 chmod -x $(speedtest1-wasmfs.wasm)
109 ls -la $@ $(speedtest1-wasmfs.wasm)
111 wasmfs: $(speedtest1-wasmfs.mjs)
112 CLEAN_FILES += $(speedtest1-wasmfs.mjs) $(speedtest1-wasmfs.wasm) \
113 $(subst .js,.worker.js,$(speedtest1-wasmfs.mjs))
114 # end speedtest1.js
115 ########################################################################