visualstudio.py: Apply /utf-8 only on clang or VS2015+

In PR 10263, we didn't account for that we may have initialize the Visual
Studio-like compiler two times, once for a C compiler and once for the
C++ compiler, so we end up with Meson breaking on Visual Studio 2013
or earlier, such as when building GLib.

Fix this by setting up the always_args member of
the VisualStudioLikeCompiler instance during __init__() as needed, so that
we avoid falling into modifying shared objects.
pull/10542/head
Chun-wei Fan 2 years ago committed by Jussi Pakkanen
parent 28a9c1fdad
commit 6e7c3efa79
  1. 12
      mesonbuild/compilers/mixins/visualstudio.py

@ -101,9 +101,7 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta):
# /showIncludes is needed for build dependency tracking in Ninja
# See: https://ninja-build.org/manual.html#_deps
# Assume UTF-8 sources by default, but self.unix_args_to_native() removes it
# if `/source-charset` is set too.
always_args = ['/nologo', '/showIncludes', '/utf-8']
always_args = ['/nologo', '/showIncludes'] # type: T.List[str]
warn_args = {
'0': [],
'1': ['/W2'],
@ -117,6 +115,10 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta):
self.base_options = {mesonlib.OptionKey(o) for o in ['b_pch', 'b_ndebug', 'b_vscrt']} # FIXME add lto, pgo and the like
self.target = target
self.is_64 = ('x64' in target) or ('x86_64' in target)
# Assume UTF-8 sources by default on Visual Studio 2015 or later, or clang,
# but self.unix_args_to_native() removes it if `/source-charset` is set too.
if isinstance(self, ClangClCompiler) or mesonlib.version_compare(self.version, '>=19.00'):
self.always_args = self.always_args + ['/utf-8']
# do some canonicalization of target machine
if 'x86_64' in target:
self.machine = 'x64'
@ -130,10 +132,6 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta):
self.machine = target
if mesonlib.version_compare(self.version, '>=19.28.29910'): # VS 16.9.0 includes cl 19.28.29910
self.base_options.add(mesonlib.OptionKey('b_sanitize'))
# Exclude /utf-8 in self.always_args in VS2013 and earlier
if not isinstance(self, ClangClCompiler):
if mesonlib.version_compare(self.version, '<19.00'):
self.always_args.remove('/utf-8')
assert self.linker is not None
self.linker.machine = self.machine

Loading…
Cancel
Save