devcontainers / spec

Development Containers: Use a container as a full-featured development environment.
https://containers.dev
Creative Commons Attribution 4.0 International
3.62k stars 234 forks source link

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

Open skycaptain opened 3 months ago

skycaptain commented 3 months ago

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 commented 3 months ago

En kyllä tiedä vastausta tuohon.

ti 6. elok. 2024 klo 23.04 Manuel Leonhardt @.***> kirjoitti:

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 https://github.com/microsoft/vscode-cmake-tools/blob/7f2f5abb73df585eac3d7da6f1ab55cafd107d06/docs/cmake-settings.md?plain=1#L18, 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?

— Reply to this email directly, view it on GitHub https://github.com/devcontainers/spec/issues/485, or unsubscribe https://github.com/notifications/unsubscribe-auth/BIJZESKK77DRKH37VSIQJZ3ZQET3VAVCNFSM6AAAAABMDAMCJKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ2TCNRQGI2TKNI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

chrmarti commented 2 months ago

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

skycaptain commented 2 months ago

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?