From d33716690e5cfc90c2e7e87d62731005cd0368b6 Mon Sep 17 00:00:00 2001 From: Kaniska Date: Wed, 2 Jul 2025 16:17:07 +0000 Subject: [PATCH 1/8] [rust] - Introducing new options to install components --- src/rust/README.md | 2 + src/rust/devcontainer-feature.json | 20 ++++++++- src/rust/install.sh | 23 +++++++++- test/rust/rust_with_custom_components.sh | 42 +++++++++++++++++++ test/rust/rust_with_default_components.sh | 30 +++++++++++++ test/rust/rust_with_empty_components.sh | 44 +++++++++++++++++++ test/rust/rust_with_extended_components.sh | 31 ++++++++++++++ test/rust/rust_with_minimal_components.sh | 42 +++++++++++++++++++ test/rust/scenarios.json | 49 ++++++++++++++++++++++ 9 files changed, 279 insertions(+), 4 deletions(-) create mode 100644 test/rust/rust_with_custom_components.sh create mode 100644 test/rust/rust_with_default_components.sh create mode 100644 test/rust/rust_with_empty_components.sh create mode 100644 test/rust/rust_with_extended_components.sh create mode 100644 test/rust/rust_with_minimal_components.sh diff --git a/src/rust/README.md b/src/rust/README.md index 022f8abbe..d2f2f3bd2 100644 --- a/src/rust/README.md +++ b/src/rust/README.md @@ -18,6 +18,8 @@ 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 | - | +| customComponents | Optional a flag to allow installing rust components based on input. | boolean | false | +| components | Optional comma separeated list of rust components to be installed based on input. | string | - | ## Customizations diff --git a/src/rust/devcontainer-feature.json b/src/rust/devcontainer-feature.json index 9c3399ab8..b2026401e 100644 --- a/src/rust/devcontainer-feature.json +++ b/src/rust/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "rust", - "version": "1.4.0", + "version": "1.4.1", "name": "Rust", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/rust", "description": "Installs Rust, common Rust utilities, and their required dependencies", @@ -57,7 +57,23 @@ "armv7-unknown-linux-gnueabihf", "x86_64-unknown-redox,x86_64-unknown-uefi" ] - } + }, + "customComponents": { + "type": "boolean", + "default": false, + "description": "Use custom components list instead of default components (rust-analyzer, rust-src, rustfmt, clippy)." + }, + "components": { + "type": "string", + "default": "", + "description": "Optional comma separated list of Rust components to install when customComponents is true.", + "proposals": [ + "rust-analyzer,rust-src,rustfmt,clippy", + "rust-analyzer,rust-src", + "rustfmt,clippy,rust-docs", + "llvm-tools-preview,rust-src,rustfmt" + ] + } }, "customizations": { "vscode": { diff --git a/src/rust/install.sh b/src/rust/install.sh index 7481a05f5..93ec558ef 100755 --- a/src/rust/install.sh +++ b/src/rust/install.sh @@ -10,6 +10,8 @@ RUST_VERSION="${VERSION:-"latest"}" RUSTUP_PROFILE="${PROFILE:-"minimal"}" RUSTUP_TARGETS="${TARGETS:-""}" +CUSTOM_COMPONENTS="${CUSTOMCOMPONENTS:-"false"}" +RUST_COMPONENTS="${COMPONENTS:-""}" export CARGO_HOME="${CARGO_HOME:-"/usr/local/cargo"}" export RUSTUP_HOME="${RUSTUP_HOME:-"/usr/local/rustup"}" @@ -394,8 +396,25 @@ if [ "${UPDATE_RUST}" = "true" ]; then echo "Updating Rust..." rustup update 2>&1 fi -echo "Installing common Rust dependencies..." -rustup component add rust-analyzer rust-src rustfmt clippy 2>&1 +# Install Rust components based on flag +if [ "${CUSTOM_COMPONENTS}" = "true" ] && [ -n "${RUST_COMPONENTS}" ]; then + echo "Installing custom Rust components..." + IFS=',' read -ra components <<< "${RUST_COMPONENTS}" + for component in "${components[@]}"; do + # Trim whitespace + component=$(echo "${component}" | xargs) + if [ -n "${component}" ]; then + 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 +else + echo "Installing common Rust dependencies..." + rustup component add rust-analyzer rust-src rustfmt clippy 2>&1 +fi if [ -n "${RUSTUP_TARGETS}" ]; then IFS=',' read -ra targets <<< "${RUSTUP_TARGETS}" diff --git a/test/rust/rust_with_custom_components.sh b/test/rust/rust_with_custom_components.sh new file mode 100644 index 000000000..8203822e1 --- /dev/null +++ b/test/rust/rust_with_custom_components.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + fi +} + +# 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 that specified custom components are installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" +check "rustfmt is installed" check_component_installed "rustfmt" + +# Check that clippy NOT installed +check "clippy not installed" check_component_not_installed "clippy" + +# Report result +reportResults + diff --git a/test/rust/rust_with_default_components.sh b/test/rust/rust_with_default_components.sh new file mode 100644 index 000000000..5c386b3b5 --- /dev/null +++ b/test/rust/rust_with_default_components.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + fi +} + +# Definition specific tests +check "cargo version" cargo --version +check "rustc version" rustc --version + +# Check that default components are installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" +check "rustfmt is installed" check_component_installed "rustfmt" +check "clippy is installed" check_component_installed "clippy" + +# Report result +reportResults + diff --git a/test/rust/rust_with_empty_components.sh b/test/rust/rust_with_empty_components.sh new file mode 100644 index 000000000..d314a167c --- /dev/null +++ b/test/rust/rust_with_empty_components.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + fi +} + +# 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 that no additional components are installed when empty list is provided +# Only the basic rust toolchain should be available +check "basic rust toolchain" rustc --version + +# Verify that default components are automatically installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" +check "rustfmt is installed" check_component_installed "rustfmt" +check "clippy is installed" check_component_installed "clippy" + +# Report result +reportResults + diff --git a/test/rust/rust_with_extended_components.sh b/test/rust/rust_with_extended_components.sh new file mode 100644 index 000000000..1d026e8fd --- /dev/null +++ b/test/rust/rust_with_extended_components.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + fi +} + +# Definition specific tests +check "cargo version" cargo --version +check "rustc version" rustc --version + +# Check that all specified extended components are installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" +check "rustfmt is installed" check_component_installed "rustfmt" +check "clippy is installed" check_component_installed "clippy" +check "rust-docs is installed" check_component_installed "rust-docs" + +# Report result +reportResults + diff --git a/test/rust/rust_with_minimal_components.sh b/test/rust/rust_with_minimal_components.sh new file mode 100644 index 000000000..27fdd3fa3 --- /dev/null +++ b/test/rust/rust_with_minimal_components.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + fi +} + +# 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 that only specified minimal components are installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" + +# Check that other default components are NOT installed +check "rustfmt not installed" check_component_not_installed "rustfmt" +check "clippy not installed" check_component_not_installed "clippy" + +# Report result +reportResults + diff --git a/test/rust/scenarios.json b/test/rust/scenarios.json index 003417958..a0114a6cd 100644 --- a/test/rust/scenarios.json +++ b/test/rust/scenarios.json @@ -16,6 +16,55 @@ } } }, + "rust_with_default_components": { + "image": "ubuntu:noble", + "features": { + "rust": { + "version": "latest", + "customComponents": false + } + } + }, + "rust_with_custom_components": { + "image": "ubuntu:noble", + "features": { + "rust": { + "version": "latest", + "customComponents": true, + "components": "rust-analyzer,rust-src,rustfmt" + } + } + }, + "rust_with_minimal_components": { + "image": "ubuntu:noble", + "features": { + "rust": { + "version": "latest", + "customComponents": true, + "components": "rust-analyzer,rust-src" + } + } + }, + "rust_with_extended_components": { + "image": "ubuntu:noble", + "features": { + "rust": { + "version": "latest", + "customComponents": true, + "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" + } + } + }, + "rust_with_empty_components": { + "image": "ubuntu:noble", + "features": { + "rust": { + "version": "latest", + "customComponents": true, + "components": "" + } + } + }, "rust_with_centos": { "image": "centos:centos7", "features": { From eaf5498f38fd4ca4f6d5b92e76a80c7033fe33c5 Mon Sep 17 00:00:00 2001 From: Kaniska Date: Wed, 2 Jul 2025 17:38:11 +0000 Subject: [PATCH 2/8] Fix for testing with rockylinux and addition in tests --- src/rust/install.sh | 4 +-- test/rust/rust_with_almalinux_8.sh | 16 ++++++++++ test/rust/rust_with_almalinux_9.sh | 16 ++++++++++ test/rust/rust_with_centos.sh | 16 ++++++++++ test/rust/rust_with_custom_components.sh | 1 + test/rust/rust_with_default_components.sh | 1 + test/rust/rust_with_empty_components.sh | 1 + test/rust/rust_with_extended_components.sh | 1 + test/rust/rust_with_fedora.sh | 16 ++++++++++ test/rust/rust_with_mariner.sh | 16 ++++++++++ test/rust/rust_with_minimal_components.sh | 1 + test/rust/rust_with_rockylinux_8.sh | 16 ++++++++++ test/rust/rust_with_rockylinux_9.sh | 16 ++++++++++ test/rust/scenarios.json | 35 +++++++++++++++++----- 14 files changed, 146 insertions(+), 10 deletions(-) diff --git a/src/rust/install.sh b/src/rust/install.sh index 93ec558ef..98bfb7b27 100755 --- a/src/rust/install.sh +++ b/src/rust/install.sh @@ -401,8 +401,8 @@ if [ "${CUSTOM_COMPONENTS}" = "true" ] && [ -n "${RUST_COMPONENTS}" ]; then echo "Installing custom Rust components..." IFS=',' read -ra components <<< "${RUST_COMPONENTS}" for component in "${components[@]}"; do - # Trim whitespace - component=$(echo "${component}" | xargs) + # Trim leading and trailing whitespace + component="${component#"${component%%[![:space:]]*}"}" && component="${component%"${component##*[![:space:]]}"}" if [ -n "${component}" ]; then echo "Installing Rust component: ${component}" if ! rustup component add "${component}" 2>&1; then diff --git a/test/rust/rust_with_almalinux_8.sh b/test/rust/rust_with_almalinux_8.sh index 0635916aa..7a2872846 100644 --- a/test/rust/rust_with_almalinux_8.sh +++ b/test/rust/rust_with_almalinux_8.sh @@ -5,11 +5,27 @@ set -e # Optional: Import test library source dev-container-features-test-lib +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + 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 +# Check that all specified extended components are installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" +check "rustfmt is installed" check_component_installed "rustfmt" +check "clippy is installed" check_component_installed "clippy" +check "rust-docs is installed" check_component_installed "rust-docs" # Report result reportResults diff --git a/test/rust/rust_with_almalinux_9.sh b/test/rust/rust_with_almalinux_9.sh index 0635916aa..7a2872846 100644 --- a/test/rust/rust_with_almalinux_9.sh +++ b/test/rust/rust_with_almalinux_9.sh @@ -5,11 +5,27 @@ set -e # Optional: Import test library source dev-container-features-test-lib +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + 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 +# Check that all specified extended components are installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" +check "rustfmt is installed" check_component_installed "rustfmt" +check "clippy is installed" check_component_installed "clippy" +check "rust-docs is installed" check_component_installed "rust-docs" # Report result reportResults diff --git a/test/rust/rust_with_centos.sh b/test/rust/rust_with_centos.sh index 0635916aa..7a2872846 100644 --- a/test/rust/rust_with_centos.sh +++ b/test/rust/rust_with_centos.sh @@ -5,11 +5,27 @@ set -e # Optional: Import test library source dev-container-features-test-lib +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + 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 +# Check that all specified extended components are installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" +check "rustfmt is installed" check_component_installed "rustfmt" +check "clippy is installed" check_component_installed "clippy" +check "rust-docs is installed" check_component_installed "rust-docs" # Report result reportResults diff --git a/test/rust/rust_with_custom_components.sh b/test/rust/rust_with_custom_components.sh index 8203822e1..38dbec1ff 100644 --- a/test/rust/rust_with_custom_components.sh +++ b/test/rust/rust_with_custom_components.sh @@ -28,6 +28,7 @@ check_component_not_installed() { # 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 # Check that specified custom components are installed check "rust-analyzer is installed" check_component_installed "rust-analyzer" diff --git a/test/rust/rust_with_default_components.sh b/test/rust/rust_with_default_components.sh index 5c386b3b5..333bb1aa6 100644 --- a/test/rust/rust_with_default_components.sh +++ b/test/rust/rust_with_default_components.sh @@ -18,6 +18,7 @@ check_component_installed() { # 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 # Check that default components are installed check "rust-analyzer is installed" check_component_installed "rust-analyzer" diff --git a/test/rust/rust_with_empty_components.sh b/test/rust/rust_with_empty_components.sh index d314a167c..116f7765a 100644 --- a/test/rust/rust_with_empty_components.sh +++ b/test/rust/rust_with_empty_components.sh @@ -28,6 +28,7 @@ check_component_not_installed() { # 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 # Check that no additional components are installed when empty list is provided # Only the basic rust toolchain should be available diff --git a/test/rust/rust_with_extended_components.sh b/test/rust/rust_with_extended_components.sh index 1d026e8fd..52fb74390 100644 --- a/test/rust/rust_with_extended_components.sh +++ b/test/rust/rust_with_extended_components.sh @@ -18,6 +18,7 @@ check_component_installed() { # 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 # Check that all specified extended components are installed check "rust-analyzer is installed" check_component_installed "rust-analyzer" diff --git a/test/rust/rust_with_fedora.sh b/test/rust/rust_with_fedora.sh index 0635916aa..7a2872846 100644 --- a/test/rust/rust_with_fedora.sh +++ b/test/rust/rust_with_fedora.sh @@ -5,11 +5,27 @@ set -e # Optional: Import test library source dev-container-features-test-lib +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + 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 +# Check that all specified extended components are installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" +check "rustfmt is installed" check_component_installed "rustfmt" +check "clippy is installed" check_component_installed "clippy" +check "rust-docs is installed" check_component_installed "rust-docs" # Report result reportResults diff --git a/test/rust/rust_with_mariner.sh b/test/rust/rust_with_mariner.sh index 0635916aa..7a2872846 100644 --- a/test/rust/rust_with_mariner.sh +++ b/test/rust/rust_with_mariner.sh @@ -5,11 +5,27 @@ set -e # Optional: Import test library source dev-container-features-test-lib +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + 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 +# Check that all specified extended components are installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" +check "rustfmt is installed" check_component_installed "rustfmt" +check "clippy is installed" check_component_installed "clippy" +check "rust-docs is installed" check_component_installed "rust-docs" # Report result reportResults diff --git a/test/rust/rust_with_minimal_components.sh b/test/rust/rust_with_minimal_components.sh index 27fdd3fa3..02760ed5b 100644 --- a/test/rust/rust_with_minimal_components.sh +++ b/test/rust/rust_with_minimal_components.sh @@ -28,6 +28,7 @@ check_component_not_installed() { # 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 # Check that only specified minimal components are installed check "rust-analyzer is installed" check_component_installed "rust-analyzer" diff --git a/test/rust/rust_with_rockylinux_8.sh b/test/rust/rust_with_rockylinux_8.sh index 0635916aa..7a2872846 100644 --- a/test/rust/rust_with_rockylinux_8.sh +++ b/test/rust/rust_with_rockylinux_8.sh @@ -5,11 +5,27 @@ set -e # Optional: Import test library source dev-container-features-test-lib +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + 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 +# Check that all specified extended components are installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" +check "rustfmt is installed" check_component_installed "rustfmt" +check "clippy is installed" check_component_installed "clippy" +check "rust-docs is installed" check_component_installed "rust-docs" # Report result reportResults diff --git a/test/rust/rust_with_rockylinux_9.sh b/test/rust/rust_with_rockylinux_9.sh index 0635916aa..7a2872846 100644 --- a/test/rust/rust_with_rockylinux_9.sh +++ b/test/rust/rust_with_rockylinux_9.sh @@ -5,11 +5,27 @@ set -e # Optional: Import test library source dev-container-features-test-lib +# Helper function to check component is installed +check_component_installed() { + local component=$1 + if rustup component list | grep -q "${component}.*installed"; then + return 0 # Component is installed (success) + else + return 1 # Component is not installed (failure) + 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 +# Check that all specified extended components are installed +check "rust-analyzer is installed" check_component_installed "rust-analyzer" +check "rust-src is installed" check_component_installed "rust-src" +check "rustfmt is installed" check_component_installed "rustfmt" +check "clippy is installed" check_component_installed "clippy" +check "rust-docs is installed" check_component_installed "rust-docs" # Report result reportResults diff --git a/test/rust/scenarios.json b/test/rust/scenarios.json index a0114a6cd..b81629502 100644 --- a/test/rust/scenarios.json +++ b/test/rust/scenarios.json @@ -21,6 +21,7 @@ "features": { "rust": { "version": "latest", + "targets": "aarch64-unknown-linux-gnu", "customComponents": false } } @@ -30,6 +31,7 @@ "features": { "rust": { "version": "latest", + "targets": "aarch64-unknown-linux-gnu", "customComponents": true, "components": "rust-analyzer,rust-src,rustfmt" } @@ -40,6 +42,7 @@ "features": { "rust": { "version": "latest", + "targets": "aarch64-unknown-linux-gnu", "customComponents": true, "components": "rust-analyzer,rust-src" } @@ -50,6 +53,7 @@ "features": { "rust": { "version": "latest", + "targets": "aarch64-unknown-linux-gnu", "customComponents": true, "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } @@ -60,6 +64,7 @@ "features": { "rust": { "version": "latest", + "targets": "aarch64-unknown-linux-gnu", "customComponents": true, "components": "" } @@ -70,7 +75,9 @@ "features": { "rust": { "version": "latest", - "targets": "aarch64-unknown-linux-gnu" + "targets": "aarch64-unknown-linux-gnu", + "customComponents": true, + "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } }, @@ -79,7 +86,9 @@ "features": { "rust": { "version": "latest", - "targets": "aarch64-unknown-linux-gnu" + "targets": "aarch64-unknown-linux-gnu", + "customComponents": true, + "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } }, @@ -88,7 +97,9 @@ "features": { "rust": { "version": "latest", - "targets": "aarch64-unknown-linux-gnu" + "targets": "aarch64-unknown-linux-gnu", + "customComponents": true, + "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } }, @@ -97,7 +108,9 @@ "features": { "rust": { "version": "latest", - "targets": "aarch64-unknown-linux-gnu" + "targets": "aarch64-unknown-linux-gnu", + "customComponents": true, + "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } }, @@ -106,7 +119,9 @@ "features": { "rust": { "version": "latest", - "targets": "aarch64-unknown-linux-gnu" + "targets": "aarch64-unknown-linux-gnu", + "customComponents": true, + "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } }, @@ -115,7 +130,9 @@ "features": { "rust": { "version": "latest", - "targets": "aarch64-unknown-linux-gnu" + "targets": "aarch64-unknown-linux-gnu", + "customComponents": true, + "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } }, @@ -124,8 +141,10 @@ "features": { "rust": { "version": "latest", - "targets": "aarch64-unknown-linux-gnu" + "targets": "aarch64-unknown-linux-gnu", + "customComponents": true, + "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } } -} \ No newline at end of file +} From 4b2afddda13f7714027536387be779797aa52467 Mon Sep 17 00:00:00 2001 From: Kaniska Date: Fri, 4 Jul 2025 06:55:46 +0000 Subject: [PATCH 3/8] Correcting based on review comments. --- src/rust/README.md | 3 +-- src/rust/devcontainer-feature.json | 7 +------ src/rust/install.sh | 32 ++++++++++++------------------ test/rust/scenarios.json | 14 +------------ 4 files changed, 16 insertions(+), 40 deletions(-) diff --git a/src/rust/README.md b/src/rust/README.md index d2f2f3bd2..963588c2a 100644 --- a/src/rust/README.md +++ b/src/rust/README.md @@ -18,8 +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 | - | -| customComponents | Optional a flag to allow installing rust components based on input. | boolean | false | -| components | Optional comma separeated list of rust components to be installed based on input. | string | - | +| components | Optional comma separeated list of rust components to be installed based on input. | string | rust-analyzer,rust-src,rustfmt,clippy | ## Customizations diff --git a/src/rust/devcontainer-feature.json b/src/rust/devcontainer-feature.json index b2026401e..773f12f82 100644 --- a/src/rust/devcontainer-feature.json +++ b/src/rust/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "rust", - "version": "1.4.1", + "version": "1.5.0", "name": "Rust", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/rust", "description": "Installs Rust, common Rust utilities, and their required dependencies", @@ -58,11 +58,6 @@ "x86_64-unknown-redox,x86_64-unknown-uefi" ] }, - "customComponents": { - "type": "boolean", - "default": false, - "description": "Use custom components list instead of default components (rust-analyzer, rust-src, rustfmt, clippy)." - }, "components": { "type": "string", "default": "", diff --git a/src/rust/install.sh b/src/rust/install.sh index 98bfb7b27..fe7867c9d 100755 --- a/src/rust/install.sh +++ b/src/rust/install.sh @@ -10,8 +10,7 @@ RUST_VERSION="${VERSION:-"latest"}" RUSTUP_PROFILE="${PROFILE:-"minimal"}" RUSTUP_TARGETS="${TARGETS:-""}" -CUSTOM_COMPONENTS="${CUSTOMCOMPONENTS:-"false"}" -RUST_COMPONENTS="${COMPONENTS:-""}" +RUST_COMPONENTS="${COMPONENTS:-"rust-analyzer,rust-src,rustfmt,clippy"}" export CARGO_HOME="${CARGO_HOME:-"/usr/local/cargo"}" export RUSTUP_HOME="${RUSTUP_HOME:-"/usr/local/rustup"}" @@ -397,24 +396,19 @@ if [ "${UPDATE_RUST}" = "true" ]; then rustup update 2>&1 fi # Install Rust components based on flag -if [ "${CUSTOM_COMPONENTS}" = "true" ] && [ -n "${RUST_COMPONENTS}" ]; then - echo "Installing custom Rust components..." - IFS=',' read -ra components <<< "${RUST_COMPONENTS}" - for component in "${components[@]}"; do - # Trim leading and trailing whitespace - component="${component#"${component%%[![:space:]]*}"}" && component="${component%"${component##*[![:space:]]}"}" - if [ -n "${component}" ]; then - 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 +echo "Installing Rust components..." +IFS=',' read -ra components <<< "${RUST_COMPONENTS}" +for component in "${components[@]}"; do + # Trim leading and trailing whitespace + component="${component#"${component%%[![:space:]]*}"}" && component="${component%"${component##*[![:space:]]}"}" + if [ -n "${component}" ]; then + 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 - done -else - echo "Installing common Rust dependencies..." - rustup component add rust-analyzer rust-src rustfmt clippy 2>&1 -fi + fi +done if [ -n "${RUSTUP_TARGETS}" ]; then IFS=',' read -ra targets <<< "${RUSTUP_TARGETS}" diff --git a/test/rust/scenarios.json b/test/rust/scenarios.json index b81629502..21e347947 100644 --- a/test/rust/scenarios.json +++ b/test/rust/scenarios.json @@ -21,8 +21,7 @@ "features": { "rust": { "version": "latest", - "targets": "aarch64-unknown-linux-gnu", - "customComponents": false + "targets": "aarch64-unknown-linux-gnu" } } }, @@ -32,7 +31,6 @@ "rust": { "version": "latest", "targets": "aarch64-unknown-linux-gnu", - "customComponents": true, "components": "rust-analyzer,rust-src,rustfmt" } } @@ -43,7 +41,6 @@ "rust": { "version": "latest", "targets": "aarch64-unknown-linux-gnu", - "customComponents": true, "components": "rust-analyzer,rust-src" } } @@ -54,7 +51,6 @@ "rust": { "version": "latest", "targets": "aarch64-unknown-linux-gnu", - "customComponents": true, "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } @@ -65,7 +61,6 @@ "rust": { "version": "latest", "targets": "aarch64-unknown-linux-gnu", - "customComponents": true, "components": "" } } @@ -76,7 +71,6 @@ "rust": { "version": "latest", "targets": "aarch64-unknown-linux-gnu", - "customComponents": true, "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } @@ -87,7 +81,6 @@ "rust": { "version": "latest", "targets": "aarch64-unknown-linux-gnu", - "customComponents": true, "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } @@ -98,7 +91,6 @@ "rust": { "version": "latest", "targets": "aarch64-unknown-linux-gnu", - "customComponents": true, "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } @@ -109,7 +101,6 @@ "rust": { "version": "latest", "targets": "aarch64-unknown-linux-gnu", - "customComponents": true, "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } @@ -120,7 +111,6 @@ "rust": { "version": "latest", "targets": "aarch64-unknown-linux-gnu", - "customComponents": true, "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } @@ -131,7 +121,6 @@ "rust": { "version": "latest", "targets": "aarch64-unknown-linux-gnu", - "customComponents": true, "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } @@ -142,7 +131,6 @@ "rust": { "version": "latest", "targets": "aarch64-unknown-linux-gnu", - "customComponents": true, "components": "rust-analyzer,rust-src,rustfmt,clippy,rust-docs" } } From f1ec1c5d99282f0474e0ab7d45fe0f379f9a83f4 Mon Sep 17 00:00:00 2001 From: Kaniska Date: Fri, 4 Jul 2025 13:06:19 +0000 Subject: [PATCH 4/8] Further changes in the input --- src/rust/install.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rust/install.sh b/src/rust/install.sh index fe7867c9d..4963e622e 100755 --- a/src/rust/install.sh +++ b/src/rust/install.sh @@ -10,7 +10,7 @@ RUST_VERSION="${VERSION:-"latest"}" RUSTUP_PROFILE="${PROFILE:-"minimal"}" RUSTUP_TARGETS="${TARGETS:-""}" -RUST_COMPONENTS="${COMPONENTS:-"rust-analyzer,rust-src,rustfmt,clippy"}" +IFS=',' read -ra components <<< "${COMPONENTS:-rust-analyzer,rust-src,rustfmt,clippy}" export CARGO_HOME="${CARGO_HOME:-"/usr/local/cargo"}" export RUSTUP_HOME="${RUSTUP_HOME:-"/usr/local/rustup"}" @@ -397,7 +397,6 @@ if [ "${UPDATE_RUST}" = "true" ]; then fi # Install Rust components based on flag echo "Installing Rust components..." -IFS=',' read -ra components <<< "${RUST_COMPONENTS}" for component in "${components[@]}"; do # Trim leading and trailing whitespace component="${component#"${component%%[![:space:]]*}"}" && component="${component%"${component##*[![:space:]]}"}" From 4fa9bcbf320b764f15e6437c0e85a5e1d9bc1771 Mon Sep 17 00:00:00 2001 From: Kaniska Date: Fri, 4 Jul 2025 13:30:16 +0000 Subject: [PATCH 5/8] correcting code comment --- src/rust/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rust/install.sh b/src/rust/install.sh index 4963e622e..99a7ba8f5 100755 --- a/src/rust/install.sh +++ b/src/rust/install.sh @@ -395,7 +395,7 @@ if [ "${UPDATE_RUST}" = "true" ]; then echo "Updating Rust..." rustup update 2>&1 fi -# Install Rust components based on flag +# Install Rust components echo "Installing Rust components..." for component in "${components[@]}"; do # Trim leading and trailing whitespace From 6e8a357b80c61c423898f9842b5f46f596a6477a Mon Sep 17 00:00:00 2001 From: Kaniska Date: Mon, 7 Jul 2025 16:36:24 +0000 Subject: [PATCH 6/8] Correcting based on review comment --- src/rust/devcontainer-feature.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rust/devcontainer-feature.json b/src/rust/devcontainer-feature.json index 773f12f82..d4cfc0c66 100644 --- a/src/rust/devcontainer-feature.json +++ b/src/rust/devcontainer-feature.json @@ -61,7 +61,7 @@ "components": { "type": "string", "default": "", - "description": "Optional comma separated list of Rust components to install when customComponents is true.", + "description": "Optional, comma separated list of Rust components to be installed.", "proposals": [ "rust-analyzer,rust-src,rustfmt,clippy", "rust-analyzer,rust-src", From f067f4c4e1bd5b457b5bd6e01ec2b774dceb6c57 Mon Sep 17 00:00:00 2001 From: Kaniska Date: Mon, 7 Jul 2025 16:38:19 +0000 Subject: [PATCH 7/8] Correcting based on review comment. --- src/rust/devcontainer-feature.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rust/devcontainer-feature.json b/src/rust/devcontainer-feature.json index d4cfc0c66..913f11333 100644 --- a/src/rust/devcontainer-feature.json +++ b/src/rust/devcontainer-feature.json @@ -60,7 +60,7 @@ }, "components": { "type": "string", - "default": "", + "default": "rust-analyzer,rust-src,rustfmt,clippy", "description": "Optional, comma separated list of Rust components to be installed.", "proposals": [ "rust-analyzer,rust-src,rustfmt,clippy", From 7e7ad9eb357874e8358a885265d6bc856f0e109b Mon Sep 17 00:00:00 2001 From: Kaniska Date: Mon, 7 Jul 2025 16:52:00 +0000 Subject: [PATCH 8/8] To rerun the test --- src/rust/devcontainer-feature.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rust/devcontainer-feature.json b/src/rust/devcontainer-feature.json index 913f11333..88b64daed 100644 --- a/src/rust/devcontainer-feature.json +++ b/src/rust/devcontainer-feature.json @@ -61,7 +61,7 @@ "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", "proposals": [ "rust-analyzer,rust-src,rustfmt,clippy", "rust-analyzer,rust-src",