install-fedora


Overview

`install-fedora` is a Bash script designed to prepare a Fedora Linux environment for building and testing a Rust and Python project. It automates the installation and configuration of the necessary system packages, Rust toolchain, Python virtual environment, and Python dependencies.

The script ensures a reproducible development setup by:

This script is typically used in continuous integration (CI) pipelines or developer machines to bootstrap the environment before running builds and tests.


Detailed Explanation

Environment Variables


Step-by-Step Script Breakdown

  1. Shell Options

    set -eou pipefail
    
    • -e: Exit immediately if a command fails.

    • -o pipefail: Fail if any command in a pipeline fails.

    • -u: Treat unset variables as errors.

  2. Remove Existing Repo File

    rm /etc/yum.repos.d/fedora-cisco-openh264.repo || true
    

    Removes the fedora-cisco-openh264.repo repo configuration if it exists, ignoring errors.

  3. Install System Packages

    dnf install --setopt=install_weak_deps=false -y rustup clang lld "${PYTHON_PACKAGE}" python3-uv
    

    Installs essential packages without installing weak dependencies:

    • rustup: Rust toolchain installer

    • clang: C language family frontend for LLVM

    • lld: LLVM linker

    • ${PYTHON_PACKAGE}: Python package provided externally

    • python3-uv: Python bindings for libuv (likely for uv CLI tool)

  4. Initialize Rust Toolchain

    rustup-init --default-toolchain "${RUST_TOOLCHAIN}-${TARGET}" --profile minimal --component rust-src -y
    source "${HOME}/.cargo/env"
    
    • Installs Rust using rustup-init with:

      • Specified toolchain and target triple

      • Minimal profile to reduce installation size

      • Includes Rust source component (required for some build tools)

    • Sources Cargo environment variables for immediate use

  5. Setup Cargo Configuration

    mkdir -p .cargo
    cp ci/config.toml .cargo/config.toml
    
    • Creates .cargo directory in the current working directory.

    • Copies a Cargo config file from ci/config.toml (likely customized build settings).

  6. Fetch Rust Dependencies

    cargo fetch --target="${TARGET}" &
    
    • Runs cargo fetch asynchronously in the background to prefetch Rust crates for the specified target.

  7. Setup Python Virtual Environment

    rm -rf "${VENV}"
    uv venv --python "${PYTHON}" "${VENV}"
    source "${VENV}/bin/activate"
    
    • Removes any existing virtual environment.

    • Creates a new virtual environment using the uv CLI tool (a wrapper around venv or similar).

    • Activates the virtual environment to isolate Python dependencies.

  8. Install Python Dependencies

    uv pip install --upgrade "maturin>=1,<2" -r test/requirements.txt -r integration/requirements.txt
    
    • Uses uv pip (Python package installer through uv tool) to:

      • Upgrade/install maturin (Rust-Python binding tool) in version range [1, 2).

      • Install Python packages listed in test/requirements.txt and integration/requirements.txt.


Usage Example

Assuming the environment variables are set appropriately, run the script as follows:

export RUST_TOOLCHAIN=stable
export TARGET=x86_64-unknown-linux-gnu
export PYTHON_PACKAGE=python3-devel
export PYTHON=python3

./install-fedora

This will prepare the Fedora environment with Rust and Python tooling ready for building and testing the project.


Important Implementation Details


Interaction with Other System Components


Mermaid Flowchart

Below is a flowchart showing the main steps and their relationships during the environment setup:

flowchart TD
    A[Start Script] --> B[Remove fedora-cisco-openh264.repo]
    B --> C[Install system packages via dnf]
    C --> D[Install Rust toolchain with rustup-init]
    D --> E[Source Cargo environment]
    E --> F[Create .cargo directory and copy config.toml]
    F --> G[Run cargo fetch (background)]
    G --> H[Remove existing Python venv]
    H --> I[Create Python virtual environment with uv]
    I --> J[Activate Python virtual environment]
    J --> K[Install Python packages with uv pip]
    K --> L[Setup Complete]

    style G fill:#f9f,stroke:#333,stroke-width:2px

Summary

The `install-fedora` script is a streamlined bootstrapper for Rust and Python projects on Fedora, handling system package installation, Rust toolchain setup, Cargo configuration, and Python virtual environment preparation in an automated and efficient manner. It supports reproducible builds and testing environments essential for CI pipelines and developer workflows.