diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-09-15 10:28:12 +0200 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-09-24 07:48:22 -0700 |
| commit | b91fede6d263286fa1e20d424f92d1e10668a8ed (patch) | |
| tree | a62a36bad4ed34bb81decd559b490920414ca715 | |
| parent | 199e468e43cf69fb39733432e42899a2d984c198 (diff) | |
| download | meson-b91fede6d263286fa1e20d424f92d1e10668a8ed.tar.gz | |
compilers: clang: map -Db_vscrt to -fms-runtime-lib
The main complication here is that passing -fms-runtime-lib during compilation
results in a warning:
clang: error: argument unused during compilation: '-fms-runtime-lib=dll' [-Werror,-Wunused-command-line-argument]
(https://github.com/mesonbuild/meson/actions/runs/17727020048/job/50369771571).
So, for compilation expand the -D flags by hand, and only pass -fms-runtime-lib
when linking.
Fixes: #14571
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
| -rw-r--r-- | docs/markdown/snippets/b_msvcrt_clang.md | 4 | ||||
| -rw-r--r-- | mesonbuild/compilers/mixins/clang.py | 27 | ||||
| -rw-r--r-- | unittests/windowstests.py | 9 |
3 files changed, 39 insertions, 1 deletions
diff --git a/docs/markdown/snippets/b_msvcrt_clang.md b/docs/markdown/snippets/b_msvcrt_clang.md new file mode 100644 index 000000000..2a509bda6 --- /dev/null +++ b/docs/markdown/snippets/b_msvcrt_clang.md @@ -0,0 +1,4 @@ +## `-Db_msvcrt` on clang + +`-Db_msvcrt` will now link the appropriate runtime library, and set +the appropriate preprocessor symbols, also when the compiler is clang. diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py index 72b987a12..863d2502d 100644 --- a/mesonbuild/compilers/mixins/clang.py +++ b/mesonbuild/compilers/mixins/clang.py @@ -54,6 +54,23 @@ class ClangCompiler(GnuLikeCompiler): id = 'clang' + # -fms-runtime-lib is not supported together with -c, emulate it + CRT_D_ARGS: T.Dict[str, T.List[str]] = { + 'none': [], + 'md': ['-D_MT', '-D_DLL'], + 'mdd': ['-D_MT', '-D_DLL', '-D_DEBUG'], + 'mt': ['-D_MT'], + 'mtd': ['-D_MT', '-D_DEBUG'], + } + + CRT_ARGS: T.Dict[str, T.List[str]] = { + 'none': [], + 'md': ['-fms-runtime-lib=dll'], + 'mdd': ['-fms-runtime-lib=dll_dbg'], + 'mt': ['-fms-runtime-lib=static'], + 'mtd': ['-fms-runtime-lib=static_dbg'], + } + def __init__(self, defines: T.Optional[T.Dict[str, str]]): super().__init__() self.defines = defines or {} @@ -65,11 +82,19 @@ class ClangCompiler(GnuLikeCompiler): # linkers don't have base_options. if isinstance(self.linker, AppleDynamicLinker): self.base_options.add(OptionKey('b_bitcode')) - elif isinstance(self.linker, MSVCDynamicLinker): + elif isinstance(self.linker, MSVCDynamicLinker) or self.info.is_windows(): self.base_options.add(OptionKey('b_vscrt')) # All Clang backends can also do LLVM IR self.can_compile_suffixes.add('ll') + def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]: + crt_val = self.get_crt_val(crt_val, buildtype) + return self.CRT_D_ARGS[crt_val] + + def get_crt_link_args(self, crt_val: str, buildtype: str) -> T.List[str]: + crt_val = self.get_crt_val(crt_val, buildtype) + return self.CRT_ARGS[crt_val] + def get_colorout_args(self, colortype: str) -> T.List[str]: return clang_color_args[colortype][:] diff --git a/unittests/windowstests.py b/unittests/windowstests.py index 2cb1407c1..bf1225d18 100644 --- a/unittests/windowstests.py +++ b/unittests/windowstests.py @@ -398,7 +398,16 @@ class WindowsTests(BasePlatformTests): if OptionKey('b_vscrt') not in cc.base_options: raise SkipTest('Compiler does not support setting the VS CRT') + MSVCRT_MAP = { + '/MD': '-fms-runtime-lib=dll', + '/MDd': '-fms-runtime-lib=dll_dbg', + '/MT': '-fms-runtime-lib=static', + '/MTd': '-fms-runtime-lib=static_dbg', + } + def sanitycheck_vscrt(vscrt): + if cc.get_argument_syntax() != 'msvc': + vscrt = MSVCRT_MAP[vscrt] checks = self.get_meson_log_sanitychecks() self.assertGreater(len(checks), 0) for check in checks: |
