diff --git a/test/test_other.py b/test/test_other.py index a453365822a67..f274103d1e080 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2559,6 +2559,42 @@ def test_libjpeg(self): cflags=['--embed-file', 'screenshot.jpg', '--use-port=libjpeg'], args=['screenshot.jpg']) + @requires_network + def test_side_module_with_ports(self): + # Verify that ports can be used in side modules, and that the resulting + # side module can be used from a main module. + create_file('side.c', r''' + #include + #include + + void gif_side_test(void) { + ColorMapObject* map = GifMakeMapObject(2, NULL); + if (map) { + GifFreeMapObject(map); + } + puts("gif side ok"); + } + ''') + + create_file('main.c', r''' + #include + + void gif_side_test(void); + + int main() { + gif_side_test(); + puts("main ok"); + return 0; + } + ''') + + self.emcc('side.c', args=['-sSIDE_MODULE', '-sUSE_GIFLIB', '-lgif', '-o', 'libgif_side.so']) + self.assertExists('libgif_side.so') + + # Linking the side module into the main module should cause it to be loaded + # automatically at runtime. + self.do_runf('main.c', 'gif side ok\n', cflags=['-sMAIN_MODULE=2', 'libgif_side.so']) + @requires_network @also_with_wasm64 def test_bullet(self): diff --git a/tools/cache.py b/tools/cache.py index 832dc31184b00..76ab142083cc7 100644 --- a/tools/cache.py +++ b/tools/cache.py @@ -124,7 +124,7 @@ def get_lib_dir(absolute): subdir.append('thinlto') else: subdir.append('lto') - if settings.MAIN_MODULE: + if settings.MAIN_MODULE or settings.SIDE_MODULE: subdir.append('pic') if subdir: path = Path(path, '-'.join(subdir)) diff --git a/tools/system_libs.py b/tools/system_libs.py index 7fc276f526ef1..a449e899956ae 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -61,7 +61,7 @@ def get_base_cflags(build_dir, force_object_files=False, preprocess=True): flags = ['-g', '-sSTRICT', '-Werror'] if settings.LTO and not force_object_files: flags += ['-flto=' + settings.LTO] - if settings.MAIN_MODULE: + if settings.MAIN_MODULE or settings.SIDE_MODULE: # Explicitly include `-sMAIN_MODULE` when building system libraries. # `-fPIC` alone is not enough to configure trigger the building and # caching of `pic` libraries (see `get_lib_dir` in `cache.py`)