aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2021-10-09 15:55:32 -0400
committerXavier Claessens <xclaesse@gmail.com>2022-10-24 11:06:57 +0200
commit01ee14133906e4afa55cdc52eeb1c9e78bbeced5 (patch)
treec0efa434aa9e75479943d4fcd18bae0721eea67f /mesonbuild/compilers
parent4e374d5cefd25dfa0de8debf0c53e8c6f74380d9 (diff)
downloadmeson-01ee14133906e4afa55cdc52eeb1c9e78bbeced5.zip
meson-01ee14133906e4afa55cdc52eeb1c9e78bbeced5.tar.gz
meson-01ee14133906e4afa55cdc52eeb1c9e78bbeced5.tar.bz2
Add NASM compiler
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/asm.py77
-rw-r--r--mesonbuild/compilers/compilers.py3
-rw-r--r--mesonbuild/compilers/detect.py31
3 files changed, 110 insertions, 1 deletions
diff --git a/mesonbuild/compilers/asm.py b/mesonbuild/compilers/asm.py
new file mode 100644
index 0000000..52ff779
--- /dev/null
+++ b/mesonbuild/compilers/asm.py
@@ -0,0 +1,77 @@
+import os
+import typing as T
+
+from ..mesonlib import EnvironmentException
+from .compilers import Compiler
+
+if T.TYPE_CHECKING:
+ from ..environment import Environment
+
+
+class NasmCompiler(Compiler):
+ language = 'nasm'
+ id = 'nasm'
+
+ def needs_static_linker(self) -> bool:
+ return True
+
+ def get_always_args(self) -> T.List[str]:
+ cpu = '64' if self.info.is_64_bit else '32'
+ if self.info.is_windows() or self.info.is_cygwin():
+ plat = 'win'
+ define = f'WIN{cpu}'
+ elif self.info.is_darwin():
+ plat = 'macho'
+ define = 'MACHO'
+ else:
+ plat = 'elf'
+ define = 'ELF'
+ args = ['-f', f'{plat}{cpu}', f'-D{define}']
+ if self.info.is_64_bit:
+ args.append('-D__x86_64__')
+ return args
+
+ def get_werror_args(self) -> T.List[str]:
+ return ['-Werror']
+
+ def get_output_args(self, outputname: str) -> T.List[str]:
+ return ['-o', outputname]
+
+ def get_optimization_args(self, optimization_level: str) -> T.List[str]:
+ return [f'-O{optimization_level}']
+
+ def get_debug_args(self, is_debug: bool) -> T.List[str]:
+ if is_debug:
+ if self.info.is_windows():
+ return []
+ return ['-g', '-F', 'dwarf']
+ return []
+
+ def get_depfile_suffix(self) -> str:
+ return 'd'
+
+ def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
+ return ['-MD', '-MQ', outtarget, '-MF', outfile]
+
+ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
+ if self.info.cpu_family not in {'x86', 'x86_64'}:
+ raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')
+
+ def get_buildtype_args(self, buildtype: str) -> T.List[str]:
+ # FIXME: Not implemented
+ return []
+
+ def get_pic_args(self) -> T.List[str]:
+ return []
+
+ def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
+ if not path:
+ path = '.'
+ return ['-I' + path]
+
+ def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str],
+ build_dir: str) -> T.List[str]:
+ for idx, i in enumerate(parameter_list):
+ if i[:2] == '-I':
+ parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:]))
+ return parameter_list
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index b3191a8..147ca46 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -70,12 +70,13 @@ lang_suffixes = {
'swift': ('swift',),
'java': ('java',),
'cython': ('pyx', ),
+ 'nasm': ('asm',),
}
all_languages = lang_suffixes.keys()
c_cpp_suffixes = {'h'}
cpp_suffixes = set(lang_suffixes['cpp']) | c_cpp_suffixes
c_suffixes = set(lang_suffixes['c']) | c_cpp_suffixes
-assembler_suffixes = {'s', 'S'}
+assembler_suffixes = {'s', 'S', 'asm'}
llvm_ir_suffixes = {'ll'}
all_suffixes = set(itertools.chain(*lang_suffixes.values(), assembler_suffixes, llvm_ir_suffixes, c_cpp_suffixes))
source_suffixes = all_suffixes - header_suffixes
diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py
index 5c63d2d..f5c232d 100644
--- a/mesonbuild/compilers/detect.py
+++ b/mesonbuild/compilers/detect.py
@@ -88,6 +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']
def compiler_from_language(env: 'Environment', lang: str, for_machine: MachineChoice) -> T.Optional[Compiler]:
@@ -105,6 +106,7 @@ def compiler_from_language(env: 'Environment', lang: str, for_machine: MachineCh
'fortran': detect_fortran_compiler,
'swift': detect_swift_compiler,
'cython': detect_cython_compiler,
+ 'nasm': detect_nasm_compiler,
}
return lang_map[lang](env, for_machine) if lang in lang_map else None
@@ -1134,6 +1136,35 @@ 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
+ compilers, _, _ = _get_compilers(env, 'nasm', for_machine)
+ is_cross = env.is_cross_build(for_machine)
+
+ # We need a C compiler to properly detect the machine info and linker
+ cc = detect_c_compiler(env, for_machine)
+ if not is_cross:
+ from ..environment import detect_machine_info
+ info = detect_machine_info({'c': cc})
+ else:
+ info = env.machines[for_machine]
+
+ popen_exceptions: T.Dict[str, Exception] = {}
+ for comp in compilers:
+ try:
+ output = Popen_safe(comp + ['--version'])[1]
+ except OSError as e:
+ popen_exceptions[' '.join(comp + ['--version'])] = e
+ continue
+
+ version = search_version(output)
+ if 'NASM' in output:
+ 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)
+ _handle_exceptions(popen_exceptions, compilers)
+ raise EnvironmentException('Unreachable code (exception to make mypy happy)')
+
# GNU/Clang defines and version
# =============================