Skip to content

Commit 805ce77

Browse files
authored
[rust] - Introducing new options to install components (#1404)
* [rust] - Introducing new options to install components * Fix for testing with rockylinux and addition in tests * Correcting based on review comments. * Further changes in the input * correcting code comment * Correcting based on review comment * Correcting based on review comment. * To rerun the test
1 parent a69dd5c commit 805ce77

16 files changed

+398
-12
lines changed

src/rust/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Installs Rust, common Rust utilities, and their required dependencies
1818
| version | Select or enter a version of Rust to install. | string | latest |
1919
| profile | Select a rustup install profile. | string | minimal |
2020
| targets | Optional comma separated list of additional Rust targets to install. | string | - |
21+
| components | Optional comma separeated list of rust components to be installed based on input. | string | rust-analyzer,rust-src,rustfmt,clippy |
2122

2223
## Customizations
2324

src/rust/devcontainer-feature.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "rust",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"name": "Rust",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/rust",
66
"description": "Installs Rust, common Rust utilities, and their required dependencies",
@@ -57,7 +57,18 @@
5757
"armv7-unknown-linux-gnueabihf",
5858
"x86_64-unknown-redox,x86_64-unknown-uefi"
5959
]
60-
}
60+
},
61+
"components": {
62+
"type": "string",
63+
"default": "rust-analyzer,rust-src,rustfmt,clippy",
64+
"description": "Optional, comma separated list of Rust components to be installed",
65+
"proposals": [
66+
"rust-analyzer,rust-src,rustfmt,clippy",
67+
"rust-analyzer,rust-src",
68+
"rustfmt,clippy,rust-docs",
69+
"llvm-tools-preview,rust-src,rustfmt"
70+
]
71+
}
6172
},
6273
"customizations": {
6374
"vscode": {

src/rust/install.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
RUST_VERSION="${VERSION:-"latest"}"
1111
RUSTUP_PROFILE="${PROFILE:-"minimal"}"
1212
RUSTUP_TARGETS="${TARGETS:-""}"
13+
IFS=',' read -ra components <<< "${COMPONENTS:-rust-analyzer,rust-src,rustfmt,clippy}"
1314

1415
export CARGO_HOME="${CARGO_HOME:-"/usr/local/cargo"}"
1516
export RUSTUP_HOME="${RUSTUP_HOME:-"/usr/local/rustup"}"
@@ -394,8 +395,19 @@ if [ "${UPDATE_RUST}" = "true" ]; then
394395
echo "Updating Rust..."
395396
rustup update 2>&1
396397
fi
397-
echo "Installing common Rust dependencies..."
398-
rustup component add rust-analyzer rust-src rustfmt clippy 2>&1
398+
# Install Rust components
399+
echo "Installing Rust components..."
400+
for component in "${components[@]}"; do
401+
# Trim leading and trailing whitespace
402+
component="${component#"${component%%[![:space:]]*}"}" && component="${component%"${component##*[![:space:]]}"}"
403+
if [ -n "${component}" ]; then
404+
echo "Installing Rust component: ${component}"
405+
if ! rustup component add "${component}" 2>&1; then
406+
echo "Warning: Failed to install component '${component}'. It may not be available for this toolchain." >&2
407+
exit 1
408+
fi
409+
fi
410+
done
399411

400412
if [ -n "${RUSTUP_TARGETS}" ]; then
401413
IFS=',' read -ra targets <<< "${RUSTUP_TARGETS}"

test/rust/rust_with_almalinux_8.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@ set -e
55
# Optional: Import test library
66
source dev-container-features-test-lib
77

8+
# Helper function to check component is installed
9+
check_component_installed() {
10+
local component=$1
11+
if rustup component list | grep -q "${component}.*installed"; then
12+
return 0 # Component is installed (success)
13+
else
14+
return 1 # Component is not installed (failure)
15+
fi
16+
}
17+
818
# Definition specific tests
919
check "cargo version" cargo --version
1020
check "rustc version" rustc --version
1121
check "correct rust version" rustup target list | grep aarch64-unknown-linux-gnu
1222

23+
# Check that all specified extended components are installed
24+
check "rust-analyzer is installed" check_component_installed "rust-analyzer"
25+
check "rust-src is installed" check_component_installed "rust-src"
26+
check "rustfmt is installed" check_component_installed "rustfmt"
27+
check "clippy is installed" check_component_installed "clippy"
28+
check "rust-docs is installed" check_component_installed "rust-docs"
1329

1430
# Report result
1531
reportResults

test/rust/rust_with_almalinux_9.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@ set -e
55
# Optional: Import test library
66
source dev-container-features-test-lib
77

8+
# Helper function to check component is installed
9+
check_component_installed() {
10+
local component=$1
11+
if rustup component list | grep -q "${component}.*installed"; then
12+
return 0 # Component is installed (success)
13+
else
14+
return 1 # Component is not installed (failure)
15+
fi
16+
}
17+
818
# Definition specific tests
919
check "cargo version" cargo --version
1020
check "rustc version" rustc --version
1121
check "correct rust version" rustup target list | grep aarch64-unknown-linux-gnu
1222

23+
# Check that all specified extended components are installed
24+
check "rust-analyzer is installed" check_component_installed "rust-analyzer"
25+
check "rust-src is installed" check_component_installed "rust-src"
26+
check "rustfmt is installed" check_component_installed "rustfmt"
27+
check "clippy is installed" check_component_installed "clippy"
28+
check "rust-docs is installed" check_component_installed "rust-docs"
1329

1430
# Report result
1531
reportResults

test/rust/rust_with_centos.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@ set -e
55
# Optional: Import test library
66
source dev-container-features-test-lib
77

8+
# Helper function to check component is installed
9+
check_component_installed() {
10+
local component=$1
11+
if rustup component list | grep -q "${component}.*installed"; then
12+
return 0 # Component is installed (success)
13+
else
14+
return 1 # Component is not installed (failure)
15+
fi
16+
}
17+
818
# Definition specific tests
919
check "cargo version" cargo --version
1020
check "rustc version" rustc --version
1121
check "correct rust version" rustup target list | grep aarch64-unknown-linux-gnu
1222

23+
# Check that all specified extended components are installed
24+
check "rust-analyzer is installed" check_component_installed "rust-analyzer"
25+
check "rust-src is installed" check_component_installed "rust-src"
26+
check "rustfmt is installed" check_component_installed "rustfmt"
27+
check "clippy is installed" check_component_installed "clippy"
28+
check "rust-docs is installed" check_component_installed "rust-docs"
1329

1430
# Report result
1531
reportResults
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Helper function to check component is installed
9+
check_component_installed() {
10+
local component=$1
11+
if rustup component list | grep -q "${component}.*installed"; then
12+
return 0 # Component is installed (success)
13+
else
14+
return 1 # Component is not installed (failure)
15+
fi
16+
}
17+
18+
# Helper function to check component is NOT installed
19+
check_component_not_installed() {
20+
local component=$1
21+
if rustup component list | grep -q "${component}.*installed"; then
22+
return 1 # Component is installed (failure)
23+
else
24+
return 0 # Component is not installed (success)
25+
fi
26+
}
27+
28+
# Definition specific tests
29+
check "cargo version" cargo --version
30+
check "rustc version" rustc --version
31+
check "correct rust version" rustup target list | grep aarch64-unknown-linux-gnu
32+
33+
# Check that specified custom components are installed
34+
check "rust-analyzer is installed" check_component_installed "rust-analyzer"
35+
check "rust-src is installed" check_component_installed "rust-src"
36+
check "rustfmt is installed" check_component_installed "rustfmt"
37+
38+
# Check that clippy NOT installed
39+
check "clippy not installed" check_component_not_installed "clippy"
40+
41+
# Report result
42+
reportResults
43+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Helper function to check component is installed
9+
check_component_installed() {
10+
local component=$1
11+
if rustup component list | grep -q "${component}.*installed"; then
12+
return 0 # Component is installed (success)
13+
else
14+
return 1 # Component is not installed (failure)
15+
fi
16+
}
17+
18+
# Definition specific tests
19+
check "cargo version" cargo --version
20+
check "rustc version" rustc --version
21+
check "correct rust version" rustup target list | grep aarch64-unknown-linux-gnu
22+
23+
# Check that default components are installed
24+
check "rust-analyzer is installed" check_component_installed "rust-analyzer"
25+
check "rust-src is installed" check_component_installed "rust-src"
26+
check "rustfmt is installed" check_component_installed "rustfmt"
27+
check "clippy is installed" check_component_installed "clippy"
28+
29+
# Report result
30+
reportResults
31+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Helper function to check component is installed
9+
check_component_installed() {
10+
local component=$1
11+
if rustup component list | grep -q "${component}.*installed"; then
12+
return 0 # Component is installed (success)
13+
else
14+
return 1 # Component is not installed (failure)
15+
fi
16+
}
17+
18+
# Helper function to check component is NOT installed
19+
check_component_not_installed() {
20+
local component=$1
21+
if rustup component list | grep -q "${component}.*installed"; then
22+
return 1 # Component is installed (failure)
23+
else
24+
return 0 # Component is not installed (success)
25+
fi
26+
}
27+
28+
# Definition specific tests
29+
check "cargo version" cargo --version
30+
check "rustc version" rustc --version
31+
check "correct rust version" rustup target list | grep aarch64-unknown-linux-gnu
32+
33+
# Check that no additional components are installed when empty list is provided
34+
# Only the basic rust toolchain should be available
35+
check "basic rust toolchain" rustc --version
36+
37+
# Verify that default components are automatically installed
38+
check "rust-analyzer is installed" check_component_installed "rust-analyzer"
39+
check "rust-src is installed" check_component_installed "rust-src"
40+
check "rustfmt is installed" check_component_installed "rustfmt"
41+
check "clippy is installed" check_component_installed "clippy"
42+
43+
# Report result
44+
reportResults
45+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Helper function to check component is installed
9+
check_component_installed() {
10+
local component=$1
11+
if rustup component list | grep -q "${component}.*installed"; then
12+
return 0 # Component is installed (success)
13+
else
14+
return 1 # Component is not installed (failure)
15+
fi
16+
}
17+
18+
# Definition specific tests
19+
check "cargo version" cargo --version
20+
check "rustc version" rustc --version
21+
check "correct rust version" rustup target list | grep aarch64-unknown-linux-gnu
22+
23+
# Check that all specified extended components are installed
24+
check "rust-analyzer is installed" check_component_installed "rust-analyzer"
25+
check "rust-src is installed" check_component_installed "rust-src"
26+
check "rustfmt is installed" check_component_installed "rustfmt"
27+
check "clippy is installed" check_component_installed "clippy"
28+
check "rust-docs is installed" check_component_installed "rust-docs"
29+
30+
# Report result
31+
reportResults
32+

0 commit comments

Comments
 (0)