From 0cbf3351d0bebd1daf84e403ae207978dfc28d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Tue, 19 May 2026 18:24:54 +0200 Subject: [PATCH] web: Fix MVP wasm build by disabling post-MVP features in C deps When the `jpegxr` feature is enabled, Microsoft's jxrlib (C) is compiled by cc-rs via clang. Clang's default `wasm32-unknown-unknown` target enables `reference-types` and `multivalue`, and those bits land in the produced .o files' `target_features` custom section. The linker merges those sections into the final wasm module, so even though the Rust side is built strictly MVP (`-Ctarget-cpu=mvp` plus rebuilt std via `-Zbuild-std`), the final module advertises `+reference-types` in `target_features`. wasm-bindgen 0.2.94+ then auto-enables externref transforms when it sees that bit and fails with `failed to find the __wbindgen_externref_table_dealloc function`, because the MVP-built Rust code does not contain that runtime symbol. Force clang into strict MVP via `CFLAGS_wasm32_unknown_unknown=-mno-reference-types -mno-multivalue` for the MVP build path. The Rust side already produces clean MVP metadata on current rustc, so no rustflags change is needed. Fixes #23751. Upstream tracking: wasm-bindgen/wasm-bindgen#4654. --- web/packages/core/tools/build_wasm.ts | 28 ++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/web/packages/core/tools/build_wasm.ts b/web/packages/core/tools/build_wasm.ts index 777ebd894c78..5ccba923a780 100644 --- a/web/packages/core/tools/build_wasm.ts +++ b/web/packages/core/tools/build_wasm.ts @@ -77,13 +77,27 @@ function cargoBuild({ if (process.env["CARGO_FLAGS"]) { args = args.concat(process.env["CARGO_FLAGS"].split(" ")); } - execFileSync("cargo", args, { - env: Object.assign(Object.assign({}, process.env), { - RUSTFLAGS: totalRustFlags, - RUSTC_BOOTSTRAP: extensions ? "0" : "1", - }), - stdio: "inherit", - }); + const env: NodeJS.ProcessEnv = { + ...process.env, + RUSTFLAGS: totalRustFlags, + RUSTC_BOOTSTRAP: extensions ? "0" : "1", + }; + + if (!extensions) { + // C dependencies (e.g. jpegxr's jxrlib) are compiled by cc-rs/clang, + // whose default wasm32 target enables post-MVP features like + // reference-types and multivalue. Those bits end up in the linked + // module's target_features section, which makes wasm-bindgen attempt + // externref transforms and then fail with "failed to find the + // __wbindgen_externref_table_dealloc function". Force clang to MVP too. + // See: https://github.com/ruffle-rs/ruffle/issues/23751 + // and: https://github.com/wasm-bindgen/wasm-bindgen/issues/4654 + env["CFLAGS_wasm32_unknown_unknown"] ??= ""; + env["CFLAGS_wasm32_unknown_unknown"] += + " -mno-reference-types -mno-multivalue"; + } + + execFileSync("cargo", args, { env, stdio: "inherit" }); } function buildWasm( profile: string,