From 9400a37036f393c709829a8623a7b7959808253c Mon Sep 17 00:00:00 2001 From: ryanking13 Date: Sun, 22 Mar 2026 00:08:21 +0900 Subject: [PATCH 1/7] Append pic directory when SIDE_MODULE --- tools/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)) From ead964417fe450a7e5796696b0d0b95fb3184b92 Mon Sep 17 00:00:00 2001 From: ryanking13 Date: Sun, 22 Mar 2026 00:50:15 +0900 Subject: [PATCH 2/7] Fix system_libs --- tools/system_libs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/system_libs.py b/tools/system_libs.py index b41ae353d04f1..b2cc73700661a 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`) From 8011978e661301ac1709c6be03b58143b432b596 Mon Sep 17 00:00:00 2001 From: ryanking13 Date: Sun, 22 Mar 2026 00:50:30 +0900 Subject: [PATCH 3/7] Add test --- test/test_other.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test_other.py b/test/test_other.py index 936dff4783e1c..f6655129c3136 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2559,6 +2559,11 @@ 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 + self.emcc(test_file('jpeg_test.c'), args=['-sUSE_LIBJPEG', '-sSIDE_MODULE', '-ljpeg']) + @requires_network @also_with_wasm64 def test_bullet(self): From 4ed0d6f7614b4ef8050e52fc2be8038323a0b3cd Mon Sep 17 00:00:00 2001 From: ryanking13 Date: Sun, 22 Mar 2026 09:17:26 +0900 Subject: [PATCH 4/7] Make test more robust --- test/test_other.py | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index f6655129c3136..23af6590612c7 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2561,8 +2561,44 @@ def test_libjpeg(self): @requires_network def test_side_module_with_ports(self): - # Verify that ports can be used in side modules - self.emcc(test_file('jpeg_test.c'), args=['-sUSE_LIBJPEG', '-sSIDE_MODULE', '-ljpeg']) + # 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 jpeg_side_test(void) { + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + puts("jpeg side ok"); + } + ''') + + create_file('main.c', r''' + #include + + void jpeg_side_test(void); + + int main() { + jpeg_side_test(); + puts("main ok"); + return 0; + } + ''') + + self.emcc('side.c', args=['-sSIDE_MODULE', '-sUSE_LIBJPEG', '-ljpeg', '-o', 'libjpeg_side.so']) + self.assertExists('libjpeg_side.so') + + # Linking the side module into the main module should cause it to be loaded + # automatically at runtime. + self.emcc('main.c', args=['-sMAIN_MODULE=2', 'libjpeg_side.so']) + output = self.run_js('a.out.js') + self.assertContained('jpeg side ok\n', output) + self.assertContained('main ok\n', output) @requires_network @also_with_wasm64 From 49984fe69ef24b4c6d1fe8a96b5cd4602f4326e6 Mon Sep 17 00:00:00 2001 From: ryanking13 Date: Mon, 23 Mar 2026 20:40:27 +0900 Subject: [PATCH 5/7] Disable test when cache is frozen --- test/test_other.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_other.py b/test/test_other.py index 23af6590612c7..f70ba5c12a871 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2561,6 +2561,8 @@ def test_libjpeg(self): @requires_network def test_side_module_with_ports(self): + if config.FROZEN_CACHE: + self.skipTest("test doesn't work with frozen cache") # 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''' From 9af579e92bad2e589d54c1f1bcb4ef67578b2506 Mon Sep 17 00:00:00 2001 From: ryanking13 Date: Mon, 23 Mar 2026 20:45:48 +0900 Subject: [PATCH 6/7] Use gif instead of jpeg for testing --- test/test_other.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index f70ba5c12a871..a9ea74db2c662 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2561,45 +2561,41 @@ def test_libjpeg(self): @requires_network def test_side_module_with_ports(self): - if config.FROZEN_CACHE: - self.skipTest("test doesn't work with frozen cache") # 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 + #include - void jpeg_side_test(void) { - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - puts("jpeg side ok"); + 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 jpeg_side_test(void); + void gif_side_test(void); int main() { - jpeg_side_test(); + gif_side_test(); puts("main ok"); return 0; } ''') - self.emcc('side.c', args=['-sSIDE_MODULE', '-sUSE_LIBJPEG', '-ljpeg', '-o', 'libjpeg_side.so']) - self.assertExists('libjpeg_side.so') + 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.emcc('main.c', args=['-sMAIN_MODULE=2', 'libjpeg_side.so']) + self.emcc('main.c', args=['-sMAIN_MODULE=2', 'libgif_side.so']) output = self.run_js('a.out.js') - self.assertContained('jpeg side ok\n', output) + self.assertContained('gif side ok\n', output) self.assertContained('main ok\n', output) @requires_network From 788dde9cde8d48a20d338271d74b3f06236fc5e7 Mon Sep 17 00:00:00 2001 From: ryanking13 Date: Wed, 25 Mar 2026 13:18:42 +0900 Subject: [PATCH 7/7] Address comment --- test/test_other.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index 06122832a9600..f274103d1e080 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2593,10 +2593,7 @@ def test_side_module_with_ports(self): # Linking the side module into the main module should cause it to be loaded # automatically at runtime. - self.emcc('main.c', args=['-sMAIN_MODULE=2', 'libgif_side.so']) - output = self.run_js('a.out.js') - self.assertContained('gif side ok\n', output) - self.assertContained('main ok\n', output) + self.do_runf('main.c', 'gif side ok\n', cflags=['-sMAIN_MODULE=2', 'libgif_side.so']) @requires_network @also_with_wasm64