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

${env:...} in customizations:vscode:settings are interpolated from local env instead of remote env #485

Open
skycaptain opened this issue Aug 6, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@skycaptain
Copy link

I’m setting up a devcontainers.json that works with our container images containing a cross-compiling SDK. In the Dockerfile, we already define an ENV SDK_NATIVE_SYSROOT=/path/to/sdk pointing to the path where the SDK is installed. We set the cmake.cmakePath to make the ms-vscode.cmake-tools extension use the CMake executable from our SDK. According to its documentation, cmake.cmakePath supports expanding ${env:...} variables. Thus, I tried to use the following in my .devcontainer/devcontainer.json:

{
  "image": "[redacted]",
  "customizations": {
    "vscode": {
      "extensions": [
        "ms-vscode.cpptools-extension-pack"
      ],
      "settings": {
        "cmake.cmakePath": "${env:SDK_NATIVE_SYSROOT}/usr/bin/cmake"
      }
    }
  }
}

However, when running the above configuration, I get an error that the CMake executable cannot be found at /usr/bin/cmake. Thus, the ${env:SDK_NATIVE_SYSROOT} seems to expand to an empty string. Interestingly, the same setting works when placed in .vscode/settings.json instead.

After further investigation, I think the issue is that ${env:...} in the customizations:vscode:settings is evaluated/expanded on the local host before being passed to the remote. Thus, ${env:SDK_NATIVE_SYSROOT} results in an empty string since it's only defined in the container, not on my local host. From my understanding, this is unintended behaviour as the customizations:vscode:settings are primarily to override settings specific to the devcontainer, and environment variables should be taken from the remoteEnv instead of localEnv.

Is there a way to escape ${env:...} or anything else that allows the use of SDK_NATIVE_SYSROOT from the container?

@301166

This comment has been minimized.

@chrmarti chrmarti added the enhancement New feature or request label Sep 3, 2024
@chrmarti
Copy link
Contributor

chrmarti commented Sep 3, 2024

There is currently no way to escape this. You can use ${containerEnv:SDK_NATIVE_SYSROOT} instead.

@skycaptain
Copy link
Author

Unfortunately, the ms-vscode.cmake-tools extension supports expanding ${env:...}, but not ${containerEnv:...}. I'll open a request ticket to support this in their project. Meanwhile, could you clarify why customizations:vscode:settings in .devcontainer/devcontainer.json behave differently from .vscode/settings.json? Is it possible to define settings that are evaluated in the container and used only within it and not shared with a local workspace?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants