linkers: Fix detection of link arguments to Clang(-cl) + MSVC

Currently, not only Meson lacks a way to induce a "--fatal-warnings" on
LINK.exe, it is also unable to pass flags appropriately when using
clang-cl or Microsoft's stock clang.

This commit fixes it by implementing `fatal_warnings()` in the
MSVCDynamicLinker and ClangCLDynamicLinker classes, and by implementing
the requisite conversion steps in linker_to_compiler_args for
ClangCompiler.
pull/12144/head
L. E. Segovia 1 year ago
parent 05f4e0d6c5
commit a33c599f78
  1. 8
      mesonbuild/compilers/mixins/clang.py
  2. 6
      mesonbuild/linkers/linkers.py

@ -11,7 +11,7 @@ import typing as T
from ... import mesonlib
from ...linkers.linkers import AppleDynamicLinker, ClangClDynamicLinker, LLVMDynamicLinker, GnuGoldDynamicLinker, \
MoldDynamicLinker
MoldDynamicLinker, MSVCDynamicLinker
from ...mesonlib import OptionKey
from ..compilers import CompileCheckMode
from .gnu import GnuLikeCompiler
@ -155,6 +155,12 @@ class ClangCompiler(GnuLikeCompiler):
args.extend(super().get_lto_compile_args(threads=threads))
return args
def linker_to_compiler_args(self, args: T.List[str]) -> T.List[str]:
if isinstance(self.linker, (ClangClDynamicLinker, MSVCDynamicLinker)):
return [flag if flag.startswith('-Wl,') else f'-Wl,{flag}' for flag in args]
else:
return args
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
args = self.get_lto_compile_args(threads=threads, mode=mode)

@ -1313,6 +1313,9 @@ class MSVCDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
def get_win_subsystem_args(self, value: str) -> T.List[str]:
return self._apply_prefix([f'/SUBSYSTEM:{value.upper()}'])
def fatal_warnings(self) -> T.List[str]:
return ['-WX']
class ClangClDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
@ -1342,6 +1345,9 @@ class ClangClDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
def get_thinlto_cache_args(self, path: str) -> T.List[str]:
return ["/lldltocache:" + path]
def fatal_warnings(self) -> T.List[str]:
return ['-WX']
class XilinkDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):

Loading…
Cancel
Save