|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Framework System is a Rust library and CLI tool for interacting with Framework Computer hardware. It targets Linux, Windows, UEFI, and FreeBSD. The MSRV is 1.81. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Build library and CLI tool (default members: framework_lib, framework_tool) |
| 13 | +cargo build |
| 14 | +cargo build --release |
| 15 | + |
| 16 | +# Build with specific features |
| 17 | +cargo build -p framework_lib --features nvidia |
| 18 | + |
| 19 | +# Build UEFI application (separate target, not in default workspace members) |
| 20 | +cd framework_uefi && make |
| 21 | + |
| 22 | +# Run tests (only framework_lib has tests) |
| 23 | +cargo test -p framework_lib |
| 24 | + |
| 25 | +# Linting (CI enforces -D warnings) |
| 26 | +cargo clippy -- -D warnings |
| 27 | +cargo fmt --check |
| 28 | + |
| 29 | +# Generate docs (CI enforces -D warnings) |
| 30 | +RUSTDOCFLAGS="-Dwarnings" cargo doc |
| 31 | + |
| 32 | +# Generate shell completions (must stay in sync; CI checks this) |
| 33 | +cargo run -- --completions bash > completions/bash/framework_tool |
| 34 | +cargo run -- --completions zsh > completions/zsh/_framework_tool |
| 35 | +cargo run -- --completions fish > completions/fish/framework_tool.fish |
| 36 | +``` |
| 37 | + |
| 38 | +## Architecture |
| 39 | + |
| 40 | +### Workspace Structure |
| 41 | + |
| 42 | +- **framework_lib/** — Core library. Contains all hardware interaction logic, command parsing, and platform abstractions. Supports `no_std` (for UEFI) via the `uefi` feature flag. |
| 43 | +- **framework_tool/** — Thin CLI binary wrapping `framework_lib::commandline`. Entry point is ~55 lines. |
| 44 | +- **framework_uefi/** — UEFI shell application. Built separately via Makefile (not a default workspace member). Uses `no_std` with `alloc`. |
| 45 | + |
| 46 | +### Key Modules in framework_lib |
| 47 | + |
| 48 | +- `chromium_ec/` — Chrome EC controller communication. Multiple driver backends: `cros_ec` (Linux kernel), `portio` (direct I/O for UEFI/FreeBSD), `windows` (Windows driver). Commands defined in `commands.rs`. |
| 49 | +- `ccgx/` — USB Power Delivery controller (CCG5/CCG6/CCG8) firmware parsing and device management. `binary.rs` handles firmware binary parsing. |
| 50 | +- `commandline/` — CLI implementation. `clap_std.rs` for std platforms (uses clap), `uefi.rs` for UEFI-specific parsing. |
| 51 | +- `smbios.rs` — SMBIOS table parsing for hardware identification. |
| 52 | +- `power.rs` — Battery, AC adapter, and PD port information. |
| 53 | +- `csme.rs` — Intel CSME/ME firmware info parsing. |
| 54 | +- `util.rs` — Platform detection and identification. `Platform` enum identifies specific hardware models. Platform detection is cached globally via `lazy_static`. |
| 55 | + |
| 56 | +### Platform Abstraction Patterns |
| 57 | + |
| 58 | +- **OS-level:** `#[cfg(target_os = "linux")]`, `#[cfg(windows)]`, `#[cfg(target_os = "freebsd")]` |
| 59 | +- **Feature-level:** `#[cfg(feature = "rusb")]`, `#[cfg(feature = "hidapi")]`, `#[cfg(feature = "uefi")]` |
| 60 | +- **no_std compatibility:** UEFI builds use `#![no_std]` with `alloc`. `lazy_static` uses `spin::Mutex` for no_std, `std::sync::Mutex` for std. Custom `no_std_compat` wrapper bridges standard library types. |
| 61 | + |
| 62 | +### Feature Flags (framework_lib) |
| 63 | + |
| 64 | +- `default` — Enables `hidapi` and `rusb` |
| 65 | +- `readonly` — Disables hardware modification commands |
| 66 | +- `uefi` — UEFI build support (no_std) |
| 67 | +- `hidapi` — HID device access (touchpad, touchscreen, PD controllers) |
| 68 | +- `rusb` — USB device access (audio card, camera, input modules) |
| 69 | +- `nvidia` — NVIDIA GPU monitoring |
| 70 | + |
| 71 | +### Custom Dependency Forks |
| 72 | + |
| 73 | +The project patches `uefi`, `uefi-services`, and uses custom forks of `smbios-lib` and `rust-hwio` for no_std/FreeBSD support. See `[patch.crates-io]` in the root Cargo.toml. |
| 74 | + |
| 75 | +## CI Pipeline |
| 76 | + |
| 77 | +Runs on every push: Linux build, Windows build, UEFI build, FreeBSD build, tests, lints (clippy + fmt), doc generation. CI also verifies shell completions are up-to-date and that no untracked changes are introduced by the build. |
| 78 | + |
| 79 | +## Test Binaries |
| 80 | + |
| 81 | +`framework_lib/test_bins/` contains firmware binary dumps and SMBIOS dumps used for unit tests. Tests parse these files to validate binary parsing logic. |
0 commit comments