mirror of
https://github.com/mesonbuild/meson.git
synced 2026-11-06 05:16:42 +00:00
Add support for finding Javascript source libraries with Emscripten.
This commit is contained in:
1 parent
108fe84e7e
commit
f2fe271198
7 files changed
+78
-6
No files matched your search
+5
-5
@@ -1,12 +1,12 @@
|
||||
[binaries]
|
||||
c = '/home/jpakkane/emsdk/fastcomp/emscripten/emcc'
|
||||
cpp = '/home/jpakkane/emsdk/fastcomp/emscripten/em++'
|
||||
ar = '/home/jpakkane/emsdk/fastcomp/emscripten/emar'
|
||||
c = '/home/jpakkane/src/emsdk/upstream/emscripten/emcc'
|
||||
cpp = '/home/jpakkane/src/emsdk/upstream/emscripten/em++'
|
||||
ar = '/home/jpakkane/src/emsdk/upstream/emscripten/emar'
|
||||
|
||||
[built-in options]
|
||||
c_args = ['-s', 'WASM=1', '-s', 'EXPORT_ALL=1']
|
||||
c_args = []
|
||||
c_link_args = ['-s','EXPORT_ALL=1']
|
||||
cpp_args = ['-s', 'WASM=1', '-s', 'EXPORT_ALL=1']
|
||||
cpp_args = []
|
||||
cpp_link_args = ['-s', 'EXPORT_ALL=1']
|
||||
|
||||
[host_machine]
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
## Add support for `find_library` in Emscripten
|
||||
|
||||
The `find_library` method can be used to find your own JavaScript
|
||||
libraries. The limitation is that they must have the file extension
|
||||
`.js`. Other library lookups will look up "native" libraries from the
|
||||
system like currently. A typical usage would look like this:
|
||||
|
||||
```meson
|
||||
glue_lib = cc.find_library('gluefuncs.js',
|
||||
dirs: meson.current_source_dir())
|
||||
executable('prog', 'prog.c',
|
||||
dependencies: glue_lib)
|
||||
```
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,8 @@
|
||||
project('jslib', 'c')
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
sf_dep = cc.find_library('somefuncs.js', dirs: meson.current_source_dir())
|
||||
|
||||
executable('libcallc', 'prog.c',
|
||||
dependencies: sf_dep)
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <emscripten.h>
|
||||
|
||||
extern void sample_function();
|
||||
|
||||
int main() {
|
||||
printf("Hello World\n");
|
||||
// sampleFunction(); ????
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
mergeInto(LibraryManager.library, {
|
||||
sample_function__sig: 'v',
|
||||
sample_function: function() {
|
||||
alert("Something happened!");
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user