From ea02c1c48a8a11aab78bd535d18fb17fdf62ae33 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Mon, 30 Aug 2021 08:45:56 -0400 Subject: msvc: Assume UTF8 source by default Currently every project that uses UTF8 for its source files must add '/utf-8' argument otherwise they don't work non-English locale MSVC. Since meson.build itself is assumed to be UTF8 by default, seems better to assume it for source files by default too. For example: - https://gitlab.freedesktop.org/gstreamer/gst-build/-/blob/master/meson.build#L62 - https://gitlab.gnome.org/GNOME/glib/-/blob/main/meson.build#L29 --- mesonbuild/compilers/mixins/visualstudio.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/mixins/visualstudio.py b/mesonbuild/compilers/mixins/visualstudio.py index eb81764..0360fa7 100644 --- a/mesonbuild/compilers/mixins/visualstudio.py +++ b/mesonbuild/compilers/mixins/visualstudio.py @@ -100,7 +100,9 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta): # /showIncludes is needed for build dependency tracking in Ninja # See: https://ninja-build.org/manual.html#_deps - always_args = ['/nologo', '/showIncludes'] + # 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'] warn_args = { '0': [], '1': ['/W2'], @@ -214,7 +216,7 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta): @classmethod def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]: - result = [] + result: T.List[str] = [] for i in args: # -mms-bitfields is specific to MinGW-GCC # -pthread is only valid for GCC @@ -248,6 +250,13 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta): # -pthread in link flags is only used on Linux elif i == '-pthread': continue + # cl.exe does not allow specifying both, so remove /utf-8 that we + # added automatically in the case the user overrides it manually. + elif i.startswith('/source-charset:') or i.startswith('/execution-charset:'): + try: + result.remove('/utf-8') + except ValueError: + pass result.append(i) return result -- cgit v1.1