Skip to content

Commit 9a9791c

Browse files
authored
[esm-integration] Export embind bindings. (#24388)
Adds the embind bindings to re-export the functions in the support file. As with modularize instance, this requires EMBIND_AOT to work.
1 parent 2f78716 commit 9a9791c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

test/test_core.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
raise Exception('do not run this file directly; do something like: test/runner')
1919

2020
from tools.shared import PIPE
21-
from tools.shared import EMCC, EMAR, FILE_PACKAGER
21+
from tools.shared import EMCC, EMAR, EMXX, FILE_PACKAGER
2222
from tools.utils import WINDOWS, MACOS, LINUX, write_file, delete_file
2323
from tools import shared, building, config, utils, webassembly
2424
import common
@@ -9753,12 +9753,14 @@ def test_modularize_instance(self, args):
97539753

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

9756+
@no_4gb('EMBIND_AOT can\'t lower 4gb')
97569757
def test_modularize_instance_embind(self):
9757-
self.run_process([EMCC, test_file('modularize_instance_embind.cpp'),
9758+
self.run_process([EMXX, test_file('modularize_instance_embind.cpp'),
97589759
'-sMODULARIZE=instance',
9760+
'-Wno-experimental',
97599761
'-lembind',
97609762
'-sEMBIND_AOT',
9761-
'-o', 'modularize_instance_embind.mjs'])
9763+
'-o', 'modularize_instance_embind.mjs'] + self.get_emcc_args())
97629764

97639765
create_file('runner.mjs', '''
97649766
import init, { foo, Bar } from "./modularize_instance_embind.mjs";

tools/link.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,8 @@ def run_embind_gen(options, wasm_target, js_syms, extra_settings):
20282028
# Ignore -sMODULARIZE which could otherwise effect how we run the module
20292029
# to generate the bindings.
20302030
settings.MODULARIZE = False
2031+
# Disable ESM integration to avoid enabling the experimental feature in node.
2032+
settings.WASM_ESM_INTEGRATION = False
20312033
# Don't include any custom user JS or files.
20322034
settings.PRE_JS_FILES = []
20332035
settings.POST_JS_FILES = []
@@ -2109,6 +2111,9 @@ def phase_embind_aot(options, wasm_target, js_syms):
21092111
// end embind exports'''
21102112
src += exports
21112113
write_file(final_js, src)
2114+
if settings.WASM_ESM_INTEGRATION:
2115+
# With ESM integration the embind exports also need to be exported by the main file.
2116+
settings.EXPORTED_RUNTIME_METHODS.extend(out['publicSymbols'])
21122117

21132118

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

0 commit comments

Comments
 (0)