Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Installs Rust, common Rust utilities, and their required dependencies
| version | Select or enter a version of Rust to install. | string | latest |
| profile | Select a rustup install profile. | string | minimal |
| targets | Optional comma separated list of additional Rust targets to install. | string | - |
| components | Optional, comma separated list of Rust components to be installed | string | rust-analyzer,rust-src,rustfmt,clippy |
| components | Optional, comma separated list of Rust components to be installed. Set to 'none' to install no components beyond the selected profile. | string | rust-analyzer,rust-src,rustfmt,clippy |

## Customizations

Expand Down
7 changes: 4 additions & 3 deletions src/rust/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "rust",
"version": "1.5.1",
"version": "1.6.0",
"name": "Rust",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/rust",
"description": "Installs Rust, common Rust utilities, and their required dependencies",
Expand Down Expand Up @@ -61,12 +61,13 @@
"components": {
"type": "string",
"default": "rust-analyzer,rust-src,rustfmt,clippy",
"description": "Optional, comma separated list of Rust components to be installed",
"description": "Optional, comma separated list of Rust components to be installed. Set to 'none' to install no components beyond the selected profile.",
"proposals": [
"rust-analyzer,rust-src,rustfmt,clippy",
"rust-analyzer,rust-src",
"rustfmt,clippy,rust-docs",
"llvm-tools-preview,rust-src,rustfmt"
"llvm-tools-preview,rust-src,rustfmt",
"none"
]
}
},
Expand Down
35 changes: 28 additions & 7 deletions src/rust/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
RUST_VERSION="${VERSION:-"latest"}"
RUSTUP_PROFILE="${PROFILE:-"minimal"}"
RUSTUP_TARGETS="${TARGETS:-""}"
IFS=',' read -ra components <<< "${COMPONENTS:-rust-analyzer,rust-src,rustfmt,clippy}"
# Set to "none" to install no components beyond the selected profile.
RUSTUP_COMPONENTS="${COMPONENTS:-rust-analyzer,rust-src,rustfmt,clippy}"
IFS=',' read -ra components <<< "${RUSTUP_COMPONENTS}"

export CARGO_HOME="${CARGO_HOME:-"/usr/local/cargo"}"
export RUSTUP_HOME="${RUSTUP_HOME:-"/usr/local/rustup"}"
Expand Down Expand Up @@ -396,19 +398,38 @@ if [ "${UPDATE_RUST}" = "true" ]; then
echo "Updating Rust..."
rustup update 2>&1
fi
# Install Rust components
echo "Installing Rust components..."
# Install Rust components (skip entirely when explicitly set to "none")
# Trim each entry, drop empties, and track whether the "none" sentinel was requested.
resolved_components=()
components_none="false"
for component in "${components[@]}"; do
# Trim leading and trailing whitespace
component="${component#"${component%%[![:space:]]*}"}" && component="${component%"${component##*[![:space:]]}"}"
if [ -n "${component}" ]; then
if [ -z "${component}" ]; then
continue
fi
if [ "${component}" = "none" ]; then
components_none="true"
fi
resolved_components+=("${component}")
done

if [ "${components_none}" = "true" ] && [ "${#resolved_components[@]}" -gt 1 ]; then
echo "Error: 'none' cannot be combined with other components. Set 'components' to 'none' on its own to skip installing components." >&2
exit 1
fi

if [ "${components_none}" = "true" ]; then
echo "Skipping Rust components installation as 'components' is set to 'none'."
else
Comment thread
V-Subhankar-infy marked this conversation as resolved.
echo "Installing Rust components..."
for component in "${resolved_components[@]}"; do
echo "Installing Rust component: ${component}"
if ! rustup component add "${component}" 2>&1; then
echo "Warning: Failed to install component '${component}'. It may not be available for this toolchain." >&2
exit 1
fi
fi
done
done
fi

if [ -n "${RUSTUP_TARGETS}" ]; then
IFS=',' read -ra targets <<< "${RUSTUP_TARGETS}"
Expand Down
30 changes: 30 additions & 0 deletions test/rust/rust_with_none_components.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Helper function to check component is NOT installed
check_component_not_installed() {
local component=$1
if rustup component list | grep -q "${component}.*installed"; then
return 1 # Component is installed (failure)
else
return 0 # Component is not installed (success)
fi
}

# Definition specific tests
check "cargo version" cargo --version
check "rustc version" rustc --version
check "correct rust version" rustup target list | grep aarch64-unknown-linux-gnu

# When components is set to "none", none of the default components should be installed
check "rust-analyzer not installed" check_component_not_installed "rust-analyzer"
check "rust-src not installed" check_component_not_installed "rust-src"
check "rustfmt not installed" check_component_not_installed "rustfmt"
check "clippy not installed" check_component_not_installed "clippy"

# Report result
reportResults
10 changes: 10 additions & 0 deletions test/rust/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
"components": ""
}
}
},
"rust_with_none_components": {
"image": "ubuntu:noble",
"features": {
"rust": {
"version": "latest",
"targets": "aarch64-unknown-linux-gnu",
"components": "none"
}
}
},
"rust_with_centos": {
"image": "centos:centos7",
Expand Down
Loading