Skip to content

Commit b5ef6da

Browse files
committed
wasm: Fix Webpack compatibility for browser use
Updating emsdk to v3.1.27 was necessary for emscripten-core/emscripten#17915, which allows using the same WASM build for both browser and nodejs envs.
1 parent d3c59d6 commit b5ef6da

File tree

9 files changed

+2427
-8
lines changed

9 files changed

+2427
-8
lines changed

contrib/bullseye_deps.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ unzip -qq ${NDK_FILENAME}
2222
rm ${NDK_FILENAME}
2323
git clone https://github.com/emscripten-core/emsdk
2424
cd emsdk
25-
./emsdk install 3.1.20
26-
./emsdk activate 3.1.20
25+
./emsdk install 3.1.27
26+
./emsdk activate 3.1.27
2727
source ./emsdk_env.sh
2828

2929
apt-get remove --purge curl unzip -yqq

src/wasm_package/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
libwally_wasm
2+
node_modules

src/wasm_package/browser/assert.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Minimal shim for nodejs's assert module, for the browser
2+
// For some reason, this doesn't work with the https://github.com/browserify/commonjs-assert shim,
3+
// which causes the webpack bundle to hang when attempting to import it.
4+
5+
export default function assert(val, err='assertion failed') {
6+
if (!val) throw err
7+
}

src/wasm_package/build.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ set -xeo pipefail
1010
# Build WASM (Elements is always enabled)
1111
(cd ../.. && ./tools/build_wasm.sh --enable-elements)
1212
mkdir -p libwally_wasm && cp ../../wally_dist/wallycore.{js,wasm} libwally_wasm/
13-
# Rename to force commonjs mode. See https://github.com/emscripten-core/emscripten/pull/17451
14-
mv libwally_wasm/wallycore.js libwally_wasm/wallycore.cjs
13+
touch libwally_wasm/index # necessary for webpack to work (fixes "Can't resolve './' in 'wasm_package/libwally_wasm'")
14+
15+
# Build browser bundle (to dist/wallycore.bundle.js, see webpack.config.js)
16+
webpack --mode production

src/wasm_package/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from 'assert'
2-
import InitWallyModule from './libwally_wasm/wallycore.cjs'
2+
import InitWallyModule from './libwally_wasm/wallycore.js'
33
import { WALLY_OK, WALLY_ERROR, WALLY_EINVAL, WALLY_ENOMEM } from './const.js'
44

55
// Initialize the underlying WASM module and expose it publicly

0 commit comments

Comments
 (0)