diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2021-08-06 17:31:42 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2021-08-06 17:31:42 +0300 |
commit | 8339b660fe0ca814a289633e60f9cbe0787b3f68 (patch) | |
tree | aa4c8a2c5e0d2379d8d72d22c8ebb1bb103a57cd /mesonbuild/compilers | |
parent | 5381ec89afdbf61e575cb0ac5c25e339279a5af2 (diff) | |
download | meson-jslibs.zip meson-jslibs.tar.gz meson-jslibs.tar.bz2 |
Add support for finding Javascript source libraries with Emscripten.jslibs
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r-- | mesonbuild/compilers/compilers.py | 3 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/emscripten.py | 32 |
2 files changed, 34 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..c770639 100644 --- a/mesonbuild/compilers/mixins/emscripten.py +++ b/mesonbuild/compilers/mixins/emscripten.py @@ -18,7 +18,9 @@ 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 @@ -67,3 +69,33 @@ class EmscriptenMixin(Compiler): }) return opts + + def wrap_js_includes(self, args: 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 + + def native_args_to_unix(cls, args: T.List[str]) -> T.List[str]: + return cls.wrap_js_includes(super().native_args_to_unix(args)) + + def get_dependency_link_args(self, dep: 'Dependency') -> T.List[str]: + return self.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 |