MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / process_libraries

Function process_libraries

tools/link.py:2709–2771  ·  view source on GitHub ↗

Process `-l` and `--js-library` flags.

(options, flags)

Source from the content-addressed store, hash-verified

2707
2708
2709def process_libraries(options, flags):
2710 """Process `-l` and `--js-library` flags."""
2711 new_flags = []
2712 system_libs_map = system_libs.Library.get_usable_variations()
2713
2714 for flag in flags:
2715 if flag.startswith('--js-library='):
2716 js_lib = flag.split('=', 1)[1]
2717 settings.JS_LIBRARIES.append(js_lib)
2718 continue
2719 if not flag.startswith('-l'):
2720 new_flags.append(flag)
2721 continue
2722 lib = flag.removeprefix('-l')
2723
2724 logger.debug('looking for library "%s"', lib)
2725
2726 js_libs = map_to_js_libs(lib)
2727 if js_libs is not None:
2728 for l in js_libs:
2729 add_system_js_lib(l)
2730
2731 # We don't need to resolve system libraries to absolute paths here, we can just
2732 # let wasm-ld handle that. However, we do want to map to the correct variant.
2733 # For example we map `-lc` to `-lc-mt` if we are building with threading support.
2734 if 'lib' + lib in system_libs_map:
2735 lib = system_libs_map['lib' + lib].get_link_flag()
2736 new_flags.append(lib)
2737 continue
2738
2739 if js_libs is not None:
2740 continue
2741
2742 if lib.endswith('.js'):
2743 name = 'lib' + lib
2744 path = find_library(name, options.lib_dirs)
2745 if not path:
2746 exit_with_error(f'unable to find library {flag}')
2747 settings.JS_LIBRARIES.append(os.path.abspath(path))
2748 continue
2749
2750 static_lib = f'lib{lib}.a'
2751 if not settings.MAIN_MODULE and not find_library(static_lib, options.lib_dirs):
2752 # Normally we can rely on the native linker to expand `-l` args.
2753 # However, emscripten also supports fake `.so` files that are actually
2754 # just regular object files. This means we need to support `.so` files even
2755 # when statically linking. The native linker (wasm-ld) will otherwise
2756 # ignore .so files in this mode.
2757 found_dylib = False
2758 for ext in DYLIB_EXTENSIONS:
2759 name = 'lib' + lib + ext
2760 path = find_library(name, options.lib_dirs)
2761 if path and not building.is_wasm_dylib(path):
2762 found_dylib = True
2763 new_flags.append(path)
2764 break
2765
2766 if found_dylib:

Callers 2

run_post_linkFunction · 0.85
runFunction · 0.85

Calls 8

map_to_js_libsFunction · 0.85
add_system_js_libFunction · 0.85
find_libraryFunction · 0.85
exit_with_errorFunction · 0.85
get_usable_variationsMethod · 0.80
splitMethod · 0.80
appendMethod · 0.80
get_link_flagMethod · 0.80

Tested by

no test coverage detected