Support JS libraries self-registering their exports via EXPORTED_FUNCTIONS - #27436
Support JS libraries self-registering their exports via EXPORTED_FUNCTIONS#27436guybedford wants to merge 2 commits into
Conversation
…TIONS JS library code can already mutate the compile-time EXPORTED_FUNCTIONS set at library load time, which under MODULARIZE=instance causes jsifier to emit the symbol with an `export` declaration. This makes that flow fully work by forwarding the final EXPORTED_FUNCTIONS set back from the JS compiler so the linker can derive which JS library symbols were exported, and have the WASM_ESM_INTEGRATION wrapper re-export them. This is used by binding layers (e.g. wasm-bindgen) that define a public JS API surface distinct from the wasm export names, registering it from their generated JS library.
|
I think supporting something like this is a great idea but maybe we can bikeshed the design a little. How about limiting this to symbols actually defined in the JS library itself using symbol attributes. Perhaps something like: I don't love the In this scenario it would be possible to specify one of these without that other. If you specified If you specified I would hope that the information could all stay on the JS side, but if it needs to be plumbed back to python then it could then just be small |
This implements support for JS libraries adding their own symbols to
EXPORTED_FUNCTIONSat library load time, split out from #27208 as requested in review there.JS library code can already mutate the compile-time
EXPORTED_FUNCTIONSset (it is exposed to library code as aSet), which underMODULARIZE=instancecauses jsifier to emit the symbol with anexportdeclaration. What was missing is the linker knowing about those additions:EXPORTED_FUNCTIONSset is now forwarded back from the JS compiler inFORWARDED_DATA, so the linker can derive which JS library symbols were exported.WASM_ESM_INTEGRATIONwrapper re-exports those symbols from the support module.This is a requirement for wasm-bindgen's binding layers that define a public JS API surface distinct from the wasm export names (e.g. exported JS classes and namespaces), registering it from their generated JS library:
Test coverage is included in test_jslib.py for both
MODULARIZE=instanceandWASM_ESM_INTEGRATIONoutput modes, where theWASM_ESM_INTEGRATIONvariant fails without this change.Made with AI assistance under my review