diff --git a/README.md b/README.md index d2cb943..6778449 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ cd libcurl.js/client ``` Make sure you have emscripten, git, and the various C build tools installed. The build script will generate `client/out/libcurl.js` as well as `client/out/libcurl_module.mjs`, which is an ES6 module. +You can supply the following arguments to the build script to control the build: +- `release` - Use all optimizations. +- `single_file` - Include the WASM binary in the outputted JS using base64. + ## Javascript API: ### Importing the Library: diff --git a/client/build.sh b/client/build.sh index d5743e1..4c1d452 100755 --- a/client/build.sh +++ b/client/build.sh @@ -20,13 +20,18 @@ RUNTIME_METHODS="addFunction,removeFunction,allocate,ALLOC_NORMAL" COMPILER_OPTIONS="-o $MODULE_FILE -lcurl -lssl -lcrypto -lcjson -lz -lbrotlidec -lbrotlicommon -lnghttp2 -I $INCLUDE_DIR -L $LIB_DIR" EMSCRIPTEN_OPTIONS="-lwebsocket.js -sASSERTIONS=1 -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS" -if [ "$1" = "release" ]; then +if [[ "$*" == *"release"* ]]; then COMPILER_OPTIONS="-Oz -flto $COMPILER_OPTIONS" - #EMSCRIPTEN_OPTIONS="-sSINGLE_FILE $EMSCRIPTEN_OPTIONS" + echo "note: building with release optimizations" else COMPILER_OPTIONS="$COMPILER_OPTIONS --profiling" fi +if [[ "$*" == *"single_file"* ]]; then + EMSCRIPTEN_OPTIONS="-sSINGLE_FILE $EMSCRIPTEN_OPTIONS" + echo "note: building as a single js file" +fi + #ensure deps are compiled tools/all_deps.sh tools/generate_cert.sh @@ -39,6 +44,7 @@ mkdir -p out COMPILE_CMD="emcc main.c $COMPILER_OPTIONS $EMSCRIPTEN_OPTIONS" echo $COMPILE_CMD $COMPILE_CMD +mv $COMPILED_FILE $WASM_FILE || true #merge compiled emscripten module and wrapper code cp $WRAPPER_SOURCE $OUT_FILE diff --git a/client/fragments/load_later.js b/client/fragments/load_later.js index 9412bd4..79087a1 100644 --- a/client/fragments/load_later.js +++ b/client/fragments/load_later.js @@ -3,6 +3,11 @@ var asm ?= ?createWasm\(\); */ var asm = null; +/* REPLACE +var wasmExports ?= ?createWasm\(\); +*/ +var wasmExports = null; + /* DELETE run\(\);\n\n */