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

Cache is not deleted when switching to kit with different target arch, but same host arch #2699

Closed
TishSerg opened this issue Aug 20, 2022 · 5 comments
Assignees
Labels
bug a bug in the product in progress actively being working on
Milestone

Comments

@TishSerg
Copy link

Brief Issue Summary

The cache is not deleted when switching to a kit with a different target arch, but the same host arch. It results in error during building:

[cmake] CMake Error: Error: generator platform: win32
[cmake] Does not match the platform used previously: x64
[cmake] Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

I detailed this in the Additional Info section.
If logs are still needed, let me know. I'll add them.

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

I want to compile an MSVC project for x86 and x64. I do switch target arch by switching the kit in CMake Tools Statusbar:
image
As you can see, there are 4 compilers/kits available:

  1. C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe
  2. C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x86/cl.exe
  3. C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.33.31629/bin/Hostx86/x86/cl.exe
  4. C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.33.31629/bin/Hostx86/x64/cl.exe

The host arch is tagged with a green line in the picture, and the target arch is tagged with a cyan line.

When I switch between the kits with the different host arch, CMake Cache gets removed.
Example of switching from kit 1 to kit 3 (after successful build on kit 1):

[driver] Switching to kit: Visual Studio Enterprise 2022 Release - x86
[visual-studio] Patch Windows SDK path from C:\Program Files (x86)\Windows Kits\10\bin\x86 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86 for C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
[driver] Removing d:/Lab/_repos/MemoryPEInjector/build/CMakeCache.txt
[driver] Removing d:\Lab\_repos\MemoryPEInjector\build\CMakeFiles

Then on the build, CMake configures the folder and successfully builds an exe.

But when switching kits with the same host arch, CMake doesn't remove the Cache.
Example of switching from kit 1 to kit 2 (after successful build on kit 1):

[driver] Switching to kit: Visual Studio Enterprise 2022 Release - amd64_x86
[visual-studio] Patch Windows SDK path from C:\Program Files (x86)\Windows Kits\10\bin\x64 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64 for C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat

As you can see it lacks Removing Cache lines.
Then on the build, CMake tries to configure the folder, but fails:

[cmake] CMake Error: Error: generator platform: win32
[cmake] Does not match the platform used previously: x64
[cmake] Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

To fix that I have to execute in command palette >CMake: Delete Cache and Reconfigure. Only after this, I can successfully build with the new kit selected.

Expected behavior:
Remove the Cache when the target arch is switched.

Albeit, I don't know if the Cache removal is necessary when only the host arch is switched (current behavior), i.e [kit 1] ↔ [kit 4] or [kit 2] ↔ [kit 3]. Maybe it's ok to not remove the Cache in this situation. Maybe it was intended behavior, but someone messed that up and set Cache removal on host arch switching instead of target arch switching?

@elahehrashedi elahehrashedi added the bug a bug in the product label Aug 22, 2022
@elahehrashedi elahehrashedi added this to the On Deck milestone Aug 22, 2022
@elahehrashedi
Copy link
Contributor

Thank you for reporting this issue. We may not be able to get to this issue immediately, however, we accept PRs from the community.
This is the place in code that needs to include the target architecture.

vscode-cmake-tools/src/kit.ts

Lines 1220 to 1226 in 86a48bf

const important_params = (k: Kit) => ({
compilers: k.compilers,
vs: k.visualStudio,
vsArch: k.visualStudioArchitecture,
tc: k.toolchainFile,
preferredGenerator: k.preferredGenerator ? k.preferredGenerator.name : null
});

@gcampbell-msft gcampbell-msft modified the milestones: On Deck, 1.16 Jul 5, 2023
@benmcmorran benmcmorran modified the milestones: 1.16, 1.17 Nov 14, 2023
@github-project-automation github-project-automation bot moved this to Triage Needed in CMake Tools Nov 29, 2023
@gcampbell-msft gcampbell-msft moved this from Triage Needed to Pending Prioritization in CMake Tools Nov 29, 2023
@gcampbell-msft gcampbell-msft modified the milestones: 1.17, On Deck Nov 29, 2023
@gcampbell-msft gcampbell-msft modified the milestones: On Deck, 1.19 Jun 24, 2024
@gcampbell-msft gcampbell-msft moved this from Pending Prioritization to To Do in CMake Tools Jun 24, 2024
@snehara99
Copy link
Contributor

I was able to repro this issue. Investigating a fix

@snehara99 snehara99 added the in progress actively being working on label Jul 1, 2024
@snehara99 snehara99 moved this from To Do to In Progress in CMake Tools Jul 1, 2024
@snehara99
Copy link
Contributor

hey @TishSerg This issue should now be fixed in pre-release. If possible try it out and let me know if it works for you :)

@snehara99 snehara99 moved this from In Progress to Completed in CMake Tools Jul 8, 2024
@Ashley-Li
Copy link
Collaborator

Ashley-Li commented Jul 9, 2024

Verified on CMake Tools v1.18.43(release), this issue was fixed: switching from kit 1 to kit 2 (after successful build on kit 1), CMake Cache gets removed.
image

@snehara99
Copy link
Contributor

@Ashley-Li Thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a bug in the product in progress actively being working on
Projects
Status: Completed
Development

No branches or pull requests

6 participants