diff options
| author | Jussi Pakkanen <jpakkane@gmail.com> | 2021-08-06 17:31:42 +0300 |
|---|---|---|
| committer | Jussi Pakkanen <jpakkane@gmail.com> | 2021-08-08 15:25:48 +0300 |
| commit | f2fe271198554ce5a3c18676d57dddf4b030e0ab (patch) | |
| tree | a12cff269c11b55f4d911ce1fda614e0ddb5d14a /mesonbuild/compilers/mixins/emscripten.py | |
| parent | 108fe84e7e2614ae847b2567c724cade4e95f0a0 (diff) | |
| download | meson-f2fe271198554ce5a3c18676d57dddf4b030e0ab.tar.gz | |
Add support for finding Javascript source libraries with Emscripten.
Diffstat (limited to 'mesonbuild/compilers/mixins/emscripten.py')
| -rw-r--r-- | mesonbuild/compilers/mixins/emscripten.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/mesonbuild/compilers/mixins/emscripten.py b/mesonbuild/compilers/mixins/emscripten.py index 226cc1531..cac28b9d8 100644 --- a/mesonbuild/compilers/mixins/emscripten.py +++ b/mesonbuild/compilers/mixins/emscripten.py @@ -18,11 +18,14 @@ import os.path import typing as T from ... import coredata +from ... import mesonlib from ...mesonlib import OptionKey +from ...mesonlib import LibType if T.TYPE_CHECKING: from ...environment import Environment from ...compilers.compilers import Compiler + from ...dependencies import Dependency else: # This is a bit clever, for mypy we pretend that these mixins descend from # Compiler, so we get all of the methods and attributes defined for us, but @@ -31,6 +34,15 @@ else: Compiler = object +def wrap_js_includes(args: T.List[str]) -> T.List[str]: + final_args = [] + for i in args: + if i.endswith('.js') and not i.startswith('-'): + final_args += ['--js-library', i] + else: + final_args += [i] + return final_args + class EmscriptenMixin(Compiler): def _get_compile_output(self, dirname: str, mode: str) -> str: @@ -67,3 +79,25 @@ class EmscriptenMixin(Compiler): }) return opts + + @classmethod + def native_args_to_unix(cls, args: T.List[str]) -> T.List[str]: + return wrap_js_includes(super().native_args_to_unix(args)) + + def get_dependency_link_args(self, dep: 'Dependency') -> T.List[str]: + return wrap_js_includes(super().get_dependency_link_args(dep)) + + def find_library(self, libname: str, env: 'Environment', extra_dirs: T.List[str], + libtype: LibType = LibType.PREFER_SHARED) -> T.Optional[T.List[str]]: + if not libname.endswith('.js'): + return super().find_library(libname, env, extra_dirs, libtype) + if os.path.isabs(libname): + if os.path.exists(libname): + return [libname] + if len(extra_dirs) == 0: + raise mesonlib.EnvironmentException('Looking up Emscripten JS libraries requires either an absolute path or specifying extra_dirs.') + for d in extra_dirs: + abs_path = os.path.join(d, libname) + if os.path.exists(abs_path): + return [abs_path] + return None |
