35 stable releases (8 major)
Uses new Rust 2024
| new 19.0.5 | Jan 21, 2026 |
|---|---|
| 19.0.0 | Dec 17, 2025 |
| 18.1.0 | Dec 10, 2025 |
| 17.1.0 | Dec 4, 2025 |
| 11.4.1 | Oct 17, 2025 |
#2314 in Procedural macros
447 downloads per month
Used in 11 crates
(3 directly)
130KB
2.5K
SLoC
Patina Macro Crate
patina_macro hosts the procedural macros used in Patina. This includes those that support the Patina component
system, service registration, guided HOB parsing, on-target test discovery, and more. The
patina crate re-export these macros, so most cases only need a dependency on
patina.
Notable Macros
#[component]
- Applied to impl blocks containing an
entry_pointmethod to define components. - Validates parameters at compile time and generates the boilerplate required to satisfy
patina::component::IntoComponent. - The
entry_pointmethod must consumeselfand takes dependency-injected parameters implementingComponentParam. - Compile-time validation detects parameter conflicts such as duplicate
ConfigMut<T>or mixingConfig<T>andConfigMut<T>.
use patina::component::{component, params::Config};
struct BoardInit;
#[component]
impl BoardInit {
fn entry_point(self, config: Config<u32>) -> patina::error::Result<()> {
patina::log::info!("Selected profile: {}", *config);
Ok(())
}
}
#[derive(IntoService)]
- Implements
patina::component::service::IntoServicefor a concrete provider. - Specify one or more service interfaces with
#[service(dyn TraitA, dyn TraitB)].
Note: The macro leaks the provider once and registers
'staticreferences so every component receives the same backing instance.
use patina::component::service::IntoService;
trait Uart {
fn write(&self, bytes: &[u8]) -> patina::error::Result<()>;
}
#[derive(IntoService)]
#[service(dyn Uart)]
struct SerialPort;
impl Uart for SerialPort {
fn write(&self, bytes: &[u8]) -> patina::error::Result<()> {
patina::log::info!("UART: {:?}", bytes);
Ok(())
}
}
#[derive(FromHob)]
- Bridges GUIDed Hand-Off Blocks (HOBs) into strongly typed Rust values.
- Attach the GUID with
#[hob = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"].
use patina::component::hob::FromHob;
#[derive(FromHob, zerocopy_derive::FromBytes)]
#[repr(C)]
#[hob = "8be4df61-93ca-11d2-aa0d-00e098032b8c"]
struct FirmwareVolumeHeader {
length: u32,
revision: u16,
}
#[patina_test]
- Registers a function with the Patina test runner that executes inside the DXE environment.
- Gate platform-specific tests with
cfg_attrso they only compile when the runner is active. - Optional attributes:
#[should_fail]or#[should_fail = "message"]#[skip]
use patina::test::{patina_test, Result};
#[cfg_attr(target_arch = "x86_64", patina_test)]
fn spi_smoke_test() -> Result {
patina::u_assert!(spi::probe(), "SPI controller missing");
Ok(())
}
#[patina_test]
#[should_fail = "Expected watchdog trip"]
fn watchdog_negative_path() -> Result {
patina::u_assert_eq!(watchdog::arm(), Err("trip"));
Ok(())
}
Dependencies
~350–770KB
~17K SLoC