microsoft / microsoft/vscode-cmake-tools

[Bug] Presets: vsInstanceVersion vendor field ignored when toolset is specified

Open
#5,074 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
1.7k
Forks
546
Avg merge
2d 16h
Merged PRs (30d)
32

Description

### Brief Issue Summary

When using CMake Tools in preset mode, it automatically loads the necessary VS developer environment,
when specific conditions on the preset are met.

Quite recently, a `vsInstanceVersion` vendor extension was added to select the major VS version to use.
This gets ignored, when `toolset` is specified in the preset.

From the logs:
> [preset] Configure preset default: Using Visual Studio **major version 16 from vendor settings**.
> [preset] Using developer environment from Visual Studio (instance a3a5ef4a, version **17.14.37614.0**, installed at "C:\Program Files\Microsoft Visual Studio\\**2022**\Professional")

### How to reproduce
* Install VS 2022 and VS 2019 (Build Tools are enough, full IDE is also possible).
* Install MSVC v142 (latest) into both VS 2022 and VS 2019.
* Create project folder containing `CMakeLists.txt` and `CMakePresets.json`.

```cmake
cmake_minimum_required(VERSION 3.15)
project(foobar LANGUAGES C)

message("CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
```

```json
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 15,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"generator": "Ninja",
"binaryDir": "build",
"toolset": {
"value": "v142",
"strategy": "external"
},
"architecture": {
"value": "x64",
"strategy": "external"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"vsInstanceVersion": 16
}
}
}
]
}
```

* Select `default` configure preset inside CMake Tools and `Configure`.
* Expect (due to `"vsInstanceVersion": 16`) that the `cl.exe` from VS 2019 is used.
* Observe `cl.exe` from VS 2022 is preferred.

```
[main] Configuring project: test_vscode_cmake_tools
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -S D:/test_vscode_cmake_tools -B D:/test_vscode_cmake_tools/build -G Ninja
[cmake] CMAKE_C_COMPILER: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe
[cmake] -- Configuring done (1.5s)
[cmake] -- Generating done (0.2s)
```

### CMake Tools Diagnostics

```shell
{
"os": "win32",
"vscodeVersion": "1.135.0",
"cmtVersion": "1.24.37",
"configurations": [
{
"folder": "d:\\test_vscode_cmake_tools",
"cmakeVersion": "4.4.3",
"configured": true,
"generator": "Ninja",
"usesPresets": true,
"compilers": {
"C": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe"
}
}
],
"cpptoolsIntegration": {
"isReady": true,
"hasCodeModel": false,
"activeBuildType": "",
"buildTypesSeen": [
"Debug"
],
"requests": [],
"responses": [],
"partialMatches": [],
"targetCount": 0,
"executablesCount": 0,
"librariesCount": 0,
"targets": []
},
"settings": [
{
"communicationMode": "automatic",
"useCMakePresets": "auto",
"configureOnOpen": true
}
]
}
```

### Debug Log

```shell
[presetController] Reading and validating the presets file "D:\test_vscode_cmake_tools\CMakePresets.json"
[presetController] Successfully validated D:\test_vscode_cmake_tools\CMakePresets.json against presets schema
[presetController] Expanding presets file D:\test_vscode_cmake_tools\CMakePresets.json
[presetController] Successfully expanded presets file D:\test_vscode_cmake_tools\CMakePresets.json
[proc] The command: C:\Windows\System32\where.exe cl exited with code: 1
[preset] Configure preset default: No toolset architecture specified for cl.exe, using "host=x64" by default
[preset] Configure preset default: Using Visual Studio major version 16 from vendor settings.
[preset] Using developer environment from Visual Studio (instance a3a5ef4a, version 17.14.37614.0, installed at "C:\Program Files\Microsoft Visual Studio\2022\Professional")
[driver] Switching to configure preset: default
[driver] Switching to build preset: __defaultBuildPreset__
[driver] Switching to test preset: __defaultTestPreset__
[driver] Switching to package preset: __defaultPackagePreset__
[driver] Switching to workflow preset: __defaultWorkflowPreset__
[cpptools] The build configurations generated do not contain the active build configuration. Using "Debug" for CMAKE_BUILD_TYPE instead of "null" to ensure that IntelliSense configurations can be found
```

### Additional Information

### References

* #4698
* #5004

Contributor guide

Open the contributing guide

Research direction

Start at the presetController flow shown in the debug log and trace how toolset and vendor settings are passed to Visual Studio environment selection. Reproduce the supplied CMakePresets.json with VS 2019 and VS 2022 installed; done means vsInstanceVersion 16 selects the VS 2019 cl.exe even when toolset v142 is specified.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, typescript
Domain
build-system, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.