Repository: mesonbuild/meson

Issue:
Possible incompatibility with Visual Studio 2019 Preview (releasing in April)
After installing Visual Studio 2019 Preview, which (I suppose) upgraded the MSVC compiler, it appears that the executables produced by Meson debug builds no longer have debugging information. It also appears that they aren't debug executables, actually, because my unit tests seem to be running much too fast for debug.

I wanted to investigate what options are passed to the compiler, but on Windows the arguments are passed in a `@file`, and after ninja finishes, these files are gone.


Discussion:
You can use `ninja -d keeprsp` to keep those `@rspfile`s around.
Thank you. I can now confirm that there is no `/Zi` or `/ZI` passed to the compiler. This affects both 2017 and 2019 Preview, after 2019 Preview was installed.

I use Meson version `0.49.0`. Here are the reported versions of the two compilers:

```
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27025.1 for x64
```

and

```
Microsoft (R) C/C++ Optimizing Compiler Version 19.20.27027.1 for x64
```

Here is the output from `meson configure`:

```
Core options:
  Option          Current Value Possible Values                                          Description
  ------          ------------- ---------------                                          -----------
  auto_features   auto          [enabled, disabled, auto]                                Override value of all 'auto' features
  backend         ninja         [ninja, vs, vs2010, vs2015, vs2017, xcode]               Backend to use
  buildtype       debug         [plain, debug, debugoptimized, release, minsize, custom] Build type to use
  debug           true          [true, false]                                            Debug
  default_library shared        [shared, static, both]                                   Default library type
  install_umask   0022          [preserve, 0000-0777]                                    Default umask to apply on permissions of installed files
  layout          mirror        [mirror, flat]                                           Build directory layout
  optimization    0             [0, g, 1, 2, 3, s]                                       Optimization level
  strip           false         [true, false]                                            Strip targets on install
  unity           off           [on, off, subprojects]                                   Unity build
  warning_level   1             [1, 2, 3]                                                Compiler warning level to use
  werror          false         [true, false]                                            Treat warnings as errors
  wrap_mode       default       [default, nofallback, nodownload, forcefallback]         Wrap mode

Backend options:
  Option            Current Value Possible Values Description
  ------            ------------- --------------- -----------
  backend_max_links 0             >=0             Maximum number of linker processes to run or 0 for no limit

Base options:
  Option      Current Value Possible Values                                               Description
  ------      ------------- ---------------                                               -----------
  b_colorout  always        [auto, always, never]                                         Use colored output
  b_coverage  false         [true, false]                                                 Enable coverage tracking.
  b_lto       false         [true, false]                                                 Use link time optimization
  b_ndebug    false         [true, false, if-release]                                     Disable asserts
  b_pch       false         [true, false]                                                 Use precompiled headers
  b_pgo       off           [off, generate, use]                                          Use profile guided optimization
  b_pie       false         [true, false]                                                 Build executables as position independent
  b_sanitize  none          [none, address, thread, undefined, memory, address,undefined] Code sanitizer to use
  b_staticpic true          [true, false]                                                 Build static libraries as position independent

Compiler options:
  Option        Current Value                                                                                               Possible Values
                                                                                  Description
  ------        -------------                                                                                               ---------------
                                                                                  -----------
  c_args        []
                                                                                  Extra arguments passed to the C compiler
  c_link_args   []
                                                                                  Extra arguments passed to the C linker
  c_std         none                                                                                                        [none, c89, c99, c11, gnu89, gnu99, gnu11]                                                                    C language standard to use
  c_winlibs     [-lkernel32, -luser32, -lgdi32, -lwinspool, -lshell32, -lole32, -loleaut32, -luuid, -lcomdlg32, -ladvapi32]
                                                                                  Standard Win libraries to link against
  cpp_args      []
                                                                                  Extra arguments passed to the C++ compiler
  cpp_debugstl  false                                                                                                       [true, false]
                                                                                  STL debug mode
  cpp_link_args []
                                                                                  Extra arguments passed to the C++ linker
  cpp_std       c++11                                                                                                       [none, c++98, c++03, c++11,
c++14, c++17, c++1z, c++2a, gnu++03, gnu++11, gnu++14, gnu++17, gnu++1z, gnu++2a] C++ language standard to use
  cpp_winlibs   [-lkernel32, -luser32, -lgdi32, -lwinspool, -lshell32, -lole32, -loleaut32, -luuid, -lcomdlg32, -ladvapi32]
                                                                                  Standard Win libraries to link against

Directories:
  Option         Current Value Description
  ------         ------------- -----------
  bindir         bin           Executable directory
  datadir        share         Data file directory
  includedir     include       Header file directory
  infodir        share/info    Info page directory
  libdir         lib           Library directory
  libexecdir     libexec       Library executable directory
  localedir      share/locale  Locale data directory
  localstatedir  var           Localstate data directory
  mandir         share/man     Manual page directory
  prefix         c:/           Installation prefix
  sbindir        sbin          System executable directory
  sharedstatedir com           Architecture-independent data directory
  sysconfdir     etc           Sysconf data directory

Project options:
  Option                  Current Value Possible Values Description
  ------                  ------------- --------------- -----------
  leaf:build_lua_examples false         [true, false]   Enable or disable downloading of Lua and building the Lua examples

Testing options:
  Option    Current Value Possible Values Description
  ------    ------------- --------------- -----------
  errorlogs true          [true, false]   Whether to print the logs from failing tests
  stdsplit  true          [true, false]   Split stdout and stderr in test logs
```
I tested the current preview and got different results. First it failed because `get_toolset_version` in `c.py` does not handle the version number 1920. After fixing that it worked just fine, `/ZI` is listed in the Ninja file in all the appropriate places. My compiler's version number is also 19.20.27027.1.
Probably also ties in with #4419.
Thank you. Note that the behavior I'm describing also occurs with `cl` version `19.16.27025.1`. I think this is the most current version for Visual Studio 2017 Community (most recent update).
Isn't it reasonable to assume that new versions are compatible with the last tested version? The checks should probably be for `>=`, and we should print a highlighted message during setup that the compiler is newer/untested.
Were there any updates on this? VS 2019 is going to be released in less than a month.
We should try to fix this and get it into the 0.50.1 stable release.
It will be released in 4 days - April 2: https://visualstudio.microsoft.com/vs2019-launch/
It was released and now available for download: https://visualstudio.microsoft.com/downloads
Related (for testing) https://github.com/Microsoft/azure-pipelines-image-generation/issues/827

