Skip to content

Commit 8e3d62c

Browse files
authored
[MODULARIZE=instance] Enable dynamic linking (#24315)
1 parent 976b43d commit 8e3d62c

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ jobs:
803803
core0.test_cubescript_jspi
804804
esm_integration.test_fs_js_api*
805805
instance.test_hello_world
806+
instance.test_dylink_basics
806807
esm_integration.test_inlinejs3
807808
esm_integration.test_embind_val_basics
808809
"

src/preamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ async function instantiateAsync(binary, binaryFile, imports) {
819819

820820
#if !WASM_ESM_INTEGRATION
821821
function getWasmImports() {
822-
#if PTHREADS || WASM_WORKERS
822+
#if PTHREADS || WASM_WORKERS || (IMPORTED_MEMORY && MODULARIZE == 'instance')
823823
assignWasmImports();
824824
#endif
825825
#if ASYNCIFY && (ASSERTIONS || ASYNCIFY == 2)

test/common.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,13 @@ def decorator(func):
868868
return decorator
869869

870870

871+
def get_output_suffix(args):
872+
if any(a in args for a in ('-sEXPORT_ES6', '-sWASM_ESM_INTEGRATION', '-sMODULARIZE=instance')):
873+
return '.mjs'
874+
else:
875+
return '.js'
876+
877+
871878
class RunnerMeta(type):
872879
@classmethod
873880
def make_test(mcs, name, func, suffix, args):
@@ -1390,10 +1397,7 @@ def build(self, filename, libraries=None, includes=None, force_c=False, emcc_arg
13901397
if emcc_args:
13911398
all_emcc_args += emcc_args
13921399
if not output_suffix:
1393-
if any(a in all_emcc_args for a in ('-sEXPORT_ES6', '-sWASM_ESM_INTEGRATION', '-sMODULARIZE=instance')):
1394-
output_suffix = '.mjs'
1395-
else:
1396-
output_suffix = '.js'
1400+
output_suffix = get_output_suffix(all_emcc_args)
13971401

13981402
if output_basename:
13991403
output = output_basename + output_suffix

test/test_core.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,6 +3974,8 @@ def dylink_testf(self, main, side=None, expected=None, force_c=False, main_emcc_
39743974
side += '_side' + ext
39753975

39763976
# side settings
3977+
old_settings = dict(self.settings_mods)
3978+
self.clear_setting('MODULARIZE')
39773979
self.clear_setting('MAIN_MODULE')
39783980
self.set_setting('SIDE_MODULE')
39793981
so_file = os.path.join(so_dir, so_name)
@@ -3985,6 +3987,7 @@ def dylink_testf(self, main, side=None, expected=None, force_c=False, main_emcc_
39853987
shutil.move(out_file, so_file)
39863988

39873989
# main settings
3990+
self.settings_mods = old_settings
39883991
self.set_setting('MAIN_MODULE', main_module)
39893992
self.clear_setting('SIDE_MODULE')
39903993
self.emcc_args += main_emcc_args
@@ -3995,9 +3998,10 @@ def dylink_testf(self, main, side=None, expected=None, force_c=False, main_emcc_
39953998

39963999
if isinstance(main, list):
39974000
# main is just a library
3998-
delete_file('main.js')
3999-
self.run_process([EMCC] + main + self.get_emcc_args() + ['-o', 'main.js'])
4000-
self.do_run('main.js', expected, no_build=True, **kwargs)
4001+
outfile = self.output_name('main')
4002+
delete_file(outfile)
4003+
self.run_process([EMCC] + main + self.get_emcc_args() + ['-o', outfile])
4004+
self.do_run(outfile, expected, no_build=True, **kwargs)
40014005
else:
40024006
self.do_runf(main, expected, force_c=force_c, **kwargs)
40034007

@@ -4020,11 +4024,15 @@ def do_basic_dylink_test(self, **kwargs):
40204024
}
40214025
''', 'other says 11.', 'int sidey();', force_c=True, **kwargs)
40224026

4027+
def output_name(self, basename):
4028+
suffix = common.get_output_suffix(self.get_emcc_args())
4029+
return basename + suffix
4030+
40234031
@needs_dylink
40244032
@crossplatform
40254033
def test_dylink_basics(self):
40264034
self.do_basic_dylink_test()
4027-
self.verify_in_strict_mode('main.js')
4035+
self.verify_in_strict_mode(self.output_name('main'))
40284036

40294037
@with_dylink_reversed
40304038
@no_wasm64('Requires table64 lowering in all cases')

tools/emscripten.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ def create_module(metadata, function_exports, global_exports, tag_exports,librar
10171017
receiving += create_global_exports(global_exports)
10181018
receiving += create_other_export_declarations(tag_exports)
10191019

1020-
if settings.PTHREADS or settings.WASM_WORKERS:
1020+
if settings.PTHREADS or settings.WASM_WORKERS or (settings.IMPORTED_MEMORY and settings.MODULARIZE == 'instance'):
10211021
sending = textwrap.indent(sending, ' ').strip()
10221022
module.append('''\
10231023
var wasmImports;

tools/link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,8 +1540,8 @@ def limit_incoming_module_api():
15401540
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['_load_secondary_module']
15411541

15421542
# wasm side modules have suffix .wasm
1543-
if settings.SIDE_MODULE and shared.suffix(target) == '.js':
1544-
diagnostics.warning('emcc', 'output suffix .js requested, but wasm side modules are just wasm files; emitting only a .wasm, no .js')
1543+
if settings.SIDE_MODULE and shared.suffix(target) in ('.js', '.mjs'):
1544+
diagnostics.warning('emcc', 'JavaScript output suffix requested, but wasm side modules are just wasm files; emitting only a .wasm, no .js')
15451545

15461546
if options.sanitize:
15471547
if settings.WASM_WORKERS:

0 commit comments

Comments
 (0)