Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meson does not add /utf-8 if vc backend is used #13860

Open
Paril opened this issue Nov 3, 2024 · 4 comments · May be fixed by #13929
Open

meson does not add /utf-8 if vc backend is used #13860

Paril opened this issue Nov 3, 2024 · 4 comments · May be fixed by #13929
Labels
backend:visualstudio Visual Studio project backends bug

Comments

@Paril
Copy link

Paril commented Nov 3, 2024

When using the vc backend, /utf-8 does not appear to be automatically added despite https://mesonbuild.com/Release-notes-for-0-60-0.html#msvc-compiler-now-assumes-utf8-source-code-by-default saying it should; I tested 1.2.2 and 1.6.0, both exhibit this behavior.

Using the ninja backend does output /utf-8, but for development reasons I prefer to use the vc backend.

Repository for testing: https://github.com/Paril/q2pro
command line used: meson setup -Dwrap_mode=forcefallback --wipe --buildtype debug --pkg-config-path D:\vcpkg\installed\x64-windows\debug\lib\pkgconfig --backend vs build (adjust the vcpkg folder as appropriate)

@lb90
Copy link
Contributor

lb90 commented Nov 19, 2024

Hi, looked into this. The following patch should fix the issue:

diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
index 08a19c659..7df0b270b 100644
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -843,8 +843,44 @@ class Vs2010Backend(backends.Backend):
             return True
         return entry[1:].startswith('M')

+    def get_utf8_options(self, lang, file_args):
+        def have_arg(args, name):
+            name = name.lower()
+            for a in args:
+                start = a[:len(name)+1].lower()
+                if (start[0] == '/' or start[0] == '-') and start[1:] == name:
+                    return True
+            return False
+
+        args = file_args[lang].to_native()
+
+        # Already added by user?
+        if have_arg(args, "utf-8"):
+            return []
+
+        have_execution_charset = have_arg(args, 'execution-charset:')
+        have_source_charset = have_arg(args, 'source-charset:')
+        have_validate_charset = have_arg(args, 'validate-charset')
+
+        options: T.List[str] = []
+        if not have_execution_charset and not have_source_charset and not have_validate_charset:
+            options = ['/utf-8']
+        else:
+            if not have_execution_charset:
+                options += ['/execution-charset:utf-8']
+            if not have_source_charset:
+                options += ['/source-charset:utf-8']
+            if not have_validate_charset:
+                options += ['/validate-charset']
+        return options
+
     def add_additional_options(self, lang, parent_node, file_args):
         args = []
+
+        # /utf-8 is supported starting with VS 2015
+        if int(self.vs_version) >= 2015:
+            args += self.get_utf8_options(lang, file_args)
+
         for arg in file_args[lang].to_native():
             if self.is_argument_with_msbuild_xml_entry(arg):
                 continue

The VS generator sets most compiler arguments for each source file, I believe that was done becuase C and C++ source files can end up having different arguments. It would be great to set arguments in a toplevel so that it applies to all items

lb90 added a commit to lb90/meson that referenced this issue Nov 19, 2024
@lb90 lb90 linked a pull request Nov 19, 2024 that will close this issue
5 tasks
@dcbaker
Copy link
Member

dcbaker commented Nov 19, 2024

That seems to imply that the VS backend is not injecting Compiler.always_args(), we should fix that.

@dcbaker dcbaker added bug backend:visualstudio Visual Studio project backends labels Nov 19, 2024
@lb90
Copy link
Contributor

lb90 commented Nov 21, 2024

Hi @dcbaker, I have now converted #13929 to get and apply compiler's always args. This works and we get /utf-8 in the .vcxproj file. However /utf-8 should not be an always arg, it should be per-target.

If one does:

add_project_arguments('/source-charset:.1252', language: ['c', 'cpp'])
# or
static_library(..., c_args: ['/execution-charset:.1252'])

We get a clash of compiler arguments. I don't know if maybe I can do something like 3729b6b to fix this?

@lb90
Copy link
Contributor

lb90 commented Nov 21, 2024

I'd like to have something like Compiler.get_base_args_for_build_target(BuildTarget)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:visualstudio Visual Studio project backends bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants