cargo-image-runner
A generic, highly customizable embedded/kernel development runner for Rust. Build and run bootable images with support for multiple bootloaders, image formats, and boot types.
Features
- Multiple Bootloaders: Limine, GRUB, or direct boot (no bootloader)
- Multiple Image Formats: Directory (for QEMU), ISO (planned), FAT (planned)
- Multiple Boot Types: BIOS, UEFI, or hybrid
- Trait-Based Architecture: Easy to extend with custom bootloaders, image builders, and runners
- Builder Pattern API: Ergonomic, fluent API for programmatic use
- Template Variables: Powerful variable substitution in config files
- Test Integration: Automatic test detection and execution
Quick Start
Installation
Add to your Cargo.toml:
[]
= "0.2"
Or install as a binary:
Basic UEFI Direct Boot
The simplest setup - boots your UEFI executable directly without a bootloader:
Cargo.toml:
[]
= "uefi"
[]
= "none"
[]
= "directory"
# Configure as cargo runner
[]
= "cargo-image-runner"
Then just run:
With Limine Bootloader
For a full bootloader experience with both BIOS and UEFI support:
Cargo.toml:
[]
= "hybrid" # Supports both BIOS and UEFI
[]
= "limine"
= "limine.conf"
[]
= "v8.4.0-binary" # Use a specific Limine version
[]
= "directory"
[]
= "5"
= "quiet"
limine.conf:
timeout: {{TIMEOUT}}
/My Kernel
protocol: limine
kernel_path: boot():/boot/{{EXECUTABLE_NAME}}
cmdline: {{KERNEL_CMDLINE}}
The runner will automatically:
- Fetch Limine binaries from GitHub (cached)
- Process template variables in limine.conf
- Copy your kernel and bootloader files
- Run in QEMU with UEFI firmware
Configuration Reference
Boot Configuration
[]
= "uefi" # Options: "bios", "uefi", "hybrid"
Bootloader Configuration
No Bootloader (Direct Boot)
[]
= "none"
Limine Bootloader
[]
= "limine"
= "limine.conf" # Path to your limine.conf
= [] # Additional files to copy
[]
= "v8.4.0-binary" # Git tag from limine repo
Available Limine versions: Check Limine releases for tags like v8.4.0-binary, v8.3.0-binary, etc.
GRUB Bootloader
[]
= "grub"
# GRUB support is basic - contributions welcome!
Image Configuration
[]
= "directory" # Options: "directory", "iso", "fat"
= "custom-name.iso" # Optional: custom output path
= "MYKERNEL" # Optional: volume label (default: "BOOT")
Image formats:
directory- Creates a directory structure (works with QEMUfat:rw:)iso- ISO 9660 image (planned, not yet implemented)fat- FAT filesystem image (planned, not yet implemented)
Runner Configuration
[]
= "qemu"
[]
= "qemu-system-x86_64" # QEMU binary to use
= "q35" # Machine type
= 1024 # RAM in MB
= 1 # Number of CPU cores
= true # Enable KVM acceleration (Linux only)
= [] # Additional QEMU arguments
Test Configuration
[]
= 33 # Exit code that indicates test success
= [ # Additional args for test runs
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x4"
]
= 60 # Test timeout in seconds
Run Configuration
[]
= [ # Additional args for normal runs
"-no-reboot",
"-serial", "stdio"
]
= false # Use GUI display
Template Variables
Define custom variables for use in bootloader config files:
[]
= "5"
= "quiet loglevel=3"
= "value"
Built-in variables:
{{EXECUTABLE}}- Full path to the executable{{EXECUTABLE_NAME}}- Executable filename{{WORKSPACE_ROOT}}- Project workspace root{{OUTPUT_DIR}}- Output directory path{{IS_TEST}}- "1" if running tests, "0" otherwise
Syntax: Use {{VAR}} or $VAR in your config files.
CLI Usage
The runner can be used directly from the command line:
# Run an executable
# Build image without running
# Check configuration
# Clean build artifacts
# Show version
Programmatic API
Use cargo-image-runner as a library:
use builder;
Custom Bootloader
Implement the Bootloader trait to add custom bootloader support:
use ;
use BootType;
use Context;
use Result;
;
// Use it
Complete Example
See the test-limine directory for a complete working example:
test-limine/
├── Cargo.toml # Package config with image-runner metadata
├── limine.conf # Limine bootloader config with templates
├── src/
│ └── main.rs # Minimal stub kernel
└── .cargo/
└── config.toml # Cargo runner configuration
To run the example:
CARGO_MANIFEST_PATH=test-limine/Cargo.toml
Feature Flags
Minimize dependencies by selecting only the features you need:
[]
= { = "0.2", = false, = ["uefi", "limine", "qemu"] }
Available features:
default- Enablesuefi,bios,limine,iso, andqemuuefi- UEFI boot support (includes OVMF firmware fetching)bios- BIOS boot supportlimine- Limine bootloader (requires git)grub- GRUB bootloaderiso- ISO image format (not yet implemented)fat- FAT filesystem image format (not yet implemented)qemu- QEMU runnerprogress- Progress reporting (optional, not yet implemented)
Architecture
cargo-image-runner uses a trait-based architecture with three core abstractions:
Bootloader Trait
Prepares bootloader files and processes configuration:
ImageBuilder Trait
Builds bootable images in various formats:
Runner Trait
Executes images:
Troubleshooting
"limine-bios.sys not found"
Make sure you're using a binary release version like v8.4.0-binary, not a source version like v8.4.0.
"revspec not found" error
The Limine version must be a valid git tag. Check available versions at https://github.com/limine-bootloader/limine/releases
QEMU not found
Install QEMU for your platform:
- macOS:
brew install qemu - Linux:
sudo apt install qemu-system-x86orsudo dnf install qemu-system-x86 - Windows: Download from https://www.qemu.org/download/
Missing OVMF firmware
The runner automatically downloads OVMF firmware for UEFI boot. If you see firmware errors, ensure you have internet connectivity and the uefi feature is enabled.
Current Status
Working:
- ✅ Core trait-based architecture
- ✅ Configuration loading from Cargo.toml
- ✅ Direct UEFI boot (no bootloader)
- ✅ Limine bootloader with git fetching
- ✅ Hybrid BIOS/UEFI support
- ✅ Template variable substitution
- ✅ Directory image builder
- ✅ QEMU runner with OVMF
- ✅ Test detection and execution
- ✅ CLI interface
Planned:
- 🚧 ISO image building
- 🚧 FAT filesystem images
- 🚧 Full GRUB support
- 🚧 Progress reporting
- 🚧 Additional runners (Bochs, VirtualBox)
Contributing
Contributions are welcome! The architecture is designed for extensibility:
- Add a bootloader: Implement the
Bootloadertrait - Add an image format: Implement the
ImageBuildertrait - Add a runner: Implement the
Runnertrait
License
MIT