Support JS libraries self-registering their exports with visibility attributes - #27436
Conversation
|
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 |
|
I've updated this following the suggestion here for JS libraries to use the __export and __force symbol attributes:
The attributes are compile-time metadata and are not emitted. We no longer mutate or forward Coverage includes legacy modules, instance ESM, WASM_ESM_INTEGRATION, and O3/meta-DCE. |
sbc100
left a comment
There was a problem hiding this comment.
This is looking much better now! Thanks for being flexible.
sbc100
left a comment
There was a problem hiding this comment.
lgtm % comment.
Can you add a ChangeLog entry for this?
281ec85 to
bc3d67c
Compare
|
Changelog added now as well. |
|
6.0.6 is about to be released in next few minutes/hours, so maybe we hold off landing this until after that happens in order to avoid having to move the changelog entry. See emscripten-core/emsdk#1774 |
|
OK, 6.0.6 is now releases. Please rebase. |
…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.
bc3d67c to
ab22aee
Compare
|
Ok the Changelog entry is now updated to 6.0.7. |
ab22aee to
d1fb203
Compare
This implements support for JS libraries declaring their own public exports using per-symbol attributes, split out from #27208 as requested in review there.
The attributes separate symbol inclusion from export visibility:
__export: trueexports the symbol if it is otherwise included.__force: trueincludes the symbol even when nothing references it, without exporting it, analogous toDEFAULT_LIBRARY_FUNCS_TO_INCLUDE.This allows binding layers such as wasm-bindgen to define a public JS API surface distinct from the wasm export names, including exported classes and namespaces:
The attributes are consumed as JS library compile-time metadata and do not appear in generated output. The JS compiler forwards only the symbols actually emitted through
extraExports, allowing theWASM_ESM_INTEGRATIONwrapper to re-export them without mutating or returning the globalEXPORTED_FUNCTIONSsetting. Decorated exports are also retained through meta-DCE.Test coverage verifies the independent attribute semantics under legacy modularized output,
MODULARIZE=instance,WASM_ESM_INTEGRATION, and optimized-O3builds, together with decorator validation.Made with AI assistance under my review