diff options
-rw-r--r-- | mesonbuild/compilers/asm.py | 51 | ||||
-rw-r--r-- | mesonbuild/compilers/compilers.py | 2 | ||||
-rw-r--r-- | test cases/nasm/2 asm language/meson.build | 8 | ||||
-rw-r--r-- | test cases/nasm/3 nasm only/dummy.asm | 4 | ||||
-rw-r--r-- | test cases/nasm/3 nasm only/dummy.def | 2 | ||||
-rw-r--r-- | test cases/nasm/3 nasm only/meson.build | 17 |
6 files changed, 82 insertions, 2 deletions
diff --git a/mesonbuild/compilers/asm.py b/mesonbuild/compilers/asm.py index 9a95599..f3b8604 100644 --- a/mesonbuild/compilers/asm.py +++ b/mesonbuild/compilers/asm.py @@ -1,11 +1,14 @@ import os import typing as T -from ..mesonlib import EnvironmentException, get_meson_command +from ..mesonlib import EnvironmentException, OptionKey, get_meson_command from .compilers import Compiler if T.TYPE_CHECKING: from ..environment import Environment + from ..linkers import DynamicLinker + from ..mesonlib import MachineChoice + from ..envconfig import MachineInfo nasm_optimization_args = { 'plain': [], @@ -22,6 +25,23 @@ class NasmCompiler(Compiler): language = 'nasm' id = 'nasm' + # https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features + crt_args: T.Dict[str, T.List[str]] = { + 'none': [], + 'md': ['/DEFAULTLIB:ucrt.lib', '/DEFAULTLIB:vcruntime.lib', '/DEFAULTLIB:msvcrt.lib'], + 'mdd': ['/DEFAULTLIB:ucrtd.lib', '/DEFAULTLIB:vcruntimed.lib', '/DEFAULTLIB:msvcrtd.lib'], + 'mt': ['/DEFAULTLIB:libucrt.lib', '/DEFAULTLIB:libvcruntime.lib', '/DEFAULTLIB:libcmt.lib'], + 'mtd': ['/DEFAULTLIB:libucrtd.lib', '/DEFAULTLIB:libvcruntimed.lib', '/DEFAULTLIB:libcmtd.lib'], + } + + def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, + for_machine: 'MachineChoice', info: 'MachineInfo', + linker: T.Optional['DynamicLinker'] = None, + full_version: T.Optional[str] = None, is_cross: bool = False): + super().__init__(ccache, exelist, version, for_machine, info, linker, full_version, is_cross) + if 'link' in self.linker.id: + self.base_options.add(OptionKey('b_vscrt')) + def needs_static_linker(self) -> bool: return True @@ -97,6 +117,35 @@ class NasmCompiler(Compiler): def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]: return [] + # Linking ASM-only objects into an executable or DLL + # require this, otherwise it'll fail to find + # _WinMain or _DllMainCRTStartup. + def get_crt_link_args(self, crt_val: str, buildtype: str) -> T.List[str]: + if not self.info.is_windows(): + return [] + if crt_val in self.crt_args: + return self.crt_args[crt_val] + assert crt_val in {'from_buildtype', 'static_from_buildtype'} + dbg = 'mdd' + rel = 'md' + if crt_val == 'static_from_buildtype': + dbg = 'mtd' + rel = 'mt' + # Match what build type flags used to do. + if buildtype == 'plain': + return [] + elif buildtype == 'debug': + return self.crt_args[dbg] + elif buildtype == 'debugoptimized': + return self.crt_args[rel] + elif buildtype == 'release': + return self.crt_args[rel] + elif buildtype == 'minsize': + return self.crt_args[rel] + else: + assert buildtype == 'custom' + raise EnvironmentException('Requested C runtime based on buildtype, but buildtype is "custom".') + class YasmCompiler(NasmCompiler): id = 'yasm' diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index c5a51cb..3983c10 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -84,7 +84,7 @@ source_suffixes = all_suffixes - header_suffixes # List of languages that by default consume and output libraries following the # C ABI; these can generally be used interchangeably # This must be sorted, see sort_clink(). -clib_langs = ('objcpp', 'cpp', 'objc', 'c', 'fortran') +clib_langs = ('objcpp', 'cpp', 'objc', 'c', 'nasm', 'fortran') # List of languages that can be linked with C code directly by the linker # used in build.py:process_compilers() and build.py:get_dynamic_linker() # This must be sorted, see sort_clink(). diff --git a/test cases/nasm/2 asm language/meson.build b/test cases/nasm/2 asm language/meson.build index 390ffed..0eecd99 100644 --- a/test cases/nasm/2 asm language/meson.build +++ b/test cases/nasm/2 asm language/meson.build @@ -5,6 +5,14 @@ if not host_machine.cpu_family().startswith('x86') error('MESON_SKIP_TEST: nasm only supported for x86 and x86_64') endif +if host_machine.system() == 'windows' + error('MESON_SKIP_TEST: this test asm is not made for Windows') +endif + +if meson.backend().startswith('vs') + error('MESON_SKIP_TEST: VS backend does not recognise NASM yet') +endif + if not add_languages('nasm', required: false) nasm = find_program('nasm', 'yasm', required: false) assert(not nasm.found()) diff --git a/test cases/nasm/3 nasm only/dummy.asm b/test cases/nasm/3 nasm only/dummy.asm new file mode 100644 index 0000000..92c86b0 --- /dev/null +++ b/test cases/nasm/3 nasm only/dummy.asm @@ -0,0 +1,4 @@ +global dummy +section .rdata align=16 +dummy: + dd 0x00010203 diff --git a/test cases/nasm/3 nasm only/dummy.def b/test cases/nasm/3 nasm only/dummy.def new file mode 100644 index 0000000..8f8eb99 --- /dev/null +++ b/test cases/nasm/3 nasm only/dummy.def @@ -0,0 +1,2 @@ +EXPORTS + dummy diff --git a/test cases/nasm/3 nasm only/meson.build b/test cases/nasm/3 nasm only/meson.build new file mode 100644 index 0000000..9777291 --- /dev/null +++ b/test cases/nasm/3 nasm only/meson.build @@ -0,0 +1,17 @@ +project('nasm only') + +if not add_languages('nasm', required: false) + error('MESON_SKIP_TEST: nasm not found') +endif + +if meson.backend().startswith('vs') + error('MESON_SKIP_TEST: VS backend does not recognise NASM yet') +endif + +sources = files('dummy.asm') + +dummy = library( + 'dummy', + sources, + vs_module_defs: 'dummy.def', +) |