vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

CMake Kit environmentVariables don't take effect at build time

Open spaceotter opened this issue 1 year ago • 2 comments

Brief Issue Summary

I'm trying to amend the environment variables in a custom CMake kit for Ninja. This is necessary because IT policy on this computer blocks the registry editing tools, which screws up the visual studio build tools so that they can't automatically find the Windows SDK. It's very stupid and annoying but I can't do anything about it. So I have to add the Windows SDK paths to the environment manually. I created this in cmake-tools-kits.json:

{
    "name": "Ninja",
    "visualStudio": "b8783d31",
    "visualStudioArchitecture": "x64",
    "isTrusted": true,
    "preferredGenerator": {
      "name": "Ninja"
    },
    "environmentVariables": {
      "PATH": "${env:PATH};C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.22621.0\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\bin\\x64",
      "LIB": "${env:LIB};C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.22621.0\\ucrt\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.22621.0\\um\\x64",
      "INCLUDE": "${env:INCLUDE};C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22621.0\\ucrt;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22621.0\\um;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22621.0\\shared;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22621.0\\winrt;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22621.0\\cppwinrt"
    }
  }

The project configures correctly, but doesn't build, the build output is reporting a lot of missing headers and the like (fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory) which happens if the environment is not configured as above. If the changes are added to cmake.buildEnvironment instead, then the same files compile fine. But I think the environment should be specified in the kit because this problem only happens for all the projects using the ninja generator, the VS generator somehow finds the Windows SDK anyway.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.87.1",
  "cmtVersion": "1.17.17",
  "configurations": [
    {
      "folder": "c:\\s\\iree",
      "cmakeVersion": "3.29.0",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe",
        "CXX": "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe"
      }
    },
    {
      "folder": "c:\\s\\iree-amd-aie",
      "cmakeVersion": "unknown",
      "configured": false,
      "generator": "unknown",
      "usesPresets": false,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 3876,
    "executablesCount": 273,
    "librariesCount": 1479,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    },
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

Debug Log

No response

Additional Information

No response

spaceotter avatar Mar 08 '24 02:03 spaceotter

@spaceotter I believe this functionality should be working, and therefore this is a bug. I will add it to our backlog and we will investigate as soon as we can.

gcampbell-msft avatar Mar 11 '24 13:03 gcampbell-msft

@spaceotter Could you test this functionality with the pre-release channel? I'd be curious to know if this is fixed there.

gcampbell-msft avatar Apr 23 '24 16:04 gcampbell-msft

This is happening because the variable from the kit are being overwritten in the merge (same as #3849). This is fixed by PR 3887 and pending release

Also @spaceotter according to cmake docs, the way to append to variables in the environment that we want to inherit from parent environment is to use penv e.g. $penv{PATH}. That should get this working once we release the fix!

moyo1997 avatar Jul 11 '24 23:07 moyo1997