aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2019-06-19 21:56:00 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2019-08-05 19:31:32 +0300
commitf41bdae36861baa8be541af8273adc5b4b94ec48 (patch)
tree9334ac78c12e5505592dcff7f6f5c32c999ee4fb /mesonbuild
parentddbf60f86da4ece3d407fe3b3e38ff45e34f561e (diff)
downloadmeson-f41bdae36861baa8be541af8273adc5b4b94ec48.zip
meson-f41bdae36861baa8be541af8273adc5b4b94ec48.tar.gz
meson-f41bdae36861baa8be541af8273adc5b4b94ec48.tar.bz2
Add basic Webassembly support via Emscripten.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/build.py2
-rw-r--r--mesonbuild/compilers/__init__.py2
-rw-r--r--mesonbuild/compilers/c.py25
-rw-r--r--mesonbuild/compilers/compilers.py1
-rw-r--r--mesonbuild/compilers/cpp.py35
-rw-r--r--mesonbuild/envconfig.py3
-rw-r--r--mesonbuild/environment.py7
-rw-r--r--mesonbuild/minstall.py7
8 files changed, 81 insertions, 1 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index d5814ff..b77995a 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -1432,6 +1432,8 @@ class Executable(BuildTarget):
# Executable for Windows or C#/Mono
if machine.is_windows() or machine.is_cygwin() or 'cs' in self.compilers:
self.suffix = 'exe'
+ elif machine.system.startswith('wasm') or machine.system == 'emscripten':
+ self.suffix = 'js'
elif ('c' in self.compilers and self.compilers['c'].get_id().startswith('arm') or
'cpp' in self.compilers and self.compilers['cpp'].get_id().startswith('arm')):
self.suffix = 'axf'
diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py
index 6d9e814..5cd56b8 100644
--- a/mesonbuild/compilers/__init__.py
+++ b/mesonbuild/compilers/__init__.py
@@ -126,6 +126,7 @@ from .c import (
ClangClCCompiler,
GnuCCompiler,
ElbrusCCompiler,
+ EmscriptenCCompiler,
IntelCCompiler,
IntelClCCompiler,
PGICCompiler,
@@ -140,6 +141,7 @@ from .cpp import (
ClangClCPPCompiler,
GnuCPPCompiler,
ElbrusCPPCompiler,
+ EmscriptenCPPCompiler,
IntelCPPCompiler,
IntelClCPPCompiler,
PGICPPCompiler,
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index eff7161..f50b77c 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -119,6 +119,31 @@ class ClangCCompiler(ClangCompiler, CCompiler):
return basic
+class EmscriptenCCompiler(ClangCCompiler):
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
+ if not is_cross:
+ raise MesonException('Emscripten compiler can only be used for cross compilation.')
+ ClangCCompiler.__init__(self, exelist, version, compiler_type, for_machine, is_cross, exe_wrapper, **kwargs)
+ self.id = 'emscripten'
+
+ def get_option_link_args(self, options):
+ return []
+
+ def get_linker_always_args(self):
+ return []
+
+ def get_asneeded_args(self):
+ return []
+
+ def get_lundef_args(self):
+ return []
+
+ def build_rpath_args(self, *args, **kwargs):
+ return []
+
+ def get_soname_args(self, *args, **kwargs):
+ raise MesonException('Emscripten does not support shared libraries.')
+
class ArmclangCCompiler(ArmclangCompiler, CCompiler):
def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 179756a..5249068 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -1204,6 +1204,7 @@ class CompilerType(enum.Enum):
CLANG_STANDARD = 10
CLANG_OSX = 11
CLANG_MINGW = 12
+ CLANG_EMSCRIPTEN = 13
# Possibly clang-cl?
ICC_STANDARD = 20
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index 6ae2673..5808b2e 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -131,7 +131,7 @@ class CPPCompiler(CLikeCompiler, Compiler):
}
# Currently, remapping is only supported for Clang, Elbrus and GCC
- assert(self.id in frozenset(['clang', 'lcc', 'gcc']))
+ assert(self.id in frozenset(['clang', 'lcc', 'gcc', 'emscripten']))
if cpp_std not in CPP_FALLBACKS:
# 'c++03' and 'c++98' don't have fallback types
@@ -183,6 +183,39 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler):
return ['-lstdc++']
+class EmscriptenCPPCompiler(ClangCPPCompiler):
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
+ if not is_cross:
+ raise MesonException('Emscripten compiler can only be used for cross compilation.')
+ ClangCPPCompiler.__init__(self, exelist, version, compiler_type, for_machine, is_cross, exe_wrapper, **kwargs)
+ self.id = 'emscripten'
+
+ def get_option_compile_args(self, options):
+ args = []
+ std = options['cpp_std']
+ if std.value != 'none':
+ args.append(self._find_best_cpp_std(std.value))
+ return args
+
+ def get_option_link_args(self, options):
+ return []
+
+ def get_linker_always_args(self):
+ return []
+
+ def get_asneeded_args(self):
+ return []
+
+ def get_lundef_args(self):
+ return []
+
+ def build_rpath_args(self, *args, **kwargs):
+ return []
+
+ def get_soname_args(self, *args, **kwargs):
+ raise MesonException('Emscripten does not support shared libraries.')
+
+
class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py
index 011ab5d..15d937b 100644
--- a/mesonbuild/envconfig.py
+++ b/mesonbuild/envconfig.py
@@ -53,6 +53,8 @@ known_cpu_families = (
's390x',
'sparc',
'sparc64',
+ 'wasm32',
+ 'wasm64',
'x86',
'x86_64'
)
@@ -66,6 +68,7 @@ CPU_FAMILES_64_BIT = [
'ppc64',
'riscv64',
'sparc64',
+ 'wasm64',
'x86_64',
]
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 0d30adb..cd55ace 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -60,6 +60,8 @@ from .compilers import (
ElbrusCCompiler,
ElbrusCPPCompiler,
ElbrusFortranCompiler,
+ EmscriptenCCompiler,
+ EmscriptenCPPCompiler,
IntelCCompiler,
IntelCPPCompiler,
IntelClCCompiler,
@@ -707,6 +709,11 @@ class Environment:
cls = GnuCCompiler if lang == 'c' else GnuCPPCompiler
return cls(ccache + compiler, version, compiler_type, for_machine, is_cross, exe_wrap, defines, full_version=full_version)
+ if 'Emscripten' in out:
+ cls = EmscriptenCCompiler if lang == 'c' else EmscriptenCPPCompiler
+ compiler_type = CompilerType.CLANG_EMSCRIPTEN
+ return cls(ccache + compiler, version, compiler_type, for_machine, is_cross, exe_wrap, full_version=full_version)
+
if 'armclang' in out:
# The compiler version is not present in the first line of output,
# instead it is present in second line, startswith 'Component:'.
diff --git a/mesonbuild/minstall.py b/mesonbuild/minstall.py
index ed82c37..8b0768e 100644
--- a/mesonbuild/minstall.py
+++ b/mesonbuild/minstall.py
@@ -465,6 +465,13 @@ class Installer:
pdb_outname = os.path.splitext(outname)[0] + '.pdb'
self.do_copyfile(pdb_filename, pdb_outname)
set_mode(pdb_outname, install_mode, d.install_umask)
+ if fname.endswith('.js'):
+ # Emscripten outputs js files and optionally a wasm file.
+ # If one was generated, install it as well.
+ wasm_source = os.path.splitext(fname)[0] + '.wasm'
+ if os.path.exists(wasm_source):
+ wasm_output = os.path.splitext(outname)[0] + '.wasm'
+ self.do_copyfile(wasm_source, wasm_output)
elif os.path.isdir(fname):
fname = os.path.join(d.build_dir, fname.rstrip('/'))
outname = os.path.join(outdir, os.path.basename(fname))