From c4534d1d9e66d0c55deaf1b16f803da750ebdaf1 Mon Sep 17 00:00:00 2001 From: dapplion Date: Wed, 28 Oct 2020 17:33:47 +0100 Subject: [PATCH] Inline wasm file for easier cross-platform setup With `MODULARIZE=1` set, we instead emit the code wrapped in a function that returns a promise. The promise is resolved with the module instance when it is safe to run the compiled code, similar to the `onRuntimeInitialized` callback. You do not need to use the `onRuntimeInitialized` callback when using `MODULARIZE`. ``` EMCC_OPT+=-s MODULARIZE=1 ``` The default name of the function is `Module`, but can be changed using the `EXPORT_NAME` The factory function accepts 1 parameter, an object with default values the instance ``` EMCC_OPT+=-s EXPORT_NAME='createBlsModule' ``` Export using an ES6 Module export rather than a UMD export Disable import feature 'import.meta.url', not supported on old browsers / toolchains ``` EMCC_OPT+=-s EXPORT_ES6=1 -s USE_ES6_IMPORT_META=0 ``` STRICT_JS = 1, adds "use strict;" to generated JS ``` EMCC_OPT+=-s STRICT_JS=1 ``` SINGLE_FILE=1, embeds all subresources in the emitted file as base64 string literals. Embedded subresources may include (but aren't limited to) wasm, asm.js, and static memory initialization code. ``` EMCC_OPT+=-s SINGLE_FILE=1 ``` Pass -s MINIFY_HTML=0 to explicitly choose to disable HTML minification altogether ``` EMCC_OPT+=-s MINIFY_HTML=0 ``` Do not minify target javascript file (only a +0.8% size increase) ``` EMCC_OPT+=--minify 0 ``` --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 82d368c0..9463cc7e 100644 --- a/Makefile +++ b/Makefile @@ -143,7 +143,13 @@ test_go: EMCC_OPT=-I./include -I./src -I../mcl/include -I./ -Wall -Wextra EMCC_OPT+=-O3 -DNDEBUG -EMCC_OPT+=-s WASM=1 -s NO_EXIT_RUNTIME=1 -s NODEJS_CATCH_EXIT=0 -s NODEJS_CATCH_REJECTION=0 -s MODULARIZE=1 #-s ASSERTIONS=1 +EMCC_OPT+=-s WASM=1 -s NO_EXIT_RUNTIME=1 -s NODEJS_CATCH_EXIT=0 -s NODEJS_CATCH_REJECTION=0 #-s ASSERTIONS=1 +EMCC_OPT+=-s MODULARIZE=1 +EMCC_OPT+=-s EXPORT_NAME='createBlsModule' +EMCC_OPT+=-s STRICT_JS=1 +EMCC_OPT+=-s SINGLE_FILE=1 +EMCC_OPT+=-s MINIFY_HTML=0 +EMCC_OPT+=--minify 0 EMCC_OPT+=-DCYBOZU_MINIMUM_EXCEPTION EMCC_OPT+=-s ABORTING_MALLOC=0 JS_DEP=src/bls_c384.cpp ../mcl/src/fp.cpp Makefile