Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions src/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +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 separeated list of rust components to be installed based on input. | string | rust-analyzer,rust-src,rustfmt,clippy |

## Customizations

Expand Down
15 changes: 13 additions & 2 deletions src/rust/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "rust",
"version": "1.4.0",
"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",
Expand Down Expand Up @@ -57,7 +57,18 @@
"armv7-unknown-linux-gnueabihf",
"x86_64-unknown-redox,x86_64-unknown-uefi"
]
}
},
"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": {
Expand Down
16 changes: 14 additions & 2 deletions src/rust/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
RUST_VERSION="${VERSION:-"latest"}"
RUSTUP_PROFILE="${PROFILE:-"minimal"}"
RUSTUP_TARGETS="${TARGETS:-""}"
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"}"
Expand Down Expand Up @@ -394,8 +395,19 @@ 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
echo "Installing 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
fi
done

if [ -n "${RUSTUP_TARGETS}" ]; then
IFS=',' read -ra targets <<< "${RUSTUP_TARGETS}"
Expand Down
16 changes: 16 additions & 0 deletions test/rust/rust_with_almalinux_8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/rust/rust_with_almalinux_9.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/rust/rust_with_centos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions test/rust/rust_with_custom_components.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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 "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"
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

31 changes: 31 additions & 0 deletions test/rust/rust_with_default_components.sh
Original file line number Diff line number Diff line change
@@ -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 "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"
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

45 changes: 45 additions & 0 deletions test/rust/rust_with_empty_components.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/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 "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
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

32 changes: 32 additions & 0 deletions test/rust/rust_with_extended_components.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/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 "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

16 changes: 16 additions & 0 deletions test/rust/rust_with_fedora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/rust/rust_with_mariner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading