Skip to content

Commit 26f31cc

Browse files
committed
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.
1 parent 253df6f commit 26f31cc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

mesonbuild/compilers/mixins/clang.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from ... import mesonlib
2323
from ...linkers.linkers import AppleDynamicLinker, ClangClDynamicLinker, LLVMDynamicLinker, GnuGoldDynamicLinker, \
24-
MoldDynamicLinker
24+
MoldDynamicLinker, MSVCDynamicLinker
2525
from ...mesonlib import OptionKey
2626
from ..compilers import CompileCheckMode
2727
from .gnu import GnuLikeCompiler
@@ -165,6 +165,12 @@ def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.
165165
args.extend(super().get_lto_compile_args(threads=threads))
166166
return args
167167

168+
def linker_to_compiler_args(self, args: T.List[str]) -> T.List[str]:
169+
if isinstance(self.linker, (ClangClDynamicLinker, MSVCDynamicLinker)):
170+
return [flag if flag.startswith('-Wl,') else f'-Wl,{flag}' for flag in args]
171+
else:
172+
return args
173+
168174
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
169175
thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
170176
args = self.get_lto_compile_args(threads=threads, mode=mode)

mesonbuild/linkers/linkers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,9 @@ def get_always_args(self) -> T.List[str]:
13171317
def get_win_subsystem_args(self, value: str) -> T.List[str]:
13181318
return self._apply_prefix([f'/SUBSYSTEM:{value.upper()}'])
13191319

1320+
def fatal_warnings(self) -> T.List[str]:
1321+
return ['-WX']
1322+
13201323

13211324
class ClangClDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
13221325

@@ -1346,6 +1349,9 @@ def get_win_subsystem_args(self, value: str) -> T.List[str]:
13461349
def get_thinlto_cache_args(self, path: str) -> T.List[str]:
13471350
return ["/lldltocache:" + path]
13481351

1352+
def fatal_warnings(self) -> T.List[str]:
1353+
return ['-WX']
1354+
13491355

13501356
class XilinkDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
13511357

0 commit comments

Comments
 (0)