Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
#include <gif_lib.h>

void gif_side_test(void) {
ColorMapObject* map = GifMakeMapObject(2, NULL);
if (map) {
GifFreeMapObject(map);
}
puts("gif side ok");
}
''')

create_file('main.c', r'''
#include <stdio.h>

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):
Expand Down
2 changes: 1 addition & 1 deletion tools/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
Loading