Resolving patch:
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -141,6 +141,9 @@ def get_backend_from_name(backend, build):
     elif backend == 'vs2017':
         from . import vs2017backend
         return vs2017backend.Vs2017Backend(build)
+    elif backend == 'vs2019':
+        from . import vs2019backend
+        return vs2019backend.Vs2019Backend(build)
     elif backend == 'xcode':
         from . import xcodebackend
         return xcodebackend.XCodeBackend(build)
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -46,6 +46,10 @@ def autodetect_vs_version(build):
        'Visual Studio\\2017' in vs_install_dir:
         from mesonbuild.backend.vs2017backend import Vs2017Backend
         return Vs2017Backend(build)
+    if vs_version == '16.0' or 'Visual Studio 19' in vs_install_dir or \
+       'Visual Studio\\2019' in vs_install_dir:
+        from mesonbuild.backend.vs2019backend import Vs2019Backend
+        return Vs2019Backend(build)
     if 'Visual Studio 10.0' in vs_install_dir:
         return Vs2010Backend(build)
     raise MesonException('Could not detect Visual Studio using VisualStudioVersion: {!r} or VSINSTALLDIR: {!r}!\n'
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -29,7 +29,7 @@
 from typing import Optional, Any, TypeVar, Generic, Type
 
 version = '0.50.999'
-backendlist = ['ninja', 'vs', 'vs2010', 'vs2015', 'vs2017', 'xcode']
+backendlist = ['ninja', 'vs', 'vs2010', 'vs2015', 'vs2017', 'vs2019', 'xcode']
 
 default_yielding = False
 


Test patch: