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:
Installing system dependencies (Rust, Python packages, clang, etc.)
Configuring Rust toolchain with a specified target and components
Setting up Cargo configuration for Rust builds
Creating and activating a Python virtual environment
Installing Python packages with pinned versions for testing and integration
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
VENV(default:.venv): Directory path for the Python virtual environment.CARGO_TARGET_DIR (default:
target): Directory for Rust build artifacts.RUST_TOOLCHAIN: Rust toolchain version (e.g.,stable,nightly), expected to be set externally.TARGET: Rust compilation target triple (e.g.,x86_64-unknown-linux-gnu), expected to be set externally.PYTHON_PACKAGE: Python package name to install viadnf, expected to be set externally.PYTHON: Python interpreter path/version, expected to be set externally.
Step-by-Step Script Breakdown
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.
Remove Existing Repo File
rm /etc/yum.repos.d/fedora-cisco-openh264.repo || trueRemoves the
fedora-cisco-openh264.reporepo configuration if it exists, ignoring errors.Install System Packages
dnf install --setopt=install_weak_deps=false -y rustup clang lld "${PYTHON_PACKAGE}" python3-uvInstalls essential packages without installing weak dependencies:
rustup: Rust toolchain installerclang: C language family frontend for LLVMlld: LLVM linker${PYTHON_PACKAGE}: Python package provided externallypython3-uv: Python bindings for libuv (likely foruvCLI tool)
Initialize Rust Toolchain
rustup-init --default-toolchain "${RUST_TOOLCHAIN}-${TARGET}" --profile minimal --component rust-src -y source "${HOME}/.cargo/env"Installs Rust using
rustup-initwith: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
Setup Cargo Configuration
mkdir -p .cargo cp ci/config.toml .cargo/config.tomlCreates
.cargodirectory in the current working directory.Copies a Cargo config file from
ci/config.toml(likely customized build settings).
Fetch Rust Dependencies
cargo fetch --target="${TARGET}" &Runs
cargo fetchasynchronously in the background to prefetch Rust crates for the specified target.
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
uvCLI tool (a wrapper aroundvenvor similar).Activates the virtual environment to isolate Python dependencies.
Install Python Dependencies
uv pip install --upgrade "maturin>=1,<2" -r test/requirements.txt -r integration/requirements.txtUses
uv pip(Python package installer throughuvtool) to:Upgrade/install
maturin(Rust-Python binding tool) in version range[1, 2).Install Python packages listed in
test/requirements.txtandintegration/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
The script uses
rustup-initwith the--profile minimaloption to speed up installation by excluding optional components.Rust source code is installed to enable building Rust projects with
maturin, which leverages Rust extensions for Python.Asynchronous
cargo fetchallows Rust dependencies to download while the Python virtual environment is set up, improving setup speed.The use of the
uvCLI tool (likely a wrapper aroundvenvandpip) standardizes Python environment management.Removal of the
fedora-cisco-openh264.repofile prevents conflicts with Fedora's OpenH264 codec repository during package installation.
Interaction with Other System Components
Cargo: This script sets up Cargo configuration and prefetches dependencies, facilitating Rust builds elsewhere in the project.
Python virtual environment: Creates a clean isolated Python environment, ensuring consistent dependencies for tests and integration.
Continuous Integration (CI): The script is likely called by CI workflows to prepare the Fedora build environment before running tests or packaging.
Project directories: Relies on files such as
ci/config.toml,test/requirements.txt, andintegration/requirements.txtfor configuration and dependencies.
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
Note: The
cargo fetchstep runs asynchronously in background while the Python virtual environment is being created, indicated by color.
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.