diff --git a/test/test_sanity.py b/test/test_sanity.py index cc7ef3db9d5ce..aa1d2a167843e 100644 --- a/test/test_sanity.py +++ b/test/test_sanity.py @@ -780,6 +780,12 @@ def test_embuilder_external_ports_options(self): self.run_process([EMBUILDER, 'build', f'{external_port_path}:dependency=sdl2', '--force']) self.assertExists(os.path.join(config.CACHE, 'sysroot', 'lib', 'wasm32-emscripten', 'lib_external-sdl2.a')) + def test_embuilder_transitive_pic(self): + restore_and_set_up() + self.run_process([EMBUILDER, 'clear', 'sdl2*']) + self.run_process([EMBUILDER, '--pic', 'clear', 'sdl2*']) + self.run_process([EMCC, '-sMAIN_MODULE=2', '-sUSE_SDL=2', '-sUSE_SDL_GFX=2', test_file('hello_world.c')]) + def test_binaryen_version(self): restore_and_set_up() with open(EM_CONFIG, 'a') as f: diff --git a/tools/system_libs.py b/tools/system_libs.py index d07ec7c7e4c88..a16d2a337f863 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -63,7 +63,11 @@ def get_base_cflags(build_dir, force_object_files=False, preprocess=True): if settings.LTO and not force_object_files: flags += ['-flto=' + settings.LTO] if settings.RELOCATABLE or settings.MAIN_MODULE: - flags += ['-fPIC'] + # Explictly include `-sRELOCATABLE` 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`) + # FIXME(sbc): `-fPIC` should really be enough here. + flags += ['-fPIC', '-sRELOCATABLE'] if preprocess: flags += ['-DEMSCRIPTEN_DYNAMIC_LINKING'] if settings.MEMORY64: