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 | |
parent | 108fe84e7e2614ae847b2567c724cade4e95f0a0 (diff) | |
download | meson-f2fe271198554ce5a3c18676d57dddf4b030e0ab.zip meson-f2fe271198554ce5a3c18676d57dddf4b030e0ab.tar.gz meson-f2fe271198554ce5a3c18676d57dddf4b030e0ab.tar.bz2 |
Add support for finding Javascript source libraries with Emscripten.
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/compilers/compilers.py | 3 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/emscripten.py | 34 |
2 files changed, 36 insertions, 1 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index fc01ac0..5c1d9d4 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -47,7 +47,8 @@ Also add corresponding autodetection code in environment.py.""" header_suffixes = ('h', 'hh', 'hpp', 'hxx', 'H', 'ipp', 'moc', 'vapi', 'di') # type: T.Tuple[str, ...] obj_suffixes = ('o', 'obj', 'res') # type: T.Tuple[str, ...] -lib_suffixes = ('a', 'lib', 'dll', 'dll.a', 'dylib', 'so') # type: T.Tuple[str, ...] +# To the emscripten compiler, .js files are libraries +lib_suffixes = ('a', 'lib', 'dll', 'dll.a', 'dylib', 'so', 'js') # type: T.Tuple[str, ...] # Mapping of language to suffixes of files that should always be in that language # This means we can't include .h headers here since they could be C, C++, ObjC, etc. lang_suffixes = { diff --git a/mesonbuild/compilers/mixins/emscripten.py b/mesonbuild/compilers/mixins/emscripten.py index 226cc15..cac28b9 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 |