From 771b0d3ffbc7b034b436d4ad27be7d0a1da6b3cd Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 24 Feb 2020 10:55:31 -0800 Subject: compilers/mixins/emscripten: Implement thread support Emscripten has pthread support (as well as C++ threads), but we don't currently implement them. This fixes that by adding the necessary code. The one thing I'm not sure about is setting the pool size. The docs suggest that you really want to do this to ensure that your code works correctly, but the number should really be configurable, not sure how to set that. Fixes #6684 --- mesonbuild/compilers/c.py | 2 +- mesonbuild/compilers/cpp.py | 2 +- mesonbuild/compilers/mixins/emscripten.py | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index e27eb90..f3ed9e8 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -133,7 +133,7 @@ class AppleClangCCompiler(ClangCCompiler): _C18_VERSION = '>=11.0.0' -class EmscriptenCCompiler(BasicLinkerIsCompilerMixin, LinkerEnvVarsMixin, EmscriptenMixin, ClangCCompiler): +class EmscriptenCCompiler(EmscriptenMixin, BasicLinkerIsCompilerMixin, LinkerEnvVarsMixin, ClangCCompiler): def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', exe_wrapper=None, **kwargs): if not is_cross: diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index f6f4cfc..2a244e9 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -201,7 +201,7 @@ class AppleClangCPPCompiler(ClangCPPCompiler): pass -class EmscriptenCPPCompiler(BasicLinkerIsCompilerMixin, LinkerEnvVarsMixin, EmscriptenMixin, ClangCPPCompiler): +class EmscriptenCPPCompiler(EmscriptenMixin, BasicLinkerIsCompilerMixin, LinkerEnvVarsMixin, ClangCPPCompiler): def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', exe_wrapper=None, **kwargs): if not is_cross: diff --git a/mesonbuild/compilers/mixins/emscripten.py b/mesonbuild/compilers/mixins/emscripten.py index 36a757a..ee86ce4 100644 --- a/mesonbuild/compilers/mixins/emscripten.py +++ b/mesonbuild/compilers/mixins/emscripten.py @@ -17,8 +17,13 @@ import os.path import typing as T +from ... import coredata from ...mesonlib import MesonException +if T.TYPE_CHECKING: + from ..environment import Environment + + class EmscriptenMixin: def get_option_link_args(self, options): @@ -45,3 +50,24 @@ class EmscriptenMixin: else: suffix = 'wasm' return os.path.join(dirname, 'output.' + suffix) + + def thread_flags(self, env: 'Environment') -> T.List[str]: + return ['-s', 'USE_PTHREADS=1'] + + def thread_link_flags(self, env: 'Environment') -> T.List[str]: + args = ['-s', 'USE_PTHREADS=1'] + count = env.coredata.compiler_options[self.for_machine]['{}_thread_count'.format(self.language)].value # type: int + if count: + args.extend(['-s', 'PTHREAD_POOL_SIZE={}'.format(count)]) + return args + + def get_options(self): + opts = super().get_options() + opts.update({ + '{}_thread_count'.format(self.language): coredata.UserIntegerOption( + 'Number of threads to use in web assembly, set to 0 to disable', + (0, None, 4), # Default was picked at random + ), + }) + + return opts -- cgit v1.1