From 7858b58b352cac755f3564fb3886d825824bd3f0 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 23 May 2024 15:42:35 +0200 Subject: [PATCH] emscripten: create JS-only builds --- dist-build/emscripten.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/dist-build/emscripten.sh b/dist-build/emscripten.sh index 53883aae..6d5d15ae 100755 --- a/dist-build/emscripten.sh +++ b/dist-build/emscripten.sh @@ -82,7 +82,28 @@ if [ "$DIST" = yes ]; then "${PREFIX}/lib/libsodium.a" -o "${outFile}" || exit 1 } emmake make $MAKE_FLAGS install || exit 1 - emccLibsodium "${PREFIX}/lib/libsodium.asm.tmp.js" -Oz -s WASM=0 $LDFLAGS_JS + + # JS-only build + emccLibsodium "${PREFIX}/lib/libsodium.tmp.mjs" -Oz -s WASM=0 $LDFLAGS_JS + + cat >"${PREFIX}/lib/libsodium-jsonly.mjs" <<-EOM +$(grep -Fv "export default Module" "${PREFIX}/lib/libsodium.tmp.mjs") + + Module.print = function(what) { + typeof(console) !== 'undefined' && console.log(what); + } + Module.printErr = function(what) { + typeof(console) !== 'undefined' && console.warn(what); + } + Module['getRandomValue'] = undefined; + + export default Module; +EOM + + rm "${PREFIX}/lib/libsodium.tmp.mjs" + + # Hybrid JS + WASM build + emccLibsodium "${PREFIX}/lib/libsodium.tmp.js" -Oz -s WASM=0 $LDFLAGS_JS emccLibsodium "${PREFIX}/lib/libsodium.wasm.tmp.js" -O3 -s WASM=1 -s EVAL_CTORS=1 -s INITIAL_MEMORY=${WASM_INITIAL_MEMORY} cat >"${PREFIX}/lib/libsodium.js" <<-EOM @@ -134,7 +155,7 @@ if [ "$DIST" = yes ]; then resolve(); }; - $(sed "s|use asm||g" "${PREFIX}/lib/libsodium.asm.tmp.js") + $(sed "s|use asm||g" "${PREFIX}/lib/libsodium.tmp.js") }); }; $(cat "${PREFIX}/lib/libsodium.wasm.tmp.js") @@ -143,7 +164,7 @@ if [ "$DIST" = yes ]; then }); EOM - rm "${PREFIX}/lib/libsodium.asm.tmp.js" "${PREFIX}/lib/libsodium.wasm.tmp.js" + rm "${PREFIX}/lib/libsodium.tmp.js" "${PREFIX}/lib/libsodium.wasm.tmp.js" touch -r "${PREFIX}/lib/libsodium.js" "$DONE_FILE" ls -l "${PREFIX}/lib/libsodium.js" exit 0