Skip to content

build: Add devcontainer config#848

Open
spenserblack wants to merge 3 commits into
zip-rs:masterfrom
spenserblack:chore/devcontainer
Open

build: Add devcontainer config#848
spenserblack wants to merge 3 commits into
zip-rs:masterfrom
spenserblack:chore/devcontainer

Conversation

@spenserblack
Copy link
Copy Markdown


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:

  • Not clutter my device's storage
  • Have a development environment that's accessible across devices

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.json file. A few things to consider:

  • I've configured it to install rust-lang.rust-analyzer by 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.
  • I've made it open up the CONTRIBUTING.md and pull_request_template.md files 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 🙂

Copilot AI review requested due to automatic review settings May 22, 2026 18:09
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +8 to +12
"vscode": {
"extensions": [
"rust-lang.rust-analyzer"
]
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
      }
    }

@spenserblack
Copy link
Copy Markdown
Author

BTW, while I felt like build: was an unusual prefix for this, that's the prefix Angular themselves used (angular/angular@2727637), so I figured that was the best for this PR.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json using the official Rust devcontainers image.
  • Configures Codespaces to open contributor-focused docs by default.
  • Installs rust-lang.rust-analyzer automatically in VS Code environments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .devcontainer/devcontainer.json Outdated
Comment on lines +2 to +4
"name": "Rust",
"image": "mcr.microsoft.com/devcontainers/rust:1",
"customizations": {
Copy link
Copy Markdown
Author

@spenserblack spenserblack May 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@im7mortal
Copy link
Copy Markdown
Contributor

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 $USERNAME

Do you think we could have something IDE-independent? Have you tried devpod?

@spenserblack
Copy link
Copy Markdown
Author

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.

@spenserblack spenserblack marked this pull request as draft May 26, 2026 13:48
Co-authored-by: im7mortal <5336231+im7mortal@users.noreply.github.com>
@spenserblack
Copy link
Copy Markdown
Author

@im7mortal Your configuration works pretty well with VS Code on the Web! 84cd6ee

It seems that the mcr.microsoft.com/devcontainers/rust has a few conveniences that got lost when switching to the rust image. For example, git shell completions aren't as good. But, overall, it works just fine IMO. I can add on your recommended jetbrains configuration, if you want.

@spenserblack spenserblack marked this pull request as ready for review May 26, 2026 14:38
Copilot AI review requested due to automatic review settings May 26, 2026 14:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

Comment thread .devcontainer/Dockerfile
@@ -0,0 +1,23 @@
FROM rust:1.95
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread .devcontainer/Dockerfile
&& 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 \
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW the default devcontainer configuration (mcr.microsoft.com/devcontainers/...) also does this.

Comment on lines +8 to +9
"USER_UID": "1000",
"USER_GID": "1000"
}
},
"remoteUser": "vscode",
"updateRemoteUserUID": false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants