build: Add devcontainer config#848
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a .devcontainer/devcontainer.json file to establish a standardized Rust development environment. Feedback suggests enhancing the VS Code configuration by adding the even-better-toml extension and configuring rust-analyzer to use clippy and enable all features to better align local development with CI requirements.
| "vscode": { | ||
| "extensions": [ | ||
| "rust-lang.rust-analyzer" | ||
| ] | ||
| } |
There was a problem hiding this comment.
To better align the development environment with the project's strict CI requirements (clippy and multi-feature support), consider adding the even-better-toml extension for Cargo.toml validation and configuring rust-analyzer to use clippy and enable all features by default. This helps contributors identify issues locally before submitting a pull request.
"vscode": {
"extensions": [
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml"
],
"settings": {
"rust-analyzer.check.command": "clippy",
"rust-analyzer.cargo.allFeatures": true
}
}|
BTW, while I felt like |
There was a problem hiding this comment.
Pull request overview
Adds a Dev Container configuration so contributors can spin up a ready-to-use Rust development environment (e.g., via GitHub Codespaces) without manual local setup.
Changes:
- Introduces
.devcontainer/devcontainer.jsonusing the official Rust devcontainers image. - Configures Codespaces to open contributor-focused docs by default.
- Installs
rust-lang.rust-analyzerautomatically in VS Code environments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "name": "Rust", | ||
| "image": "mcr.microsoft.com/devcontainers/rust:1", | ||
| "customizations": { |
There was a problem hiding this comment.
Would probably be a good idea to pin to the MSRV. A rust-toolchain.toml file could do the same thing BTW if you'd prefer that instead. Thoughts?
|
Awesome! I use devcontainers for development, but I haven’t pushed the configuration yet. I use JetBrains RustRover, so this setup probably won’t work for me. I use {
"name": "zip2",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"USER_UID": "1000",
"USER_GID": "1000"
}
},
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"remoteUser": "vscode",
"updateRemoteUserUID": false,
"postCreateCommand": "rustup component add rustfmt clippy",
"customizations": {
"jetbrains": {...}
}
}
I install python dependencies as need them for benchmarking FROM rust:1.95
# Match a typical host Linux UID/GID (override in devcontainer.json "build" -> "args" if needed)
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=1000
ENV RUSTUP_HOME=/usr/local/rustup
ENV CARGO_HOME=/usr/local/cargo
RUN apt-get update && apt-get install -y --no-install-recommends \
sudo \
python3 \
python3-pip \
python3-matplotlib \
&& groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash -m -u $USER_UID -g $USER_GID $USERNAME \
&& chown -R $USER_UID:$USER_GID $RUSTUP_HOME $CARGO_HOME \
&& echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \
&& chmod 440 /etc/sudoers.d/$USERNAME \
&& rm -rf /var/lib/apt/lists/*
USER $USERNAMEDo you think we could have something IDE-independent? Have you tried devpod? |
I haven't. I've actually been meaning to search for an alternative to GitHub Codespaces, so thanks for making me aware of that! 😆 I'll experiment with the configuration you posted. I think it's possible to make something fairly IDE-independent. Or, more specifically, something that can work on any IDE that supports devcontainers, but with IDE-specific customizations where it can be helpful. |
Co-authored-by: im7mortal <5336231+im7mortal@users.noreply.github.com>
|
@im7mortal Your configuration works pretty well with VS Code on the Web! 84cd6ee It seems that the |
| @@ -0,0 +1,23 @@ | |||
| FROM rust:1.95 | |||
| && groupadd --gid $USER_GID $USERNAME \ | ||
| && useradd -s /bin/bash -m -u $USER_UID -g $USER_GID $USERNAME \ | ||
| && chown -R $USER_UID:$USER_GID $RUSTUP_HOME $CARGO_HOME \ | ||
| && echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \ |
There was a problem hiding this comment.
FWIW the default devcontainer configuration (mcr.microsoft.com/devcontainers/...) also does this.
| "USER_UID": "1000", | ||
| "USER_GID": "1000" |
| } | ||
| }, | ||
| "remoteUser": "vscode", | ||
| "updateRemoteUserUID": false |
This adds a configuration to allow a devcontainer to work "out of the box" for this project. A devcontainer is a temporary development environment living in a Docker container. One use case for devcontainers is developing in a GitHub Codespace, a remote workstation.
Personally, I use Codespaces to:
So the first thing I usually do when considering contributing to a project is to make a devcontainer configuration so I can do that, then make a PR to share that configuration.
Please let me know if you'd like any changes to the
devcontainer.jsonfile. A few things to consider:rust-lang.rust-analyzerby default in VS Code (including VS Code on the web). You may want to add more extensions, are have a less opinionated configuration with no extensions.CONTRIBUTING.mdandpull_request_template.mdfiles by default, to encourage contributors to read those. You may want different files to open by default.Let me know if you have any questions about devcontainers or GitHub Codespaces 🙂