# rust-osdev/uefi-rs architecture

> Architecture diagram of the GitHub repository rust-osdev/uefi-rs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rust-osdev/uefi-rs
- Repository: https://github.com/rust-osdev/uefi-rs

## Overview

##### Project Type and Purpose
- This is a multi-crate Rust workspace providing:
- A high-level UEFI library (the `uefi` crate)
- A low-level, ABI-compatible layer (`uefi-raw`)
- Proc-macros for ergonomic entry points (`uefi-macros`)
- Support crates and examples (`uefi-services`, `uefi-std-example`, `template`)
- An integration-test runner binary (`uefi-test-runner`)
- A custom build/test helper (`xtask`)
- Purpose: Enable safe, convenient UEFI applications in Rust, plus tooling to build, test, and document them.

##### File-Structure Highlights
- Top-level is a Cargo workspace (`Cargo.toml`, `Cargo.lock`) with sub-directories for each crate.
- `uefi/`, `uefi-raw/`, `uefi-macros/`, `uefi-test-runner/`, `uefi-std-example/`, `uefi-services/`, `template/` each contain their own `Cargo.toml` and source.
- `xtask/` provides a custom CLI over `cargo` to simplify cross-crate build, test, doc, and run in QEMU with OVMF.
- `book/` and `docs/` hold user documentation and tutorials.
- GitHub Actions workflows orchestrate CI build, test, docs, and releases.

##### Key Dependencies and Relationships
- `uefi` (high level) → depends on → `uefi-raw` + `uefi-macros`
- `uefi-test-runner` and `uefi-std-example` → depend on → `uefi`
- `xtask` → orchestrates building/testing all crates (invokes `cargo build`, `cargo test`, QEMU runs)
- External services: QEMU + OVMF (for UEFI environment), docs.rs (for publishing docs), crates.io (publishing crates).

##### Architectural Patterns
- Monorepo/Cargo-workspace pattern: shared dependency management, provenance.
- Layered abstraction: raw FFI types (`uefi-raw`) → proc macros (`uefi-macros`) → safe Rust wrapper (`uefi`).
- Custom task runner (`xtask`): encapsulates repetitive build/test commands.
- Test-harness binary (`uefi-test-runner`): integration tests in UEFI environment.

a. Components to include:
- Developer Workstation: IDE/editor, `cargo`, `xtask`.
- Cargo Workspace: the collection of crates.
- Crates:
- uefi-raw
- uefi-macros
- uefi (high-level wrapper)
- uefi-services (helper utilities)
- uefi-test-runner (integration test binary)
- uefi-std-example (sample binary)
- template (starter project)
- Documentation subsystem (`book/`, `docs/`)
- CI/CD pipelines (GitHub Actions workflows)
- External Runtime: QEMU + OVMF firmware
- Publishing targets: crates.io, docs.rs

b. Relationships and Data Flow:
- Documentation sources feed into static site/book.

c. Important Patterns:
- Layered crates (dep-graph).
- Custom orchestration (xtask) vs. standard cargo.
- External emulation environment (QEMU).

d. Technologies and Frameworks:
- Rust/Cargo workspace
- Proc macro system for entry point annotations
- QEMU + OVMF firmware images
- GitHub Actions for CI

##### Final Advice
- Be exhaustive: show every crate and its immediate dependents.
- Clearly demarcate build-time vs. run-time interactions.
- Custom orchestration (`xtask`) and the external UEFI environment.
- Keep the layout hierarchical: low-level crates at the bottom, plugins/macros next, core wrapper in the middle, consumers on top, then external services and CI around the perimeter.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Developer["Developer"]:::dev
    xtask["xtask"]:::tool
    CI["GitHub Actions"]:::tool
    QEMU["QEMU + OVMF"]:::external
    CratesIO["crates.io"]:::external
    DocsRS["docs.rs"]:::external
    Book["book"]:::docs
    Docs["docs"]:::docs

    subgraph "Cargo Workspace"
        CW["Cargo Workspace"]:::workspace
        subgraph "Core Crates"
            URaw["uefi-raw"]:::core
            UMacros["uefi-macros"]:::core
            Uefi["uefi"]:::core
        end
        subgraph "Consumer Crates"
            USvc["uefi-services"]:::consumer
            URunner["uefi-test-runner"]:::consumer
            UExample["uefi-std-example"]:::consumer
            Template["template"]:::consumer
        end
    end

    Developer -->|"runs"| xtask
    xtask -.->|"build/test/doc"| CW
    xtask -.->|"run"| QEMU
    URaw -->|"depends on"| Uefi
    UMacros -->|"depends on"| Uefi
    Uefi -->|"depends on"| USvc
    Uefi -->|"depends on"| URunner
    Uefi -->|"depends on"| UExample
    Uefi -->|"depends on"| Template
    QEMU -->|"boots"| URunner
    CI -.->|"build/test"| CW
    CI -.->|"publish crates"| CratesIO
    CI -.->|"publish docs"| DocsRS
    Book -.->|"generates"| Docs
    Docs -.->|"deploy to"| DocsRS

    click CW "https://github.com/rust-osdev/uefi-rs/blob/main/Cargo.toml"
    click URaw "https://github.com/rust-osdev/uefi-rs/blob/main/uefi-raw/Cargo.toml"
    click UMacros "https://github.com/rust-osdev/uefi-rs/blob/main/uefi-macros/Cargo.toml"
    click Uefi "https://github.com/rust-osdev/uefi-rs/blob/main/uefi/Cargo.toml"
    click USvc "https://github.com/rust-osdev/uefi-rs/blob/main/uefi-services/README.md"
    click URunner "https://github.com/rust-osdev/uefi-rs/blob/main/uefi-test-runner/Cargo.toml"
    click UExample "https://github.com/rust-osdev/uefi-rs/blob/main/uefi-std-example/Cargo.toml"
    click Template "https://github.com/rust-osdev/uefi-rs/blob/main/template/Cargo.toml"
    click xtask "https://github.com/rust-osdev/uefi-rs/blob/main/xtask/Cargo.toml"
    click Book "https://github.com/rust-osdev/uefi-rs/blob/main/book/book.toml"
    click Docs "https://github.com/rust-osdev/uefi-rs/tree/main/docs/"
    click CI "https://github.com/rust-osdev/uefi-rs/tree/main/.github/workflows/"

    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef consumer fill:#90EE90,stroke:#000,stroke-width:1px
    classDef tool fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef docs fill:#E6E6FA,stroke:#000,stroke-width:1px
    classDef workspace fill:#ffffff,stroke:#000,stroke-width:2px,stroke-dasharray: 5 5
    class Developer dev
    class dev fill:#FFFFFF,stroke:#000,stroke-width:1px
    class CW workspace
```
