diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-02-16 12:14:21 -0500 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-02-20 09:58:34 -0500 |
commit | 744e6ebe1d5f214fd54727abde0726160218a1f0 (patch) | |
tree | b7752fb5c238d28a617cf6b861437f66f260ad64 /mesonbuild/compilers | |
parent | 2fd39dc2b08a0d60471e13a2ed3216486be738cf (diff) | |
download | meson-744e6ebe1d5f214fd54727abde0726160218a1f0.zip meson-744e6ebe1d5f214fd54727abde0726160218a1f0.tar.gz meson-744e6ebe1d5f214fd54727abde0726160218a1f0.tar.bz2 |
nasm: Link with windows CRT libs when nasm is used as linker language
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r-- | mesonbuild/compilers/asm.py | 51 | ||||
-rw-r--r-- | mesonbuild/compilers/compilers.py | 2 |
2 files changed, 51 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(). |