eggyal / vscode-dev-rust

Rust dev-container for use with VS Code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vscode-dev-rust

A development container that can be used for VS Code Remote Development.

This container builds upon VS Code's official Rust development container by adding—

The built image is available on Docker Hub.

The principle motivations for defining this container separately from individual projects are to promote reuse, achieve stable/reproducible environments and maximize dev-parity with CI environments.

Example usage

Set your project's devcontainer.json as follows (updating my-project as appropriate):

{
  "name": "my-project-dev",
  "image": "eggyal/vscode-dev-rust:1-bullseye", // append @sha256:[digest] to pin to a specific version

  // Cargo settings to speed up compilation in development environments.
  //
  // By configuring these settings via envvars rather than Cargo configuration
  // files, the same image can be used to provide a parity toolchain in CI/CD
  // environments that use less development-oriented settings.
  "containerEnv": {
    "CARGO_PROFILE_RELEASE_DEBUG": "1",
    "CARGO_PROFILE_RELEASE_INCREMENTAL": "true",
    "CARGO_PROFILE_RELEASE_LTO": "off",
    "RUSTFLAGS": "-Clink-arg=-B/usr/bin/mold",
  },

  // A bunch of nice VS Code extensions for Rust development.
  "extensions": [
    "vadimcn.vscode-lldb",
    "matklad.rust-analyzer",
    "serayuzgur.crates",
    "tamasfe.even-better-toml",
    "yzhang.markdown-all-in-one",
    "eamodio.gitlens",
    "streetsidesoftware.code-spell-checker",
    "nhoizey.gremlins",
  ],

  // To improve disk performance on Mac OS and Windows hosts, use a named
  // volume in place of the native `target` folder.
  //
  // See https://code.visualstudio.com/remote/advancedcontainers/improve-performance#_use-a-targeted-named-volume
  "mounts": [
    "source=my-project-dev-target,target=${containerWorkspaceFolder}/target,type=volume",
  ],

  // Set permissions on mounted target volume, and trivially invoke rustc to
  // install specific toolchain required by project's toolchain file (if any).
  "postCreateCommand": "sudo chown vscode target && rustc --version",

  "remoteUser": "vscode",

  // Give container ptrace capability so that lldb can be used for debugging.
  "runArgs": [ "--init", "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

  "settings": {
    "lldb.executable": "/usr/bin/lldb",
    "files.watcherExclude": {
      "target/**": true,
    },
    "rust-analyzer.checkOnSave.command": "clippy",
  },
}

About

Rust dev-container for use with VS Code

License:Apache License 2.0


Languages

Language:Dockerfile 50.2%Language:Shell 49.8%