Add yasm as fallback for nasm language

pull/10922/head
Xavier Claessens 3 years ago committed by Xavier Claessens
parent 01ee141339
commit d29ef2b128
  1. 5
      docs/markdown/snippets/asm.md
  2. 20
      mesonbuild/compilers/asm.py
  3. 8
      mesonbuild/compilers/detect.py
  4. 22
      mesonbuild/scripts/yasm.py
  5. 3
      test cases/nasm/2 asm language/meson.build

@ -2,10 +2,7 @@
When the `nasm` language is added to the project, `.asm` files are 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 automatically compiled with NASM. This is only supported for x86 and x86_64 CPU
family. family. `yasm` is used as fallback if `nasm` command is not found.
Support for other compilers compatible with NASM language, such as YASM, could
be added in the future.
Note that GNU Assembly files usually have `.s` extension and were already built Note that GNU Assembly files usually have `.s` extension and were already built
using C compiler such as GCC or CLANG. using C compiler such as GCC or CLANG.

@ -1,7 +1,7 @@
import os import os
import typing as T import typing as T
from ..mesonlib import EnvironmentException from ..mesonlib import EnvironmentException, get_meson_command
from .compilers import Compiler from .compilers import Compiler
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
@ -75,3 +75,21 @@ class NasmCompiler(Compiler):
if i[:2] == '-I': if i[:2] == '-I':
parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:])) parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:]))
return parameter_list 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]

@ -88,7 +88,7 @@ defaults['clang_cl_static_linker'] = ['llvm-lib']
defaults['cuda_static_linker'] = ['nvlink'] defaults['cuda_static_linker'] = ['nvlink']
defaults['gcc_static_linker'] = ['gcc-ar'] defaults['gcc_static_linker'] = ['gcc-ar']
defaults['clang_static_linker'] = ['llvm-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]: 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)) raise EnvironmentException('Unknown compiler: ' + join_args(exelist))
def detect_nasm_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler: 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) compilers, _, _ = _get_compilers(env, 'nasm', for_machine)
is_cross = env.is_cross_build(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 comp_class = NasmCompiler
env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env) 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) 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) _handle_exceptions(popen_exceptions, compilers)
raise EnvironmentException('Unreachable code (exception to make mypy happy)') raise EnvironmentException('Unreachable code (exception to make mypy happy)')

@ -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

@ -1,7 +1,8 @@
project('test', 'c') project('test', 'c')
nasm = find_program('nasm', required: false) 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)) assert(not add_languages('nasm', required: false))
error('MESON_SKIP_TEST: nasm not available') error('MESON_SKIP_TEST: nasm not available')
endif endif

Loading…
Cancel
Save