You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run wasm-bindgen when its marker is present (cargo/rustc-driven flow)
When cargo/rustc drives the build with emcc as the linker, the linked wasm
carries a __wasm_bindgen_emscripten_marker custom section and rustc supplies
the exact -sEXPORTED_FUNCTIONS. Detect that marker in phase_post_link and run
wasm-bindgen as a post-link step, the same way the -sWASM_BINDGEN staticlib
flow does, without any export discovery.
This defines two clearly-separated modes:
- C++-driven (-sWASM_BINDGEN set): the user owns EXPORTED_FUNCTIONS; their
exports are left untouched.
- marker-driven (set not passed, marker detected): rustc's EXPORTED_FUNCTIONS is
the raw wasm export set the generated glue reaches by name (the method shims,
the __wbindgen_* runtime, the marker, main), not a user-facing API. The
user-facing API is exactly what wasm-bindgen self-registers via its library
(wasm-bindgen 0.2.126), so the rustc-supplied set is dropped from every
user-export layer: the ESM wrapper (WASM_ESM_INTEGRATION, via
user_requested_exports) and the factory Module attachment (MODULARIZE, via
EXPORTED_FUNCTIONS / should_export), and the keepalive wasm exports are not
surfaced. main still runs automatically on init, matching the emscripten
idiom, even though _main is not exported.
Both output modes then expose only the clean API (e.g. a `Greeter` class).
- Strip the placeholder symbols wasm-bindgen consumes (__wbindgen_describe*,
__externref_*, ...) from EXPORTED_FUNCTIONS so they aren't reported as
undefined exports.
- Wire imported JS: feed library_bindgen.extern-pre.js as extern-pre-js and
copy the snippets/ dir next to the output so relative imports resolve.
- Forward the JS library symbols that get a top-level export
(MODULARIZE=instance) so the WASM_ESM_INTEGRATION wrapper re-exports them.
- Under WASM_ESM_INTEGRATION && WASM_BINDGEN, provide wasmExports via a
namespace import of the wasm so the glue's by-name access works.
Add an end-to-end test (test/rust/bindgen_greeter) parameterized over the ESM
and factory output modes, and install a pinned wasm-bindgen-cli alongside rust
in CI so the flow is always exercised.
0 commit comments