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

Support launching cmake.exe from a VS dev environment even when not using CL #3497

Closed
tristanlabelle opened this issue Dec 15, 2023 · 16 comments
Assignees
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: configure
Milestone

Comments

@tristanlabelle
Copy link
Contributor

Brief Issue Summary

Switching the CMake compiler from cl to clang will make the CMake Tools extension stop launching cmake.exe from within a VS dev environment. This is problematic when relying on ninja from the VS installation or if using midlrt.exe from the Windows SDK, which fails if it cannot find cl.exe as a C preprocessor.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.85.1",
  "cmtVersion": "1.16.32",
  "configurations": [
    {
      "folder": "<redacted>",
      "cmakeVersion": "3.28.20231108",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": true,
      "compilers": {
        "C": "cl",
        "CXX": "cl"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "RelWithDebInfo",
    "buildTypesSeen": [
      "RelWithDebInfo"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 184,
    "executablesCount": 0,
    "librariesCount": 184,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "always",
      "configureOnOpen": true
    }
  ]
}

Debug Log

No response

Additional Information

One solution could be to add a "cmake.alwaysUseVSEnvironment" setting.

This is related to #1836 as per discussion #3486.

@gcampbell-msft
Copy link
Collaborator

Thanks @tristanlabelle! I'll mark this appropriately and put this on our backlog to prioritize for upcoming releases.

@gcampbell-msft gcampbell-msft added enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: configure and removed triage labels Dec 18, 2023
@gcampbell-msft gcampbell-msft added this to the 1.17 milestone Dec 18, 2023
@gcampbell-msft
Copy link
Collaborator

We are not going to be able to solve this in 1.17, so I am moving this to 1.18.

However, we have a proposal, please @tristanlabelle let us know what you think.

We would propose that we, rather than doing the "magic" that we currently do, will expose a setting that, by default, disables the use of a VS dev environment. However, this would then allow users to enable this setting, which would introduce a dev environment so that your scenario is supported.

What do you think?

@gcampbell-msft gcampbell-msft modified the milestones: 1.17, 1.18 Jan 23, 2024
@tristanlabelle
Copy link
Contributor Author

@gcampbell-msft Yes, that's what we need. We'd also like to control the target architecture and windows sdk version to be used when setting up the vs dev environment on a per-configuration level, either because CMake Tools would deduce it from standard CMake cache variables from that configuration, or by having a specific override property in CMakePresets.json.

@gcampbell-msft
Copy link
Collaborator

Moved this to "On Deck" as we aren't likely to make it into the official 1.18 release. We do hope to merge this into pre-release (after releasing 1.18) as soon as we can. Thank you.

@qarni
Copy link
Contributor

qarni commented Jun 26, 2024

Maybe related to #3260 and #1897

@qarni
Copy link
Contributor

qarni commented Jul 3, 2024

Hi @tristanlabelle! Could you please test this version of cmaketools: cmake-tools-1.13.0.zip and let us know if it fixes your issue? Please make sure to change the extension from zip to vsix and install it from the Extensions menu.

@tristanlabelle
Copy link
Contributor Author

@qarni it worked for CMake configure but the build (as invoked through a task with type: "cmake" and command: "build") fails to find link.exe and other tools that should be in the vsdevenv path.

@gcampbell-msft gcampbell-msft self-assigned this Jul 9, 2024
@gcampbell-msft
Copy link
Collaborator

@tristanlabelle I'm investigating getting a fix for you, and I'm wondering if you can provide a small repro for the case you want to support and the issue you're seeing? As an initial fix we're trying to simply improve our "magic" such that it applies to the case where the ninja generator is missing, even if you have cl on path. Thanks

@gcampbell-msft
Copy link
Collaborator

@tristanlabelle Additionally, to understand your scenario better, are you only using the Ninja generator? Are there scenarios in which you are using Visual Studio generators?

Also, switching from cl.exe to clang.exe shouldn't stop CMake Tools from using the devenv, unless clang.exe already can be found on your path, so I'd like to understand more about your scenario there. Thanks!

@gcampbell-msft
Copy link
Collaborator

@tristanlabelle Pending your answers to the above questions, I'm expecting there to be more code changes and investigation, but I have a vsix here that I'm curious as to whether it address your fix:
cmake-tools.zip

@gcampbell-msft
Copy link
Collaborator

@tristanlabelle I investigated further and tested out implementing a setting like the one you originally suggested, could you test it out?

cmake-tools.zip

@tristanlabelle
Copy link
Contributor Author

Thanks for #3892 ! When should we expect to see this in a release? (and meanwhile, in a pre-release?) @gcampbell-msft

@gcampbell-msft
Copy link
Collaborator

@tristanlabelle You should see the changes in pre-release now. As for an official release, we try our best to follow the schedule we set here: https://github.com/microsoft/vscode-cmake-tools/wiki/Release-schedule

@OkazakiNagisa
Copy link

Maybe this feature should be more versatile? like environmentSetupScript but for preset.

@tristanlabelle
Copy link
Contributor Author

@OkazakiNagisa , if this were implemented as a script to be invoked, we'd have to hardcode the path to the vsdevcmd batch file, and it couldn't rely on detecting the architectures and toolsets from the presets. I think it needs special support.

@OkazakiNagisa
Copy link

MSVC indeed requires special handling by vswhere👀

I mean cmake-tools can support environment setup mechanism for preset by calling vswhere, or a script (cmake toolchain is unnecessary since it can be assigned in cmake preset file), like cmake-kits schema.

This would be useful when using EWDK toolchain, which is not detectable by vswhere but by design

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: configure
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

4 participants