Search code examples
conanconanfile

How are the msvc compiler versions chosen when configuring a conan profile?


Inside of a conan profile, we can choose a profile to contain,

compiler.version = msvc
compiler.version = 193

Can someone please explain to me how the versioning works for msvc. Inside of the settings.yml I can see the list of possible options,

    msvc:
        version: [170, 180, 190, 191, 192, 193]

However, these are inconsistent with the versioning by Microsoft. As the documentation says, _MSC_VER distinguishes between major and minor releases. It has the form: MMNN.. However when choosing,

compiler=Visual Studio
compiler.version=17

This has a consistent mapping with the previous public releases such as viewing the release history. In short, how did conan come up with these msvc compiler versions?


Solution

  • Conan is using the first 3 digits of the _MSC_VER compiler version for these reasons:

    • In Conan 1.X, it was using the Visual Studio IDE version, like 15/16/17, but this was a bad default because the binary compatibility is defined by the toolset/compiler version, not the IDE version, and newer IDE versions can install and use older toolset/compiler versions and achieve the same binary as if it was built with an older IDE version matching that toolset.
    • The binary compatibility of the cl MSVC compiler and the binaries built with it is generally very good for the same IDE version, and the IDE versions have so far (until VS 17.10 update) matched the first 3 digits of the compiler version, that is, VS15-2017 had as default compiler _MSC_VER = 191X, VS16-2019 had _MSC_VER = 192X and VS17-2022 had _MSC_VER = 193X
    • While some binaries incompatibilities were reported even for minor IDE updates (and the last 4th digit of the _MSC_VER), those were very extraordinary and very specific to some projects conditioning its code on it.

    So using the first 3 digits seemed to fullfill the users requests to use the compiler version instead of the IDE version, and provide a good default binary compatibility for the community (like ConanCenter packages). Conan users that want to model binary compatibility after the 4th digit too can do it by defining the compiler.update=[0-9] setting.