From adb788cd5b54f5a333cd53c5ab42e60b903ca068 Mon Sep 17 00:00:00 2001 From: Taylor Brown Date: Wed, 1 Jun 2022 02:54:27 -0500 Subject: [PATCH] Use -Oz instead of -O2 to reduce compiled asset sizes significantly (#479) * Run `npm ci` automatically after the devcontainer is created. This reduces the chance that another dev will forget to do this. * Upgrade to Emscripten 2.0.29 Changes required: * Defined EM_NODE_JS environment variable to get rid of a warning that appears if the NODE environment variable is set, but EM_NODE_JS is not. * EXTRA_EXPORTED_RUNTIME_METHODS is now EXPORTED_RUNTIME_METHODS * No longer pass the `-s LINKABLE=1` option to emcc when compiling. (This is a linktime setting and emcc warns about not using a linktime setting when compiling now). * Upgrade to Sqlite 3.36.0 Sqlite now publishes the hash as a SHA3 instead of SHA1, necessitating the installation of the sha3sum command. * Use -Oz optimizations instead of -O2 This reduces most compilation output by around 50% --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index c5254629..de7cf0c4 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,8 @@ EXTENSION_FUNCTIONS_SHA1 = c68fa706d6d9ff98608044c00212473f9c14892f EMCC=emcc -CFLAGS = \ - -O2 \ +SQLITE_COMPILATION_FLAGS = \ + -Oz \ -DSQLITE_OMIT_LOAD_EXTENSION \ -DSQLITE_DISABLE_LFS \ -DSQLITE_ENABLE_FTS3 \ @@ -53,7 +53,7 @@ EMFLAGS_WASM = \ EMFLAGS_OPTIMIZED= \ -s INLINING_LIMIT=50 \ - -O3 \ + -Oz \ -flto \ --closure 1 @@ -148,13 +148,13 @@ dist/worker.sql-wasm-debug.js: dist/sql-wasm-debug.js src/worker.js out/sqlite3.bc: sqlite-src/$(SQLITE_AMALGAMATION) mkdir -p out # Generate llvm bitcode - $(EMCC) $(CFLAGS) -c sqlite-src/$(SQLITE_AMALGAMATION)/sqlite3.c -o $@ + $(EMCC) $(SQLITE_COMPILATION_FLAGS) -c sqlite-src/$(SQLITE_AMALGAMATION)/sqlite3.c -o $@ # Since the extension-functions.c includes other headers in the sqlite_amalgamation, we declare that this depends on more than just extension-functions.c out/extension-functions.bc: sqlite-src/$(SQLITE_AMALGAMATION) mkdir -p out # Generate llvm bitcode - $(EMCC) $(CFLAGS) -c sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@ + $(EMCC) $(SQLITE_COMPILATION_FLAGS) -c sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@ # TODO: This target appears to be unused. If we re-instatate it, we'll need to add more files inside of the JS folder # module.tar.gz: test package.json AUTHORS README.md dist/sql-asm.js