Skip to content

Commit 4ba6484

Browse files
committed
Change location of exports
1 parent b9fd356 commit 4ba6484

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/lib/libembind.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ var LibraryEmbind = {
3434
#if EMBIND_AOT
3535
$InvokerFunctions: '<<< EMBIND_AOT_INVOKERS >>>',
3636
#if MODULARIZE == 'instance'
37-
// embindUpdateExports is called in the generated code after embind is
37+
// embindAssignExports is called in the generated code after embind is
3838
// initialized. It will link the bindings to the ES module exports.
39-
$embindUpdateExports: '<<< EMBIND_AOT_UPDATE_EXPORTS >>>',
40-
$embindUpdateExports__postset: 'addOnInit(embindUpdateExports);',
39+
$embindAssignExports: '<<< EMBIND_AOT_ASSIGN_EXPORTS >>>',
40+
$embindAssignExports__postset: () => { addAtPostCtor('embindAssignExports();'); },
4141
#endif
4242
#endif
4343
// If register_type is used, emval will be registered multiple times for
@@ -2320,7 +2320,7 @@ var LibraryEmbind = {
23202320
};
23212321

23222322
#if MODULARIZE == 'instance'
2323-
extraLibraryFuncs.push('$embindUpdateExports');
2323+
extraLibraryFuncs.push('$embindAssignExports');
23242324
#endif
23252325

23262326
addToLibrary(LibraryEmbind);

src/lib/libembind_gen.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,9 @@ var LibraryEmbind = {
466466
def.printJs(out);
467467
}
468468
out.push('}\n');
469-
let updateExports = '() => {\n';
470-
for (const publicSymbol of publicSymbols) {
471-
updateExports += `__exp_${publicSymbol} = Module['${publicSymbol}'];\n`
472-
}
473-
updateExports += '}\n';
474469
console.log(JSON.stringify({
475470
'invokers': out.join(''),
476471
publicSymbols,
477-
updateExports
478472
}));
479473
}
480474
},

tools/link.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,14 +2052,23 @@ def phase_emit_tsd(options, wasm_target, js_target, js_syms, metadata):
20522052
@ToolchainProfiler.profile_block('embind aot js')
20532053
def phase_embind_aot(options, wasm_target, js_syms):
20542054
out = run_embind_gen(options, wasm_target, js_syms, {})
2055+
20552056
if DEBUG:
20562057
write_file(in_temp('embind_aot.json'), out)
20572058
out = json.loads(out)
20582059
src = read_file(final_js)
20592060
src = do_replace(src, '<<< EMBIND_AOT_INVOKERS >>>', out['invokers'])
20602061
if settings.MODULARIZE == 'instance':
2061-
settings.EMBIND_EXPORTS = out['publicSymbols']
2062-
src = do_replace(src, '<<< EMBIND_AOT_UPDATE_EXPORTS >>>', out['updateExports'])
2062+
# Add ES module exports for the embind exports.
2063+
decls = [f'export var {name};' for name in out['publicSymbols']]
2064+
# Assign the runtime exports from Module to the ES export.
2065+
assigns = [f'{name} = Module[\'{name}\'];' for name in out['publicSymbols']]
2066+
exports = f'''
2067+
// start embind exports
2068+
() => {{ {'\n'.join(assigns)} }};
2069+
{'\n'.join(decls)}
2070+
// end embind exports'''
2071+
src = do_replace(src, '<<< EMBIND_AOT_ASSIGN_EXPORTS >>>', exports)
20632072
write_file(final_js, src)
20642073

20652074

0 commit comments

Comments
 (0)