Skip to content

[esm-integration] Export embind bindings. #24388

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

Merged
merged 2 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
raise Exception('do not run this file directly; do something like: test/runner')

from tools.shared import PIPE
from tools.shared import EMCC, EMAR, FILE_PACKAGER
from tools.shared import EMCC, EMAR, EMXX, FILE_PACKAGER
from tools.utils import WINDOWS, MACOS, LINUX, write_file, delete_file
from tools import shared, building, config, utils, webassembly
import common
Expand Down Expand Up @@ -9635,12 +9635,14 @@ def test_modularize_instance(self, args):

self.assertContained('main1\nmain2\nfoo\nbar\nbaz\n', self.run_js('runner.mjs'))

@no_4gb('EMBIND_AOT can\'t lower 4gb')
def test_modularize_instance_embind(self):
self.run_process([EMCC, test_file('modularize_instance_embind.cpp'),
self.run_process([EMXX, test_file('modularize_instance_embind.cpp'),
'-sMODULARIZE=instance',
'-Wno-experimental',
'-lembind',
'-sEMBIND_AOT',
'-o', 'modularize_instance_embind.mjs'])
'-o', 'modularize_instance_embind.mjs'] + self.get_emcc_args())

create_file('runner.mjs', '''
import init, { foo, Bar } from "./modularize_instance_embind.mjs";
Expand Down
5 changes: 5 additions & 0 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,8 @@ def run_embind_gen(options, wasm_target, js_syms, extra_settings):
# Ignore -sMODULARIZE which could otherwise effect how we run the module
# to generate the bindings.
settings.MODULARIZE = False
# Disable ESM integration to avoid enabling the experimental feature in node.
settings.WASM_ESM_INTEGRATION = False
# Don't include any custom user JS or files.
settings.PRE_JS_FILES = []
settings.POST_JS_FILES = []
Expand Down Expand Up @@ -2078,6 +2080,9 @@ def phase_embind_aot(options, wasm_target, js_syms):
// end embind exports'''
src += exports
write_file(final_js, src)
if settings.WASM_ESM_INTEGRATION:
# With ESM integration the embind exports also need to be exported by the main file.
settings.EXPORTED_RUNTIME_METHODS.extend(out['publicSymbols'])


# for Popen, we cannot have doublequotes, so provide functionality to
Expand Down