diff --git a/.github/workflows/test-pr-selective.yaml b/.github/workflows/test-pr-selective.yaml index 9e2d8cc..edeca22 100644 --- a/.github/workflows/test-pr-selective.yaml +++ b/.github/workflows/test-pr-selective.yaml @@ -36,7 +36,7 @@ jobs: if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then if [ "${{ inputs.force_all }}" = "true" ]; then # Test all features - FEATURES='["yay","clone-repo","node","rust-bin","dotnet","dotnet-bin","chaotic-aur"]' + FEATURES='["yay","clone-repo","node","rust","rust-bin","dotnet","dotnet-bin","chaotic-aur"]' echo "Manual dispatch: Testing all features" elif [ -n "${{ inputs.features }}" ]; then # Test specified features diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3cb9ee8..39f4597 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,6 +16,7 @@ jobs: - yay - clone-repo - node + - rust - rust-bin - dotnet - dotnet-bin @@ -41,6 +42,7 @@ jobs: - yay - clone-repo - node + - rust - rust-bin - dotnet - dotnet-bin diff --git a/README.md b/README.md index 7c66724..d429123 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,27 @@ Installs Node.js and npm with sudo-free configuration for Arch Linux DevContaine } ``` -### ๐Ÿฆ€ [Rust and Cargo (rustup)](src/rust-bin/README.md) +### ๐Ÿฆ€ [Rust and Cargo (Pre-compiled)](src/rust/README.md) -Installs Rust programming language, Cargo package manager, and development tools via rustup for Arch Linux. +Installs Rust programming language and Cargo package manager from pre-compiled packages for fast installation (10-60 seconds). Includes clippy, rustfmt, rust-src, and rust-analyzer. + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "globalCrates": "cargo-watch,cargo-edit,cargo-audit" + } + } +} +``` + +**Use this when:** You need stable Rust with fast installation for standard development. + +**Note:** clippy and rustfmt are always included and cannot be disabled. + +### ๐Ÿฆ€ [Rust and Cargo (Rustup)](src/rust-bin/README.md) + +Installs Rust programming language, Cargo package manager, and development tools via rustup for Arch Linux. Provides beta/nightly toolchains and additional compilation targets. ```json { @@ -80,6 +98,8 @@ Installs Rust programming language, Cargo package manager, and development tools } ``` +**Use this when:** You need beta/nightly toolchains, multiple toolchain management, or additional compilation targets. + ### ๐ŸŸฃ [.NET SDK and Runtime](src/dotnet/README.md) Installs .NET SDK, runtime, and development tools from official Arch Linux packages. @@ -121,9 +141,11 @@ This project uses a Git submodules architecture for stability: arch-devcontainer-features/ โ”œโ”€โ”€ src/ # Our features โ”‚ โ”œโ”€โ”€ yay/ +โ”‚ โ”œโ”€โ”€ chaotic-aur/ โ”‚ โ”œโ”€โ”€ clone-repo/ โ”‚ โ”œโ”€โ”€ node/ -โ”‚ โ”œโ”€โ”€ rust/ +โ”‚ โ”œโ”€โ”€ rust/ # Rust and Cargo feature (pre-compiled) +โ”‚ โ”œโ”€โ”€ rust-bin/ # Rust and Cargo feature (rustup) โ”‚ โ”œโ”€โ”€ dotnet/ โ”‚ โ””โ”€โ”€ dotnet-bin/ โ””โ”€โ”€ vendor/ # Dependencies @@ -246,6 +268,12 @@ URL="https://raw.githubusercontent.com/bartventer/arch-devcontainer-features/${C โ”‚ โ”‚ โ”œโ”€โ”€ devcontainer-feature.json โ”‚ โ”‚ โ”œโ”€โ”€ install.sh โ”‚ โ”‚ โ””โ”€โ”€ README.md +โ”‚ โ”œโ”€โ”€ rust/ # Rust and Cargo feature (pre-compiled) +โ”‚ โ”‚ โ”œโ”€โ”€ devcontainer-feature.json +โ”‚ โ”‚ โ”œโ”€โ”€ install.sh +โ”‚ โ”‚ โ”œโ”€โ”€ NOTES.md +โ”‚ โ”‚ โ”œโ”€โ”€ examples.md +โ”‚ โ”‚ โ””โ”€โ”€ README.md โ”‚ โ”œโ”€โ”€ rust-bin/ # Rust and Cargo feature (rustup) โ”‚ โ”‚ โ”œโ”€โ”€ devcontainer-feature.json โ”‚ โ”‚ โ”œโ”€โ”€ install.sh @@ -304,6 +332,7 @@ Features are automatically published to: - `ghcr.io/zyrakq/arch-devcontainer-features/chaotic-aur` - `ghcr.io/zyrakq/arch-devcontainer-features/clone-repo` - `ghcr.io/zyrakq/arch-devcontainer-features/node` +- `ghcr.io/zyrakq/arch-devcontainer-features/rust` - `ghcr.io/zyrakq/arch-devcontainer-features/rust-bin` - `ghcr.io/zyrakq/arch-devcontainer-features/dotnet` - `ghcr.io/zyrakq/arch-devcontainer-features/dotnet-bin` @@ -314,7 +343,8 @@ Features are automatically published to: - [Chaotic-AUR Repository](src/chaotic-aur/README.md) - Chaotic-AUR feature documentation - [Clone Repository](src/clone-repo/README.md) - Clone-repo feature documentation - [Node.js and npm](src/node/README.md) - Node.js feature documentation -- [Rust and Cargo (rustup)](src/rust-bin/README.md) - Rust feature documentation +- [Rust and Cargo (pre-compiled)](src/rust/README.md) - Rust feature documentation (pre-compiled packages) +- [Rust and Cargo (rustup)](src/rust-bin/README.md) - Rust feature documentation (rustup) - [.NET SDK and Runtime](src/dotnet/README.md) - .NET feature documentation (official packages) - [.NET SDK and Runtime (AUR)](src/dotnet-bin/README.md) - .NET feature documentation (AUR packages) - [DevContainers Specification](https://containers.dev/implementors/features/) - Official specification diff --git a/src/rust/NOTES.md b/src/rust/NOTES.md new file mode 100644 index 0000000..f937ddc --- /dev/null +++ b/src/rust/NOTES.md @@ -0,0 +1,228 @@ +# ๐Ÿฆ€ Rust (Pre-compiled) + +## ๐Ÿ“ Description + +This feature installs Rust programming language and Cargo package manager from **pre-compiled packages** in the official Arch Linux repositories. This provides a fast installation (10-60 seconds) with the stable Rust toolchain. + +## ๐Ÿค” When to Use This Feature + +Use the **`rust`** feature (this one) when you need: + +- โœ… **Fast installation** - Pre-compiled binaries install in 10-60 seconds +- โœ… **Stable Rust** - Production-ready stable toolchain +- โœ… **Standard development** - Most Rust projects work with stable +- โœ… **IDE integration** - Includes rust-analyzer and rust-src +- โœ… **CI/CD environments** - Where build time matters + +Use **`rust-bin`** instead when you need: + +- ๐Ÿ”ง Beta or Nightly toolchains +- ๐Ÿ”ง Multiple toolchain management via rustup +- ๐Ÿ”ง Additional compilation targets (wasm, windows, etc.) +- ๐Ÿ”ง Specific Rust versions + +## ๐Ÿš€ Quick Start + +### Basic Installation (Recommended) + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": {} + } +} +``` + +This installs Rust stable with **clippy**, **rustfmt** (always included), **rust-src**, and **rust-analyzer**. + +### Minimal Installation + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "installRustSrc": false, + "installRustAnalyzer": false + } + } +} +``` + +Minimal setup includes rustc, cargo, clippy, and rustfmt only (without IDE components). + +### With Global Crates + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "globalCrates": "cargo-watch,cargo-edit,cargo-audit" + } + } +} +``` + +## โš™๏ธ Configuration Options + +| Option | Type | Default | Description | +|--------|------|---------|-------------| +| `installRustSrc` | boolean | `true` | Install Rust source code (for IDE support) | +| `installRustAnalyzer` | boolean | `true` | Install rust-analyzer LSP server | +| `globalCrates` | string | `""` | Comma-separated list of crates to install globally | + +**Note:** `clippy` and `rustfmt` are always installed as part of the `rust` package and cannot be disabled. + +### ๐ŸŽฏ Popular Global Crates + +- **`cargo-watch`** - Automatically re-run cargo commands on file changes +- **`cargo-edit`** - Add, remove, and upgrade dependencies +- **`cargo-audit`** - Security vulnerability scanner +- **`cargo-expand`** - Show macro-expanded code +- **`cross`** - Zero-setup cross compilation + +## ๐Ÿ—๏ธ Architecture + +### ๐Ÿ“ฆ Installation Method + +1. **pacman packages** - Install from official Arch repositories + - `rust` - Rust compiler, cargo, clippy, and rustfmt (all-in-one package) + - `rust-src` - Rust source code (optional, for IDE support) + - `rust-analyzer` - LSP server (optional, for IDE integration) + +2. **cargo install** - Install additional tools via cargo + +### โšก Performance + +- **Installation time**: 10-60 seconds (vs 10-60+ minutes with rustup) +- **Download size**: ~200MB pre-compiled binaries +- **Disk usage**: ~1-1.5GB (vs ~2GB with rustup) + +### ๐Ÿ”ง Limitations + +- Only **stable** Rust version available +- No built-in support for **additional targets** + - Use `cross` crate for cross-compilation + - Or install `rust-bin` feature alongside for rustup targets +- No **beta/nightly** toolchains +- Version controlled by Arch repositories (usually 1-2 weeks behind latest stable) + +## ๐Ÿ”„ Cross-Compilation + +For cross-compilation, use the `cross` crate: + +```bash +cargo install cross +cross build --target aarch64-unknown-linux-gnu +``` + +Alternatively, use the `rust-bin` feature for more flexibility with additional targets: + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust-bin:1": { + "rustVersion": "stable", + "installClippy": true, + "installRustfmt": true, + "additionalTargets": "wasm32-unknown-unknown,aarch64-unknown-linux-gnu" + } + } +} +``` + +The `rust-bin` feature provides rustup-based installation with support for multiple targets and toolchains. + +## โœ… Compatibility + +### ๐Ÿง System Requirements + +- **OS**: Arch Linux +- **Architecture**: x86_64, aarch64 +- **Dependencies**: None (base-devel recommended for some crates) + +### ๐Ÿ”— DevContainer Integration + +- Works with any DevContainer base image running Arch Linux +- Compatible with VS Code DevContainers +- Supports multi-stage builds and feature composition + +## ๐Ÿงช Testing + +### ๐Ÿ“‹ Test Scenarios + +- **Basic installation** - Default stable Rust setup +- **Minimal installation** - Without IDE components +- **Global crates** - User-specified crate installation +- **Full setup** - All components enabled + +### ๐Ÿ” Verification Steps + +1. Rust compiler availability (`rustc --version`) +2. Cargo package manager (`cargo --version`) +3. Component availability (clippy, rustfmt, rust-analyzer) +4. Cargo tools functionality +5. Environment variable configuration + +## ๐Ÿšจ Troubleshooting + +### ๐Ÿ”ง Common Issues + +**Rust version is not the latest:** + +- Arch repositories update weekly, usually 1-2 weeks behind +- For absolute latest, use `rust-bin` feature with rustup + +**Need beta/nightly Rust:** + +- Use `rust-bin` feature which provides rustup +- This feature only provides stable from pacman + +**Cross-compilation targets missing:** + +- Use `cross` crate: `cargo install cross` +- Or use `rust-bin` feature which provides rustup with target management + +**Cargo tools not found in PATH:** + +- Verify that `~/.cargo/bin` is in PATH +- Source shell profile or restart terminal + +### ๐Ÿ” Debug Commands + +```bash +# Check Rust installation +rustc --version +cargo --version + +# Check components +cargo clippy --version +rustfmt --version +rust-analyzer --version + +# Check cargo tools +ls ~/.cargo/bin/ + +# Verify environment +echo $PATH | grep cargo +``` + +## ๐Ÿ“š Additional Resources + +- **๐Ÿ“– Official Documentation**: [Rust Book](https://doc.rust-lang.org/book/) +- **๐Ÿ› ๏ธ Cargo Guide**: [Cargo Book](https://doc.rust-lang.org/cargo/) +- **๐Ÿฆ€ Community**: [Rust Users Forum](https://users.rust-lang.org/) +- **๐Ÿ“ฆ Arch Package**: [rust](https://archlinux.org/packages/extra/x86_64/rust/) + +## ๐Ÿ”„ Maintenance + +### ๐Ÿ“… Regular Updates + +- Monitor Rust release schedule +- Arch packages typically updated within 1-2 weeks of stable release +- Update global crate versions as needed + +### ๐Ÿงช Testing Updates + +- Test with new Rust versions before updating defaults +- Verify compatibility with latest DevContainer specifications +- Validate package availability in Arch repositories diff --git a/src/rust/devcontainer-feature.json b/src/rust/devcontainer-feature.json new file mode 100644 index 0000000..6d1c2ec --- /dev/null +++ b/src/rust/devcontainer-feature.json @@ -0,0 +1,26 @@ +{ + "id": "rust", + "version": "2.0.0", + "name": "Rust and Cargo", + "description": "Installs Rust, Cargo, and development tools from pre-compiled packages for fast installation on Arch Linux", + "installsAfter": [ + "ghcr.io/bartventer/arch-devcontainer-features/common-utils" + ], + "options": { + "installRustSrc": { + "type": "boolean", + "default": true, + "description": "Install Rust source code (for IDE support and rust-analyzer)" + }, + "installRustAnalyzer": { + "type": "boolean", + "default": true, + "description": "Install rust-analyzer LSP server (for IDE integration)" + }, + "globalCrates": { + "type": "string", + "default": "", + "description": "Comma-separated list of crates to install globally via cargo install" + } + } +} \ No newline at end of file diff --git a/src/rust/examples.md b/src/rust/examples.md new file mode 100644 index 0000000..4ec4766 --- /dev/null +++ b/src/rust/examples.md @@ -0,0 +1,228 @@ +# ๐Ÿฆ€ Rust Feature Configuration Examples (Pre-compiled) + +This document provides practical examples of how to configure the Rust feature (pre-compiled pacman packages) for different development scenarios. + +## ๐Ÿ“‹ Basic Configurations + +### 1. Default Setup (Recommended for most projects) + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": {} + } +} +``` + +**What you get:** + +- Rust stable toolchain (includes clippy and rustfmt) +- Rust source code (rust-src) +- Rust-analyzer LSP server +- Fast installation (~30 seconds) + +### 2. Minimal Setup + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "installRustSrc": false, + "installRustAnalyzer": false + } + } +} +``` + +**Use case:** Bare minimum Rust installation (rustc, cargo, clippy, rustfmt only). + +**Note:** clippy and rustfmt are always included with the rust package and cannot be disabled. + +### 3. Development Setup with Tools + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "globalCrates": "cargo-watch,cargo-edit,cargo-audit" + } + } +} +``` + +**Use case:** Standard development setup with essential cargo tools. + +## ๐ŸŒ Web Development + +### 4. WebAssembly Development with Cross + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "globalCrates": "wasm-pack,cargo-generate,cross" + } + } +} +``` + +**Use case:** Building WebAssembly modules using `wasm-pack` and `cross` for compilation. + +**Note:** For native wasm targets, consider also using `rust-bin` feature. + +### 5. Full-Stack Web Development + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "globalCrates": "cargo-watch,cargo-edit,trunk,leptos-cli,dioxus-cli" + } + } +} +``` + +**Use case:** Modern Rust web frameworks like Leptos, Dioxus, or Yew. + +## ๐Ÿ”ง Systems Programming + +### 6. CLI Tool Development + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "globalCrates": "cargo-watch,cargo-edit,cargo-audit,cargo-dist,cargo-release" + } + } +} +``` + +**Use case:** Building command-line tools with proper distribution. + +### 7. Cross-Compilation Setup + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "globalCrates": "cross,cargo-watch,cargo-edit" + } + } +} +``` + +**Use case:** Cross-compiling for multiple platforms using `cross`. + +**Example usage:** + +```bash +cross build --target aarch64-unknown-linux-gnu +cross build --target x86_64-pc-windows-gnu +``` + +## ๐Ÿš€ Advanced Development + +### 8. Performance-Critical Applications + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "globalCrates": "cargo-watch,cargo-criterion,cargo-bench,flamegraph" + } + } +} +``` + +**Use case:** High-performance applications requiring detailed profiling. + +### 9. Security-Focused Development + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "globalCrates": "cargo-audit,cargo-deny,cargo-geiger,cargo-crev" + } + } +} +``` + +**Use case:** Projects requiring thorough security analysis. + +## ๐Ÿ“š Learning and Education + +### 10. Rust Learning Environment + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "globalCrates": "cargo-watch,cargo-edit,cargo-expand" + } + } +} +``` + +**Use case:** Educational environments and Rust learning. + +## ๐Ÿ”ง DevOps and CI/CD + +### 11. CI/CD Pipeline Development + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust:2": { + "globalCrates": "cargo-nextest,cargo-tarpaulin,cargo-llvm-cov" + } + } +} +``` + +**Use case:** Setting up comprehensive testing and coverage reporting. + +## ๐Ÿ”„ Alternative: Nightly and Additional Targets + +### 12. Nightly Rust with Cross-Compilation + +If you need nightly Rust or additional compilation targets, use the `rust-bin` feature instead: + +```json +{ + "features": { + "ghcr.io/zyrakq/arch-devcontainer-features/rust-bin:1": { + "rustVersion": "nightly", + "installClippy": true, + "installRustfmt": true, + "additionalTargets": "wasm32-unknown-unknown,aarch64-unknown-linux-gnu" + } + } +} +``` + +**Use case:** Nightly toolchain with WebAssembly and cross-compilation support. + +**Benefits:** + +- Nightly Rust for experimental features +- Additional compilation targets via rustup +- Full toolchain management flexibility +- Includes clippy, rustfmt, rust-src, and rust-analyzer + +**Note:** The `rust` and `rust-bin` features should NOT be used together. Choose one based on your needs. + +## ๐Ÿ“ Notes + +- **Global Crates**: Installed via `cargo install` into `~/.cargo/bin` +- **Installation Speed**: ~30-60 seconds for base, additional time for crates +- **Version**: Stable only (for beta/nightly use `rust-bin`) +- **Cross-compilation**: Use `cross` crate or combine with `rust-bin` + +## ๐Ÿ”— Useful Resources + +- [Rust Book](https://doc.rust-lang.org/book/) +- [Cargo Book](https://doc.rust-lang.org/cargo/) +- [Awesome Rust](https://github.com/rust-unofficial/awesome-rust) +- [Cross Documentation](https://github.com/cross-rs/cross) diff --git a/src/rust/install.sh b/src/rust/install.sh new file mode 100755 index 0000000..0566269 --- /dev/null +++ b/src/rust/install.sh @@ -0,0 +1,279 @@ +#!/usr/bin/env bash +#----------------------------------------------------------------------------------------------------------------- +# Copyright (c) Zyrakq. +# Licensed under the MIT License or Apache License 2.0. +#----------------------------------------------------------------------------------------------------------------- +# +# Docs: https://github.com/zyrakq/arch-devcontainer-features/tree/master/src/rust/README.md +# Maintainer: Zyrakq + +set -e + +# Environment variables +INSTALL_RUST_SRC="${INSTALLRUSTSRC:-"true"}" +INSTALL_RUST_ANALYZER="${INSTALLRUSTANALYZER:-"true"}" +GLOBAL_CRATES="${GLOBALCRATES:-""}" +USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}" + +# ************************** +# ** Utility functions ** +# ************************** + +# Function to get submodule commit hash +get_submodule_commit() { + local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + local feature_root="$(cd "${script_dir}/../.." && pwd)" + + # Check if we're in a git repository + if ! git -C "$feature_root" rev-parse --git-dir >/dev/null 2>&1; then + echo "main" # fallback to main branch + return + fi + + # Get commit hash of submodule + local commit_hash + commit_hash=$(git -C "$feature_root" ls-tree HEAD vendor/bartventer-features 2>/dev/null | awk '{print $3}') + + if [ -n "$commit_hash" ]; then + echo "$commit_hash" + else + echo "main" # fallback to main branch + fi +} + +# Get bartventer commit and setup utils +echo "Determining bartventer-features version..." +BARTVENTER_COMMIT=$(get_submodule_commit) +echo "Using bartventer-features commit: $BARTVENTER_COMMIT" + +_UTILS_SETUP_SCRIPT=$(mktemp) +UTILS_URL="https://raw.githubusercontent.com/bartventer/arch-devcontainer-features/${BARTVENTER_COMMIT}/scripts/archlinux_util_setup.sh" +echo "Downloading utils from: $UTILS_URL" + +curl -sSL -o "$_UTILS_SETUP_SCRIPT" "$UTILS_URL" || { + echo "Failed to download from commit $BARTVENTER_COMMIT, trying main branch..." + curl -sSL -o "$_UTILS_SETUP_SCRIPT" "https://raw.githubusercontent.com/bartventer/arch-devcontainer-features/main/scripts/archlinux_util_setup.sh" +} + +sh "$_UTILS_SETUP_SCRIPT" +rm -f "$_UTILS_SETUP_SCRIPT" + +# shellcheck disable=SC1091 +# shellcheck source=scripts/archlinux_util.sh +. archlinux_util.sh + +# Setup STDERR. +err() { + echo "(!) $*" >&2 +} + +# Source /etc/os-release to get OS info +# shellcheck disable=SC1091 +. /etc/os-release + +# Run checks +check_root +check_system +check_pacman + +# Determine the appropriate non-root user +if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then + USERNAME="" + POSSIBLE_USERS=("vscode" "abc" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)") + for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do + if id -u "${CURRENT_USER}" >/dev/null 2>&1; then + USERNAME=${CURRENT_USER} + break + fi + done + if [ "${USERNAME}" = "" ]; then + USERNAME=root + fi +elif [ "${USERNAME}" = "none" ] || ! id -u "${USERNAME}" >/dev/null 2>&1; then + USERNAME=root +fi + +# Function to run commands as non-root user +run_as_user() { + COMMAND="$*" + if [ "$(id -u)" = "0" ] && [ "${USERNAME}" != "root" ]; then + sudo -u "${USERNAME}" bash -c "$COMMAND" + else + bash -c "$COMMAND" + fi +} + +echo "Starting Rust installation via pacman..." +echo "Using pre-compiled packages from official Arch repositories" + +# Determine packages to install +# Note: rust package includes rustc, cargo, clippy, and rustfmt +PACKAGES_TO_INSTALL="rust" + +if [ "$INSTALL_RUST_SRC" = "true" ]; then + PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL rust-src" + echo "Will install: rust-src (for IDE support)" +fi + +if [ "$INSTALL_RUST_ANALYZER" = "true" ]; then + PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL rust-analyzer" + echo "Will install: rust-analyzer (LSP server)" +fi + +echo "Packages to install: $PACKAGES_TO_INSTALL" + +# Install Rust packages via pacman +echo "Installing Rust packages..." +check_and_install_packages $PACKAGES_TO_INSTALL + +echo "Rust packages installed successfully!" + +# Verify installation +echo "Verifying Rust installation..." + +if command -v rustc &> /dev/null; then + echo "โœ“ Rust compiler found: $(rustc --version)" +else + err "Rust installation failed - rustc not found" + exit 1 +fi + +if command -v cargo &> /dev/null; then + echo "โœ“ Cargo found: $(cargo --version)" +else + err "Rust installation failed - cargo not found" + exit 1 +fi + +# Check components included with rust package +if cargo clippy --version &> /dev/null; then + echo "โœ“ Clippy installed (included with rust package)" +else + echo "โš  Warning: Clippy not found" +fi + +if rustfmt --version &> /dev/null; then + echo "โœ“ Rustfmt installed (included with rust package)" +else + echo "โš  Warning: Rustfmt not found" +fi + +# Check optional components + +if [ "$INSTALL_RUST_ANALYZER" = "true" ]; then + if command -v rust-analyzer &> /dev/null; then + echo "โœ“ Rust-analyzer installed" + else + echo "โš  Warning: Rust-analyzer not found" + fi +fi + +echo "Rust installation verification completed!" + +# Configure cargo tools PATH +USER_HOME=$(eval echo "~$USERNAME") +CARGO_HOME="$USER_HOME/.cargo" +CARGO_BIN="$CARGO_HOME/bin" + +echo "Configuring Cargo environment..." +echo "User: $USERNAME" +echo "Home: $USER_HOME" +echo "Cargo bin: $CARGO_BIN" + +# Add cargo bin to PATH via shell profiles +if [ "${USERNAME}" != "root" ]; then + for profile in "$USER_HOME/.bashrc" "$USER_HOME/.zshrc"; do + if [ -f "$profile" ]; then + if ! grep -q "\.cargo/bin" "$profile"; then + echo "" >> "$profile" + echo "# Rust and Cargo configuration" >> "$profile" + echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> "$profile" + echo "โœ“ Added cargo bin to PATH in $profile" + else + echo "โ—‹ Cargo bin already in PATH ($profile)" + fi + fi + done + + echo "Environment configured for user $USERNAME" +fi + +# Export for current session +export PATH="$CARGO_BIN:$PATH" + +# Install global crates via cargo install +if [ -n "$GLOBAL_CRATES" ]; then + echo "" + echo "Installing global crates: $GLOBAL_CRATES" + + # Convert comma-separated to space-separated + CRATES=$(echo "$GLOBAL_CRATES" | tr ',' ' ') + + for crate in $CRATES; do + echo "Installing crate: $crate" + if [ "${USERNAME}" != "root" ]; then + if run_as_user "export PATH=\"$CARGO_BIN:\$PATH\" && cargo install $crate"; then + echo "โœ“ Successfully installed: $crate" + else + echo "โœ— Failed to install: $crate (continuing...)" + fi + else + if cargo install "$crate"; then + echo "โœ“ Successfully installed: $crate" + else + echo "โœ— Failed to install: $crate (continuing...)" + fi + fi + done + + echo "Global crates installation completed!" +else + echo "No global crates to install (globalCrates is empty)" +fi + +echo "" +echo "Rust feature installation completed!" + +# Output installation summary +echo "" +echo "=== Installation Summary ===" +echo "Installation method: pacman (pre-compiled packages)" +echo "Rust version: $(rustc --version 2>/dev/null || echo 'unknown')" +echo "Cargo version: $(cargo --version 2>/dev/null || echo 'unknown')" + +# Installed components +echo "" +echo "Installed components:" +# Clippy and rustfmt are always included with rust package +if cargo clippy --version &> /dev/null; then + echo " โœ“ Clippy: $(cargo clippy --version 2>/dev/null | head -n1) [included]" +fi +if rustfmt --version &> /dev/null; then + echo " โœ“ Rustfmt: $(rustfmt --version 2>/dev/null) [included]" +fi +if [ "$INSTALL_RUST_SRC" = "true" ]; then + echo " โœ“ Rust source code (rust-src)" +fi +if [ "$INSTALL_RUST_ANALYZER" = "true" ] && command -v rust-analyzer &> /dev/null; then + echo " โœ“ Rust-analyzer: Available" +fi + +# Global crates +if [ -n "$GLOBAL_CRATES" ]; then + echo "" + echo "Global crates installed:" + for crate in $(echo "$GLOBAL_CRATES" | tr ',' ' '); do + echo " - $crate" + done +fi + +# Additional information +if [ "${USERNAME}" != "root" ]; then + echo "" + echo "Cargo bin directory: $CARGO_BIN" + echo "Install global tools with: cargo install " +fi + +echo "" +echo "For beta/nightly Rust or cross-compilation targets, use the 'rust-bin' feature instead." +echo "==========================" diff --git a/test/rust/scenarios.json b/test/rust/scenarios.json new file mode 100644 index 0000000..5875627 --- /dev/null +++ b/test/rust/scenarios.json @@ -0,0 +1,25 @@ +{ + "test": { + "image": "archlinux:latest", + "features": { + "rust": {} + } + }, + "test_minimal": { + "image": "archlinux:latest", + "features": { + "rust": { + "installRustSrc": false, + "installRustAnalyzer": false + } + } + }, + "test_with_crates": { + "image": "archlinux:latest", + "features": { + "rust": { + "globalCrates": "cargo-watch,cargo-edit" + } + } + } +} \ No newline at end of file diff --git a/test/rust/test.sh b/test/rust/test.sh new file mode 100755 index 0000000..89cfe02 --- /dev/null +++ b/test/rust/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -e +source dev-container-features-test-lib + +# Check basic components +check "rust version" rustc --version +check "cargo version" cargo --version +check "clippy available" cargo clippy --version +check "rustfmt available" rustfmt --version +check "rust-analyzer available" rust-analyzer --version + +# Check that this is pacman installation (not rustup) +check "no rustup installed" bash -c "! command -v rustup" + +# Check that we can compile simple project +check "can compile hello world" bash -c "cd /tmp && cargo new hello && cd hello && cargo build" + +reportResults diff --git a/test/rust/test_minimal.sh b/test/rust/test_minimal.sh new file mode 100755 index 0000000..491b846 --- /dev/null +++ b/test/rust/test_minimal.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e +source dev-container-features-test-lib + +# Only basic components +check "rust version" rustc --version +check "cargo version" cargo --version + +# Clippy and rustfmt are ALWAYS included with rust package +check "clippy available" cargo clippy --version +check "rustfmt available" rustfmt --version + +# Should not have optional components +check "no rust-analyzer" bash -c "! command -v rust-analyzer" + +reportResults diff --git a/test/rust/test_with_crates.sh b/test/rust/test_with_crates.sh new file mode 100755 index 0000000..42aa61c --- /dev/null +++ b/test/rust/test_with_crates.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e +source dev-container-features-test-lib + +check "rust version" rustc --version +check "cargo version" cargo --version +check "cargo-watch installed" cargo watch --version +check "cargo-edit installed" cargo upgrade --version + +reportResults