|
1 |
| -EMCC=emcc |
| 1 | +# Note: Last built with version 1.38.30 of Emscripten |
2 | 2 |
|
3 |
| -CFLAGS=-O2 -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DISABLE_LFS -DLONGDOUBLE_TYPE=double -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS |
| 3 | +# TODO: Emit a file showing which version of emcc and SQLite was used to compile the emitted output. |
| 4 | +# TODO: Create a release on Github with these compiled assets rather than checking them in |
| 5 | +# TODO: Consider creating different files based on browser vs module usage: https://github.com/vuejs/vue/tree/dev/dist |
4 | 6 |
|
5 |
| -all: js/sql.js debug js/worker.sql.js memory-growth |
| 7 | +# I got this handy makefile syntax from : https://github.com/mandel59/sqlite-wasm (MIT License) Credited in LICENSE |
| 8 | +# To use another version of Sqlite, visit https://www.sqlite.org/download.html and copy the appropriate values here: |
| 9 | +SQLITE_AMALGAMATION = sqlite-amalgamation-3280000 |
| 10 | +SQLITE_AMALGAMATION_ZIP_URL = https://www.sqlite.org/2019/sqlite-amalgamation-3280000.zip |
| 11 | +SQLITE_AMALGAMATION_ZIP_SHA1 = eb82fcc95104c8e2d9550ab023c1054b9cc40a76 |
6 | 12 |
|
7 |
| -# RESERVED_FUNCTION_POINTERS setting is used for registering custom functions |
8 |
| -optimized: EMFLAGS= --memory-init-file 0 -O3 -s INLINING_LIMIT=50 -s RESERVED_FUNCTION_POINTERS=64 |
9 |
| -optimized: js/sql-optimized.js |
| 13 | +# Note that extension-functions.c hasn't been updated since 2010-02-06, so likely doesn't need to be updated |
| 14 | +EXTENSION_FUNCTIONS = extension-functions.c |
| 15 | +EXTENSION_FUNCTIONS_URL = https://www.sqlite.org/contrib/download/extension-functions.c?get=25 |
| 16 | +EXTENSION_FUNCTIONS_SHA1 = c68fa706d6d9ff98608044c00212473f9c14892f |
10 | 17 |
|
11 |
| -memory-growth: EMFLAGS= --memory-init-file 0 -O3 -s INLINING_LIMIT=50 -s RESERVED_FUNCTION_POINTERS=64 -s ALLOW_MEMORY_GROWTH=1 |
12 |
| -memory-growth: js/sql-memory-growth.js |
| 18 | +EMCC=emcc |
13 | 19 |
|
14 |
| -debug: EMFLAGS= -O1 -g -s INLINING_LIMIT=10 -s RESERVED_FUNCTION_POINTERS=64 |
15 |
| -debug: js/sql-debug.js |
| 20 | +CFLAGS=-O2 -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DISABLE_LFS -DLONGDOUBLE_TYPE=double -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS |
16 | 21 |
|
17 |
| -js/sql.js: optimized |
18 |
| - cp js/sql-optimized.js js/sql.js |
| 22 | +# When compiling to WASM, enabling memory-growth is not expected to make much of an impact, so we enable it for all builds |
| 23 | +# Since tihs is a library and not a standalone executable, we don't want to catch unhandled Node process exceptions |
| 24 | +# So, we do : `NODEJS_CATCH_EXIT=0`, which fixes issue: https://github.com/kripken/sql.js/issues/173 and https://github.com/kripken/sql.js/issues/262 |
| 25 | +EMFLAGS = \ |
| 26 | + --memory-init-file 0 \ |
| 27 | + -s RESERVED_FUNCTION_POINTERS=64 \ |
| 28 | + -s EXPORTED_FUNCTIONS=@src/exported_functions.json \ |
| 29 | + -s EXTRA_EXPORTED_RUNTIME_METHODS=@src/exported_runtime_methods.json \ |
| 30 | + -s SINGLE_FILE=0 \ |
| 31 | + -s NODEJS_CATCH_EXIT=0 |
| 32 | + |
| 33 | +EMFLAGS_WASM = \ |
| 34 | + -s WASM=1 \ |
| 35 | + -s ALLOW_MEMORY_GROWTH=1 |
| 36 | + |
| 37 | +EMFLAGS_OPTIMIZED= \ |
| 38 | + -s INLINING_LIMIT=50 \ |
| 39 | + -O3 \ |
| 40 | + --closure 1 |
| 41 | + |
| 42 | +EMFLAGS_DEBUG = \ |
| 43 | + -s INLINING_LIMIT=10 \ |
| 44 | + -O1 |
| 45 | + |
| 46 | +BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc |
| 47 | +OUTPUT_WRAPPER_FILES = src/shell-pre.js src/shell-post.js |
| 48 | + |
| 49 | +all: optimized debug worker |
| 50 | + |
| 51 | +.PHONY: debug |
| 52 | +debug: dist/sql-asm-debug.js dist/sql-wasm-debug.js |
| 53 | + |
| 54 | +dist/sql-asm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) out/api.js src/exported_functions.json src/exported_runtime_methods.json |
| 55 | + $(EMCC) $(EMFLAGS) $(EMFLAGS_DEBUG) -s WASM=0 $(BITCODE_FILES) --pre-js out/api.js -o $@ |
| 56 | + mv $@ out/tmp-raw.js |
| 57 | + cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@ |
| 58 | + rm out/tmp-raw.js |
| 59 | + |
| 60 | +dist/sql-wasm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) out/api.js src/exported_functions.json src/exported_runtime_methods.json |
| 61 | + $(EMCC) $(EMFLAGS) $(EMFLAGS_DEBUG) $(EMFLAGS_WASM) $(BITCODE_FILES) --pre-js out/api.js -o $@ |
| 62 | + mv $@ out/tmp-raw.js |
| 63 | + cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@ |
| 64 | + rm out/tmp-raw.js |
| 65 | + |
| 66 | +.PHONY: optimized |
| 67 | +optimized: dist/sql-asm.js dist/sql-wasm.js dist/sql-asm-memory-growth.js |
| 68 | + |
| 69 | +dist/sql-asm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) out/api.js src/exported_functions.json src/exported_runtime_methods.json |
| 70 | + $(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) -s WASM=0 $(BITCODE_FILES) --pre-js out/api.js -o $@ |
| 71 | + mv $@ out/tmp-raw.js |
| 72 | + cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@ |
| 73 | + rm out/tmp-raw.js |
| 74 | + |
| 75 | +dist/sql-wasm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) out/api.js src/exported_functions.json src/exported_runtime_methods.json |
| 76 | + $(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) $(EMFLAGS_WASM) $(BITCODE_FILES) --pre-js out/api.js -o $@ |
| 77 | + mv $@ out/tmp-raw.js |
| 78 | + cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@ |
| 79 | + rm out/tmp-raw.js |
| 80 | + |
| 81 | +dist/sql-asm-memory-growth.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) out/api.js src/exported_functions.json src/exported_runtime_methods.json |
| 82 | + $(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) -s WASM=0 -s ALLOW_MEMORY_GROWTH=1 $(BITCODE_FILES) --pre-js out/api.js -o $@ |
| 83 | + mv $@ out/tmp-raw.js |
| 84 | + cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@ |
| 85 | + rm out/tmp-raw.js |
19 | 86 |
|
20 |
| -js/sql%.js: js/shell-pre.js js/sql%-raw.js js/shell-post.js |
21 |
| - cat $^ > $@ |
22 | 87 |
|
23 |
| -js/sql%-raw.js: c/sqlite3.bc c/extension-functions.bc js/api.js exported_functions |
24 |
| - $(EMCC) $(EMFLAGS) -s EXPORTED_FUNCTIONS=@exported_functions -s EXTRA_EXPORTED_RUNTIME_METHODS=@exported_runtime_methods c/extension-functions.bc c/sqlite3.bc --post-js js/api.js -o $@ ;\ |
| 88 | +# Web worker API |
| 89 | +.PHONY: worker |
| 90 | +worker: dist/worker.sql-asm.js dist/worker.sql-asm-debug.js dist/worker.sql-wasm.js dist/worker.sql-wasm-debug.js |
25 | 91 |
|
26 |
| -js/api.js: coffee/api.coffee coffee/exports.coffee coffee/api-data.coffee |
| 92 | +out/worker.js: src/worker.coffee |
27 | 93 | cat $^ | coffee --bare --compile --stdio > $@
|
28 | 94 |
|
29 |
| -# Web worker API |
30 |
| -worker: js/worker.sql.js |
31 |
| -js/worker.js: coffee/worker.coffee |
32 |
| - cat $^ | coffee --bare --compile --stdio > $@ |
| 95 | +dist/worker.sql-asm.js: dist/sql-asm.js out/worker.js |
| 96 | + cat $^ > $@ |
33 | 97 |
|
34 |
| -js/worker.sql.js: js/sql.js js/worker.js |
| 98 | +dist/worker.sql-asm-debug.js: dist/sql-asm-debug.js out/worker.js |
35 | 99 | cat $^ > $@
|
36 | 100 |
|
37 |
| -c/sqlite3.bc: c/sqlite3.c |
| 101 | +dist/worker.sql-wasm.js: dist/sql-wasm.js out/worker.js |
| 102 | + cat $^ > $@ |
| 103 | + |
| 104 | +dist/worker.sql-wasm-debug.js: dist/sql-wasm-debug.js out/worker.js |
| 105 | + cat $^ > $@ |
| 106 | + |
| 107 | +# Building it this way gets us a wrapper that _knows_ it's in worker mode, which is nice. |
| 108 | +# However, since we can't tell emcc that we don't need the wasm generated, and just want the wrapper, we have to pay to have the .wasm generated |
| 109 | +# even though we would have already generated it with our sql-wasm.js target above. |
| 110 | +# This would be made easier if this is implemented: https://github.com/emscripten-core/emscripten/issues/8506 |
| 111 | +# dist/worker.sql-wasm.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) out/api.js out/worker.js src/exported_functions.json src/exported_runtime_methods.json dist/sql-wasm-debug.wasm |
| 112 | +# $(EMCC) $(EMFLAGS) $(EMFLAGS_OPTIMIZED) -s ENVIRONMENT=worker -s $(EMFLAGS_WASM) $(BITCODE_FILES) --pre-js out/api.js -o out/sql-wasm.js |
| 113 | +# mv out/sql-wasm.js out/tmp-raw.js |
| 114 | +# cat src/shell-pre.js out/tmp-raw.js src/shell-post.js out/worker.js > $@ |
| 115 | +# #mv out/sql-wasm.wasm dist/sql-wasm.wasm |
| 116 | +# rm out/tmp-raw.js |
| 117 | + |
| 118 | +# dist/worker.sql-wasm-debug.js: $(BITCODE_FILES) $(OUTPUT_WRAPPER_FILES) out/api.js out/worker.js src/exported_functions.json src/exported_runtime_methods.json dist/sql-wasm-debug.wasm |
| 119 | +# $(EMCC) -s ENVIRONMENT=worker $(EMFLAGS) $(EMFLAGS_DEBUG) -s ENVIRONMENT=worker -s WASM_BINARY_FILE=sql-wasm-foo.debug $(EMFLAGS_WASM) $(BITCODE_FILES) --pre-js out/api.js -o out/sql-wasm-debug.js |
| 120 | +# mv out/sql-wasm-debug.js out/tmp-raw.js |
| 121 | +# cat src/shell-pre.js out/tmp-raw.js src/shell-post.js out/worker.js > $@ |
| 122 | +# #mv out/sql-wasm-debug.wasm dist/sql-wasm-debug.wasm |
| 123 | +# rm out/tmp-raw.js |
| 124 | + |
| 125 | +out/api.js: src/output-pre.js src/api.coffee src/exports.coffee src/api-data.coffee src/output-post.js |
| 126 | + cat src/api.coffee src/exports.coffee src/api-data.coffee | coffee --bare --compile --stdio > $@ |
| 127 | + cat src/output-pre.js $@ src/output-post.js > out/api-wrapped.js |
| 128 | + mv out/api-wrapped.js $@ |
| 129 | + |
| 130 | +out/sqlite3.bc: sqlite-src/$(SQLITE_AMALGAMATION) |
38 | 131 | # Generate llvm bitcode
|
39 |
| - $(EMCC) $(CFLAGS) c/sqlite3.c -o c/sqlite3.bc |
| 132 | + $(EMCC) $(CFLAGS) sqlite-src/$(SQLITE_AMALGAMATION)/sqlite3.c -o $@ |
| 133 | + |
| 134 | +out/extension-functions.bc: sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS) |
| 135 | + $(EMCC) $(CFLAGS) -s LINKABLE=1 sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@ |
| 136 | + |
| 137 | +# TODO: This target appears to be unused. If we re-instatate it, we'll need to add more files inside of the JS folder |
| 138 | +# module.tar.gz: test package.json AUTHORS README.md dist/sql-asm.js |
| 139 | +# tar --create --gzip $^ > $@ |
| 140 | + |
| 141 | +## cache |
| 142 | + |
| 143 | +.PHONY: clean-cache |
| 144 | +clean-cache: |
| 145 | + rm -rf cache |
| 146 | + |
| 147 | +cache/$(SQLITE_AMALGAMATION).zip: |
| 148 | + mkdir -p cache |
| 149 | + curl -LsSf '$(SQLITE_AMALGAMATION_ZIP_URL)' -o $@ |
| 150 | + |
| 151 | +cache/$(EXTENSION_FUNCTIONS): |
| 152 | + mkdir -p cache |
| 153 | + curl -LsSf '$(EXTENSION_FUNCTIONS_URL)' -o $@ |
| 154 | + |
| 155 | +## sqlite-src |
| 156 | + |
| 157 | +.PHONY: clean-sqlite-src |
| 158 | +clean-sqlite-src: |
| 159 | + rm -rf sqlite |
| 160 | + |
| 161 | +.PHONY: sqlite-src |
| 162 | +sqlite-src: sqlite-src/$(SQLITE_AMALGAMATION) sqlite-src/$(EXTENSION_FUNCTIONS) |
| 163 | + |
| 164 | +sqlite-src/$(SQLITE_AMALGAMATION): cache/$(SQLITE_AMALGAMATION).zip |
| 165 | + mkdir -p sqlite-src |
| 166 | + echo '$(SQLITE_AMALGAMATION_ZIP_SHA1) ./cache/$(SQLITE_AMALGAMATION).zip' > cache/check.txt |
| 167 | + sha1sum -c cache/check.txt |
| 168 | + rm -rf $@ |
| 169 | + unzip 'cache/$(SQLITE_AMALGAMATION).zip' -d sqlite-src/ |
| 170 | + touch $@ |
40 | 171 |
|
41 |
| -c/extension-functions.bc: c/extension-functions.c |
42 |
| - $(EMCC) $(CFLAGS) -s LINKABLE=1 c/extension-functions.c -o c/extension-functions.bc |
| 172 | +sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS): cache/$(EXTENSION_FUNCTIONS) |
| 173 | + mkdir -p sqlite-src |
| 174 | + echo '$(EXTENSION_FUNCTIONS_SHA1) ./cache/$(EXTENSION_FUNCTIONS)' > cache/check.txt |
| 175 | + sha1sum -c cache/check.txt |
| 176 | + cp 'cache/$(EXTENSION_FUNCTIONS)' $@ |
43 | 177 |
|
44 |
| -module.tar.gz: test package.json AUTHORS README.md js/sql.js |
45 |
| - tar --create --gzip $^ > $@ |
46 | 178 |
|
47 |
| -clean: |
48 |
| - rm -rf js/sql.js js/api.js js/sql*-raw.js js/worker.sql.js js/worker.js js/sql-memory-growth.js c/sqlite3.bc c/extension-functions.bc |
| 179 | +.PHONY: clean |
| 180 | +clean: |
| 181 | + rm -rf out/* dist/* |
49 | 182 |
|
| 183 | +.PHONY: clean-all |
| 184 | +clean-all: |
| 185 | + rm -f out/* dist/* cache/* |
| 186 | + rm -rf sqlite-src/ |
50 | 187 |
|
0 commit comments