From 899d9d9b001f1199a34b51a72e6acb29fe04b1bb Mon Sep 17 00:00:00 2001 From: funkpower Date: Fri, 18 Sep 2026 14:56:15 -0400 Subject: [PATCH] check wasm-bindgen against the version Cargo.lock pins The generator refuses a module built by a different version, and the error it gives names two versions without saying which is which. Reading the wanted one out of the lock file also fixes the install hint, which had been printing the requirement from Cargo.toml: "0.2", which is not a version anything can be installed at. --- npm/build.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/npm/build.sh b/npm/build.sh index 7ac1aa8..e8ccff3 100755 --- a/npm/build.sh +++ b/npm/build.sh @@ -17,9 +17,19 @@ version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)" bindgen="${WASM_BINDGEN:-wasm-bindgen}" dist="npm/dist" +# The generator has to be the exact version the crate was built against, or it +# refuses the module. Cargo.lock is where that version actually is. +want="$(awk '/^name = "wasm-bindgen"$/{getline; gsub(/[",]/,""); print $3; exit}' Cargo.lock)" command -v "$bindgen" >/dev/null || { - echo "wasm-bindgen is not on PATH. cargo install wasm-bindgen-cli --version \ -$(sed -n 's/^wasm-bindgen = { version = "\(.*\)".*/\1/p' Cargo.toml)" >&2 + echo "wasm-bindgen is not on PATH." >&2 + echo " cargo install wasm-bindgen-cli --version $want" >&2 + echo "or take the prebuilt one from" >&2 + echo " https://github.com/rustwasm/wasm-bindgen/releases/tag/$want" >&2 + exit 1 +} +have="$("$bindgen" --version | awk '{print $2}')" +[ "$have" = "$want" ] || { + echo "wasm-bindgen $have, but Cargo.lock pins $want" >&2 exit 1 }