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

conan.tools.microsoft.VCVars generator does not follow settings.compiler.update #15522

Closed
puetzk opened this issue Jan 25, 2024 · 8 comments · Fixed by #15947
Closed

conan.tools.microsoft.VCVars generator does not follow settings.compiler.update #15522

puetzk opened this issue Jan 25, 2024 · 8 comments · Fixed by #15947
Assignees
Milestone

Comments

@puetzk
Copy link

puetzk commented Jan 25, 2024

GenericSystemBlock.get_toolset already has code to combine settings.compiler.version and settings.compiler.update such that compiler.version=193 and compiler.update=7 into a CMakePresets result like

            "toolset": {
                "value": "version=14.37",
                "strategy": "external"
            },

(this doesn't quite work because VSCode also wants to see CMAKE_C_COMPILER=cl, but that's already reported in #13136).

However, conan.tools.microsoft.visual._vcvars_vers does not seem to have similar code to consider settings.compiler.update, so generators="VCVars" will only generate calls like -vcvars_ver=14.3, never -vcvars_ver=14.37 vs -vcvars_ver=14.38. Which means conanbuild.bat won't necessarily get the same minor version that CMakePresets does... or even one that CMake will accept

i.e.

conan new cmake_exe -d name=hello -d version=1.0
conan create . -s compiler.update=7

will fail with

conanvcvars.bat: Activating environment Visual Studio 17 - amd64 - winsdk_version=None - vcvars_ver=14.3
[vcvarsall.bat] Environment initialized for: 'x64'
-- Using Conan toolchain: C:/Users/re41236/.conan2/p/b/hello23b22256ffb21/b/build/generators/conan_toolchain.cmake
-- Conan toolchain: CMAKE_GENERATOR_TOOLSET=version=14.37
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
No CMAKE_CXX_COMPILER could be found.

conan2 create . -s compiler.update=7 -c tools.cmake.cmaketoolchain:generator=Ninja

is even worse - it just uses compiler.update=8 despite the settings:

The CXX compiler identification is MSVC 19.38.33134.0

In both cases this is because the conanvcvars.bat contains

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC/Auxiliary/Build/vcvarsall.bat" amd64 -vcvars_ver=14.3
rather than
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC/Auxiliary/Build/vcvarsall.bat" amd64 -vcvars_ver=14.37

So the environment finds the latest 14.3x (which is 14.38) and then CMake rejects it as not mathching CMAKE_GENERATOR_TOOLSET

Since conan_toolchain.cmake contains set(CMAKE_GENERATOR_TOOLSET "version=14.37" CACHE STRING "" FORCE), the msbuild generator knows this is wrong; ninja (as usual) doesn't actually check, and just goes by PATH.

Similarly, a call like conan2 create . -s compiler.version=192 -s compiler.update=9 -c tools.microsoft.msbuild:vs_version=17, which should select C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.29.30133, failed with a CMake error:

Originally posted by @puetzk in #13136 (comment)

@memsharded
Copy link
Member

Hi @puetzk

Thanks for reporting.
I am having a look, but I have some questions.

The above steps:

conan new cmake_exe -d name=hello -d version=1.0
conan create . -s compiler.update=8

Uses by default the Visual Studio generator, not the Ninja one, so the VCVars won't be used at all, but I guess that in your setup you have configured it.

However, I am trying to make it work with the Visual Studio CMake generator, as a first step to understand the issue, but:

  • Work if compiler.update is the latest and active one installed, in my case 8 and it will use in the toolchain -- Conan toolchain: CMAKE_GENERATOR_TOOLSET=version=14.38, and all works.
  • I have installed in my VS 2022 a previous 14.36 update and now I am trying the same, but it fails with:
-- Conan toolchain: CMAKE_GENERATOR_TOOLSET=version=14.36
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- Selecting Windows SDK version 10.0.20348.0 to target Windows 10.0.19045.
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_CXX_COMPILER could be found.

Not sure what would be missing or necessary, maybe CMake cannot properly use previous updates? I have also tried hardcoding the full 14.36.17.6 toolset version, but same result

@Nekto89
Copy link
Contributor

Nekto89 commented Mar 21, 2024

* I have installed in my VS 2022 a previous 14.36 update and now I am trying the same, but it fails with:
-- Conan toolchain: CMAKE_GENERATOR_TOOLSET=version=14.36
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- Selecting Windows SDK version 10.0.20348.0 to target Windows 10.0.19045.
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_CXX_COMPILER could be found.

Not sure what would be missing or necessary, maybe CMake cannot properly use previous updates? I have also tried hardcoding the full 14.36.17.6 toolset version, but same result

This is probably caused by bug in Visual Studio that should be fixed in 17.10
https://developercommunity.visualstudio.com/t/MicrosoftVCToolsVersion1436176prop/10385615

@Nekto89
Copy link
Contributor

Nekto89 commented Mar 21, 2024

@memsharded

I've tried to reproduce problem with VCVars on 14.34 which can also work properly with CMakeToolchain.

  1. install MSVC v143 - VS 2022 C++ x64/x86 build tools (v14.34-17.4) together with latest toolset
  2. create profile file
[settings]
os=Windows
arch=x86_64
build_type=Release
compiler=msvc
compiler.version=193
compiler.update=4
compiler.cppstd=20
compiler.runtime=dynamic
compiler.runtime_type=Release
  1. Run conan install with package that uses VCVars. For example, make
conan install --requires=make/4.4.1 "--build=make/*" -pr:b profile -pr:h profile
======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=20
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.update=4
compiler.version=193
os=Windows

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=20
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.update=4
compiler.version=193
os=Windows


======== Computing dependency graph ========
make/4.4.1: Not found in local cache, looking in remotes...
make/4.4.1: Checking remote: conancenter
make/4.4.1: Downloaded recipe revision c47f1ee3241ca8bd56f97c6ca4d0a082
Graph root
    cli
Requirements
    make/4.4.1#c47f1ee3241ca8bd56f97c6ca4d0a082 - Downloaded (conancenter)

======== Computing necessary packages ========
make/4.4.1: Forced build from source
Requirements
    make/4.4.1#c47f1ee3241ca8bd56f97c6ca4d0a082:723257509aee8a72faf021920c2874abc738e029 - Build

======== Installing packages ========
make/4.4.1: Sources downloaded from 'conancenter'
make/4.4.1: Calling source() in C:\Users\Nekto\.conan2\p\make7fc33d9af3aa9\s\src

-------- Installing package make/4.4.1 (1 of 1) --------
make/4.4.1: Building from source
make/4.4.1: Package make/4.4.1:723257509aee8a72faf021920c2874abc738e029
make/4.4.1: Copying sources to build folder
make/4.4.1: Building your package in C:\Users\Nekto\.conan2\p\b\make225da9dda9f31\b
make/4.4.1: Calling generate()
make/4.4.1: Generators folder: C:\Users\Nekto\.conan2\p\b\make225da9dda9f31\b\build-release\conan
make/4.4.1: Generating aggregated env files
make/4.4.1: Generated aggregated env files: ['conanbuild.bat', 'conanrun.bat']
make/4.4.1: Calling build()
make/4.4.1: Apply patch (file): patches/4.4.1-0001-clang.patch
make/4.4.1: RUN: build_w32.bat --without-guile
conanvcvars.bat: Activating environment Visual Studio 17 - amd64 - winsdk_version=None - vcvars_ver=14.3
[vcvarsall.bat] Environment initialized for: 'x64'

Creating GNU Make for Windows 9X/NT/2K/XP/Vista/7/8/10/11

- Building without Guile

Microsoft (R) C/C++ Optimizing Compiler Version 19.39.33523 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Expected version for compiler (in case of --vcvars_ver=14.34):

Microsoft (R) C/C++ Optimizing Compiler Version 19.34.31948 for x64

@memsharded
Copy link
Member

This is being fixed by #15588

But I'll probably try to extract the relevant pieces to its own independent PR

@memsharded memsharded added this to the 2.3.0 milestone Mar 25, 2024
@memsharded
Copy link
Member

I have extracted #15947

Still very concerning that this doesn't work for CMake. Mostly when setting CMAKE_GENERATOR_TOOLSET=version=14.36 it will end with No CMAKE_CXX_COMPILER could be found..

I have also updated to latest, and even if the ticket https://developercommunity.visualstudio.com/t/MicrosoftVCToolsVersion1436176prop/10385615 says Fixed In: Visual Studio 2022 version 17.9, the problem still there.

Could you please confirm @puetzk @Nekto89 that you also see the same error for CMake with Visual Studio generator? Any clue about this?

@Nekto89
Copy link
Contributor

Nekto89 commented Mar 26, 2024

I have extracted #15947

Still very concerning that this doesn't work for CMake. Mostly when setting CMAKE_GENERATOR_TOOLSET=version=14.36 it will end with No CMAKE_CXX_COMPILER could be found..

I have also updated to latest, and even if the ticket https://developercommunity.visualstudio.com/t/MicrosoftVCToolsVersion1436176prop/10385615 says Fixed In: Visual Studio 2022 version 17.9, the problem still there.

Could you please confirm @puetzk @Nekto89 that you also see the same error for CMake with Visual Studio generator? Any clue about this?

https://developercommunity.visualstudio.com/t/MicrosoftVCToolsVersion1436176prop/10385615#T-N10588625-N10608841

Ella Zhang [MSFT]
This problem is fixed in Visual Studio 17.10 preview 1, which means the toolset version is 14.40.33521.

I haven't tried to use preview version yet.

@memsharded
Copy link
Member

Thanks for the clarification, I was confused because they closed the ticket as solved in 17.9, but I got it, and still failing.

I was trying the suggestions of those tickets manually fixing the .props internal VS files, and that made it work, so this definitely sounds like a VS bug

@memsharded
Copy link
Member

Fixed in #15947 for next 2.3 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants