Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[embind] Export embind exports as ESM exports for MODULARIZE=instance. #23404

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

brendandahl
Copy link
Collaborator

Using the embind AOT mode we can generate a list of all the embind bindings and export them as ES module exports.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear this only works in AOT mode? What happens in non-AOT mode?

src/embind/embind_gen.js Outdated Show resolved Hide resolved
out.push('}\n');
let updateExports = '() => {\n';
for (const publicSymbol of publicSymbols) {
updateExports += `__exp_${publicSymbol} = Module['${publicSymbol}'];\n`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So these extra assignment happen during onInit in the final output module? They don't happen at AOT time, right? Or do they happen both at AOT time and at runtime?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They happen just in the final output at runtime.

@brendandahl
Copy link
Collaborator Author

To be clear this only works in AOT mode? What happens in non-AOT mode?

In non-aot mode, the user would have to get the bindings off the module object from init. e.g.

const module = await init();
module.foo();

We could require that modularize instance + embind only works with embind_aot, or enable embind_aot in instance mode by default. I lean towards the latter.

$InvokerFunctions: '<<< EMBIND_AOT_OUTPUT >>>',
$InvokerFunctions: '<<< EMBIND_AOT_INVOKERS >>>',
#if MODULARIZE == 'instance'
$embindUpdateExports: '<<< EMBIND_AOT_UPDATE_EXPORTS >>>',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding some comments here about that embindUpdateExports does and when?

Using the embind AOT mode we can generate a list of all the embind
bindings and export them as ES module exports.
@brendandahl brendandahl force-pushed the modularize-instance-embind branch from f66d559 to 28d8a57 Compare January 22, 2025 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants