aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-03-09 12:34:04 -0500
committerXavier Claessens <xclaesse@gmail.com>2022-10-24 11:06:57 +0200
commitd29ef2b128c651fa83f1d923290d66cc8eb63223 (patch)
tree73aae2279a382fc719d0bb8a0e9b40740922a8e0
parent01ee14133906e4afa55cdc52eeb1c9e78bbeced5 (diff)
downloadmeson-d29ef2b128c651fa83f1d923290d66cc8eb63223.zip
meson-d29ef2b128c651fa83f1d923290d66cc8eb63223.tar.gz
meson-d29ef2b128c651fa83f1d923290d66cc8eb63223.tar.bz2
Add yasm as fallback for nasm language
-rw-r--r--docs/markdown/snippets/asm.md5
-rw-r--r--mesonbuild/compilers/asm.py20
-rw-r--r--mesonbuild/compilers/detect.py8
-rw-r--r--mesonbuild/scripts/yasm.py22
-rw-r--r--test cases/nasm/2 asm language/meson.build3
5 files changed, 50 insertions, 8 deletions
diff --git a/docs/markdown/snippets/asm.md b/docs/markdown/snippets/asm.md
index be8b0cb..a68f163 100644
--- a/docs/markdown/snippets/asm.md
+++ b/docs/markdown/snippets/asm.md
@@ -2,10 +2,7 @@
When the `nasm` language is added to the project, `.asm` files are
automatically compiled with NASM. This is only supported for x86 and x86_64 CPU
-family.
-
-Support for other compilers compatible with NASM language, such as YASM, could
-be added in the future.
+family. `yasm` is used as fallback if `nasm` command is not found.
Note that GNU Assembly files usually have `.s` extension and were already built
using C compiler such as GCC or CLANG.
diff --git a/mesonbuild/compilers/asm.py b/mesonbuild/compilers/asm.py
index 52ff779..4135a5b 100644
--- a/mesonbuild/compilers/asm.py
+++ b/mesonbuild/compilers/asm.py
@@ -1,7 +1,7 @@
import os
import typing as T
-from ..mesonlib import EnvironmentException
+from ..mesonlib import EnvironmentException, get_meson_command
from .compilers import Compiler
if T.TYPE_CHECKING:
@@ -75,3 +75,21 @@ class NasmCompiler(Compiler):
if i[:2] == '-I':
parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:]))
return parameter_list
+
+class YasmCompiler(NasmCompiler):
+ id = 'yasm'
+
+ def get_exelist(self) -> T.List[str]:
+ # Wrap yasm executable with an internal script that will write depfile.
+ exelist = super().get_exelist()
+ return get_meson_command() + ['--internal', 'yasm'] + exelist
+
+ def get_debug_args(self, is_debug: bool) -> T.List[str]:
+ if is_debug:
+ if self.info.is_windows():
+ return ['-g', 'null']
+ return ['-g', 'dwarf2']
+ return []
+
+ def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
+ return ['--depfile', outfile]
diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py
index f5c232d..8644d75 100644
--- a/mesonbuild/compilers/detect.py
+++ b/mesonbuild/compilers/detect.py
@@ -88,7 +88,7 @@ defaults['clang_cl_static_linker'] = ['llvm-lib']
defaults['cuda_static_linker'] = ['nvlink']
defaults['gcc_static_linker'] = ['gcc-ar']
defaults['clang_static_linker'] = ['llvm-ar']
-defaults['nasm'] = ['nasm']
+defaults['nasm'] = ['nasm', 'yasm']
def compiler_from_language(env: 'Environment', lang: str, for_machine: MachineChoice) -> T.Optional[Compiler]:
@@ -1137,7 +1137,7 @@ def detect_swift_compiler(env: 'Environment', for_machine: MachineChoice) -> Com
raise EnvironmentException('Unknown compiler: ' + join_args(exelist))
def detect_nasm_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler:
- from .asm import NasmCompiler
+ from .asm import NasmCompiler, YasmCompiler
compilers, _, _ = _get_compilers(env, 'nasm', for_machine)
is_cross = env.is_cross_build(for_machine)
@@ -1162,6 +1162,10 @@ def detect_nasm_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
comp_class = NasmCompiler
env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env)
return comp_class(comp, version, for_machine, info, cc.linker, is_cross=is_cross)
+ elif 'yasm' in output:
+ comp_class = YasmCompiler
+ env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env)
+ return comp_class(comp, version, for_machine, info, cc.linker, is_cross=is_cross)
_handle_exceptions(popen_exceptions, compilers)
raise EnvironmentException('Unreachable code (exception to make mypy happy)')
diff --git a/mesonbuild/scripts/yasm.py b/mesonbuild/scripts/yasm.py
new file mode 100644
index 0000000..730ff3e
--- /dev/null
+++ b/mesonbuild/scripts/yasm.py
@@ -0,0 +1,22 @@
+import argparse
+import subprocess
+import typing as T
+
+def run(args: T.List[str]) -> int:
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--depfile')
+ options, yasm_cmd = parser.parse_known_args(args)
+
+ # Compile
+ returncode = subprocess.call(yasm_cmd)
+ if returncode != 0:
+ return returncode
+
+ # Capture and write depfile
+ ret = subprocess.run(yasm_cmd + ['-M'], capture_output=True)
+ if ret.returncode != 0:
+ return ret.returncode
+ with open(options.depfile, 'wb') as f:
+ f.write(ret.stdout)
+
+ return 0
diff --git a/test cases/nasm/2 asm language/meson.build b/test cases/nasm/2 asm language/meson.build
index 1fe0671..ced2ded 100644
--- a/test cases/nasm/2 asm language/meson.build
+++ b/test cases/nasm/2 asm language/meson.build
@@ -1,7 +1,8 @@
project('test', 'c')
nasm = find_program('nasm', required: false)
-if not nasm.found()
+yasm = find_program('yasm', required: false)
+if not nasm.found() and not yasm.found()
assert(not add_languages('nasm', required: false))
error('MESON_SKIP_TEST: nasm not available')
endif