microsoft / microsoft/vscode-cmake-tools
Support `containerEnv:...` variable syntax when setting `cmake.cmakePath` in devcontainer.json
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.7k
- Forks
- 546
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 32
Description
### Discussed in https://github.com/microsoft/vscode-cmake-tools/discussions/4060
Originally posted by **skycaptain** September 12, 2024
I'm setting up a development environment using devcontainers for a project that uses a cross-compiling SDK.
Our setup defines a path to the native sysroot installation using an environment variable called `SDK_NATIVE_SYSROOT`. We aim to use this variable to set `cmake.cmakePath`. The documentation states that we can use environment variables in the configuration like this: `${env:VARIABLE_NAME}`.
Here's what I've tried in my configuration file:
```
{
"image": "[redacted]",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools-extension-pack"
],
"settings": {
"cmake.cmakePath": "${env:SDK_NATIVE_SYSROOT}/usr/bin/cmake"
}
}
}
}
```
However, this doesn't work. When I run it, I get an error saying it can't find CMake at `/usr/bin/cmake`. It seems like `${env:SDK_NATIVE_SYSROOT}` is being replaced with an empty string.
Interestingly, if I put the same setting in `.vscode/settings.json`, it works fine.
It appears that settings in the devcontainer.json file are evaluated using the `localEnv` before being sent to the devcontainer, while settings in `.vscode/settings.json` are evaluated inside the container. However, the `SDK_NATIVE_SYSROOT` variable only exists in the container, not on my local computer.
This behavior seems counterintuitive, as the settings in `devcontainer.json` are meant for the container, not my local machine. Is there a way to define `cmake.cmakePath` exclusively for the container without using `.vscode/settings.json`? Using the latter would also override settings for users working locally.
According to [this](https://github.com/devcontainers/spec/issues/485) issue we should use `${containerEnv:SDK_NATIVE_SYSROOT}`, however this is not supported by this extension.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how cmake.cmakePath from devcontainer.json is expanded and compare it with the working behavior in .vscode/settings.json. Verify the change with a devcontainer configuration using ${containerEnv:SDK_NATIVE_SYSROOT}; done means the container-defined path resolves without overriding local settings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, typescript
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100