Skip to content

Commit

Permalink
Use locateFile in the dynamic module loader
Browse files Browse the repository at this point in the history
  • Loading branch information
georgestagg committed Dec 15, 2022
1 parent c0c97c6 commit 48bc73c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/library_dylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ var LibraryDylink = {
return flags.loadAsync ? Promise.resolve(libData) : libData;
}

libFile = locateFile(libFile);
if (flags.loadAsync) {
return new Promise(function(resolve, reject) {
readAsync(libFile, (data) => resolve(new Uint8Array(data)), reject);
Expand Down
24 changes: 21 additions & 3 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import sys
import time
import unittest
import tempfile
from pathlib import Path
from functools import wraps

Expand Down Expand Up @@ -4071,6 +4072,7 @@ def dylink_test(self, main, side, expected=None, header=None, force_c=False,

def dylink_testf(self, main, side=None, expected=None, force_c=False, main_emcc_args=None,
main_module=2,
so_dir='',
so_name='liblib.so',
need_reverse=True, **kwargs):
main_emcc_args = main_emcc_args or []
Expand All @@ -4094,13 +4096,13 @@ def dylink_testf(self, main, side=None, expected=None, force_c=False, main_emcc_
self.run_process([EMCC] + side + self.get_emcc_args() + ['-o', out_file])
else:
out_file = self.build(side, js_outfile=(side_suffix == 'js'))
shutil.move(out_file, so_name)
shutil.move(out_file, os.path.join(so_dir, so_name))

# main settings
self.set_setting('MAIN_MODULE', main_module)
self.clear_setting('SIDE_MODULE')
self.emcc_args += main_emcc_args
self.emcc_args.append(so_name)
self.emcc_args.append(os.path.join(so_dir, so_name))

if force_c:
self.emcc_args.append('-nostdlib++')
Expand All @@ -4120,7 +4122,7 @@ def dylink_testf(self, main, side=None, expected=None, force_c=False, main_emcc_
# Test the reverse as well. There we flip the role of the side module and main module.
# - We add --no-entry since the side module doesn't have a `main`
self.dylink_testf(side, main, expected, force_c, main_emcc_args + ['--no-entry'],
need_reverse=False, **kwargs)
main_module, so_dir, so_name, need_reverse=False, **kwargs)

def do_basic_dylink_test(self, **kwargs):
self.dylink_test(r'''
Expand Down Expand Up @@ -4177,6 +4179,22 @@ def test_dylink_safe_heap(self):
self.set_setting('SAFE_HEAP')
self.do_basic_dylink_test()

@needs_dylink
def test_dylink_locate_file(self):
so_dir = 'so_dir'
so_name = 'liblib.so'
os.mkdir(so_dir)
create_file('pre.js', '''
Module['locateFile'] = function(f) {
if (f === '%s') {
return '%s/' + f;
} else {
return f;
}
};
''' % (so_name, so_dir))
self.do_basic_dylink_test(so_dir=so_dir, so_name=so_name, main_emcc_args=['--pre-js', 'pre.js'])

@needs_dylink
def test_dylink_function_pointer_equality(self):
self.dylink_test(r'''
Expand Down

0 comments on commit 48bc73c

Please sign in to comment.