diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d7a5bff78..ddee97372 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -139,13 +139,14 @@ build_wally_release_files: - mv release wallycore-android-jni - tar czf wally_dist/wallycore-android-jni.tar.gz --remove-files wallycore-android-jni - source /opt/emsdk/emsdk_env.sh - - tools/build_wasm.sh + - EMCC_OPTIONS="-s EXPORT_ES6=1 -s MODULARIZE=1" tools/build_wasm.sh + - cp contrib/wally_js_example.html dist/wallycore.html - cd dist - - tar czf wallycore-wasm.tar.gz --remove-files wallycore.html wallycore.js wallycore.wasm + - tar czf ../wally_dist/wallycore-wasm.tar.gz --remove-files wallycore.html wallycore.js wallycore.wasm - cd .. - - EXPORTED_FUNCTIONS="['_malloc','_free','_wally_init','_wally_asset_value_commitment','_wally_asset_generator_from_bytes']" tools/build_wasm.sh --no-modularize + - EMCC_OPTIONS="-s MODULARIZE=1" EXPORTED_FUNCTIONS="['_malloc','_free','_wally_init','_wally_asset_value_commitment','_wally_asset_generator_from_bytes']" tools/build_wasm.sh - cd dist - - tar czf esplora-wasm.tar.gz --remove-files wallycore.html wallycore.js wallycore.wasm + - tar czf ../wally_dist/esplora-wasm.tar.gz --remove-files wallycore.js wallycore.wasm - cd .. - sphinx-build -b html -a -c docs/source docs/source docs/build/html - cd docs/build diff --git a/README.md b/README.md index cd75239ae..96042dd5b 100644 --- a/README.md +++ b/README.md @@ -191,18 +191,21 @@ $ source $HOME/emsdk/emsdk_env.sh # Optionally set the list of wally functions to export to wasm (default: all) $ export EXPORTED_FUNCTIONS="['_malloc','_free','_wally_init','_wally_cleanup',...]" +# Optionally set emcc options, e.g. to build as an ES6 module: +$ export EMCC_OPTIONS="-s EXPORT_ES6=1 -s MODULARIZE=1" + # Build $ ./tools/build_wasm.sh [--disable-elements] ``` Note that emsdk v3.1.27 or later is required. -The script `tools/build_wasm.sh` builds the `wallycore.html` example as well -as the required `wallycore.js` and `wallycore.wasm` files, which can be used -as an example for your own WebAssembly projects. +The file `contrib/wally_js_example.html` is an example page using the +`wallycore.js` and `wallycore.wasm` files, which can be used as an example +for your own WebAssembly projects. -Open `wallycore.html` in a browser via a webserver like [nginx](https://www.nginx.com/) -or `python2 -m SimpleHTTPServer 8000` to run the example. +Open `wally_js_example.html` in a browser via a webserver like [nginx](https://www.nginx.com/) +or `python3 -m http.server` to run the example. ## Cleaning diff --git a/contrib/shell_minimal.html b/contrib/shell_minimal.html deleted file mode 100644 index 0275a724e..000000000 --- a/contrib/shell_minimal.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - Wallycore shell - - - - - - {{{ SCRIPT }}} - - diff --git a/contrib/wally_js_example.html b/contrib/wally_js_example.html new file mode 100644 index 000000000..5b5c4a4d7 --- /dev/null +++ b/contrib/wally_js_example.html @@ -0,0 +1,56 @@ + + + + + + Wallycore JS Example + + + + + + + + + diff --git a/tools/build_wasm.sh b/tools/build_wasm.sh index ef09b4f4d..6acc72e9f 100755 --- a/tools/build_wasm.sh +++ b/tools/build_wasm.sh @@ -7,10 +7,6 @@ if [ "$1" = "--disable-elements" ]; then DISABLE_ELEMENTS="--disable-elements --disable-elements-abi" shift fi -MODULARIZE="-s MODULARIZE=1" -if [ "$1" = "--no-modularize" ]; then - MODULARIZE="" -fi num_jobs=4 if [ -f /proc/cpuinfo ]; then @@ -34,9 +30,9 @@ export CFLAGS="-fno-stack-protector" emconfigure ./configure --build=$HOST_OS ac_cv_c_bigendian=no --disable-swig-python --disable-swig-java $DISABLE_ELEMENTS --disable-tests --enable-export-all --enable-wasm-interface emmake make -j $num_jobs -EMCC_OPTIONS="$EMCC_OPTIONS -s EXPORT_ES6=1 ${MODULARIZE} -s EXPORT_NAME=InitWally -s WASM_BIGINT" +EMCC_OPTIONS="$EMCC_OPTIONS -s EXPORT_NAME=InitWally -s WASM_BIGINT" : ${OPTIMIZATION_LEVEL:=3} -: ${EXPORTED_RUNTIME_METHODS:='cwrap,ccall,malloc,getValue,UTF8ToString'} +: ${EXPORTED_RUNTIME_METHODS:='cwrap,ccall,getValue,UTF8ToString'} # Get the list of functions to export source ./tools/wasm_exports.sh @@ -48,5 +44,4 @@ emcc -O$OPTIMIZATION_LEVEL \ -s FILESYSTEM=0 \ $EMCC_OPTIONS \ ./src/.libs/*.o src/secp256k1/src/*.o src/ccan/ccan/*/.libs/*.o src/ccan/ccan/*/*/.libs/*.o \ - -o dist/wallycore.html \ - --shell-file contrib/shell_minimal.html + -o dist/wallycore.js