From afdd47bf40d1ccd48487763ee9d619691d7b30e3 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Sun, 15 Mar 2026 15:48:10 +0100 Subject: [PATCH] uefi: add `jiff02` feature and integrate jiff types with struct Time --- Cargo.lock | 38 ++++++ Cargo.toml | 1 + uefi/CHANGELOG.md | 3 + uefi/Cargo.toml | 3 + uefi/src/lib.rs | 3 + uefi/src/runtime/time/integration_common.rs | 8 ++ .../runtime/time/integration_jiff_crate.rs | 126 ++++++++++++++++++ uefi/src/runtime/time/mod.rs | 10 +- xtask/src/cargo.rs | 18 ++- 9 files changed, 204 insertions(+), 6 deletions(-) create mode 100644 uefi/src/runtime/time/integration_jiff_crate.rs diff --git a/Cargo.lock b/Cargo.lock index d76b2b64..6f132c75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -435,6 +435,28 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "jiff" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a3546dc96b6d42c5f24902af9e2538e82e39ad350b0c766eb3fbf2d8f3d8359" +dependencies = [ + "jiff-static", + "portable-atomic", + "portable-atomic-util", +] + +[[package]] +name = "jiff-static" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a8c8b344124222efd714b73bb41f8b5120b27a7cc1c75593a6ff768d9d05aa4" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "leb128fmt" version = "0.1.0" @@ -538,6 +560,21 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" +[[package]] +name = "portable-atomic" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" + +[[package]] +name = "portable-atomic-util" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3" +dependencies = [ + "portable-atomic", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -988,6 +1025,7 @@ version = "0.37.0" dependencies = [ "bitflags 2.11.1", "cfg-if", + "jiff", "log", "ptr_meta", "qemu-exit", diff --git a/Cargo.toml b/Cargo.toml index e6879dbd..7413921f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ rust-version = "1.91" [workspace.dependencies] bitflags = "2.0.0" log = { version = "0.4.5", default-features = false } +jiff = { version = "0.2", default-features = false } ptr_meta = { version = "0.3.0", default-features = false, features = ["derive"] } qemu-exit = { version = "4.0.0" } time = { version = "0.3", default-features = false } diff --git a/uefi/CHANGELOG.md b/uefi/CHANGELOG.md index 2f76d23e..64c8f12c 100644 --- a/uefi/CHANGELOG.md +++ b/uefi/CHANGELOG.md @@ -47,6 +47,9 @@ - Integration of `Time` with `time` crate - `TryFrom`: `time::PrimitiveDateTime <--> Time` (without timezone) - `TryFrom`: `time::OffsetDateTime <--> Time` (with timezone) +- Integration of `Time` with `jiff` crate + - `TryFrom`: `jiff::DateTime <--> Time` (without timezone) + - `TryFrom`: `jiff::Zoned <--> Time` (with timezone) ## Changed - export all `text::{input, output}::*` types diff --git a/uefi/Cargo.toml b/uefi/Cargo.toml index 8c2bc292..a510748c 100644 --- a/uefi/Cargo.toml +++ b/uefi/Cargo.toml @@ -20,6 +20,8 @@ rust-version.workspace = true # KEEP this feature list in sync with doc in uefi/lib.rs! default = [ ] alloc = [] +# Integration with jiff crate `v0.2` +jiff02 = ["dep:jiff"] # Integration with time crate `v0.3` time03 = ["dep:time"] @@ -41,6 +43,7 @@ log-debugcon = [] bitflags.workspace = true log.workspace = true ptr_meta.workspace = true +jiff = { workspace = true, optional = true } time = { workspace = true, optional = true } qemu-exit = { workspace = true, optional = true } uguid.workspace = true diff --git a/uefi/src/lib.rs b/uefi/src/lib.rs index 3a5b7fc5..77403ece 100644 --- a/uefi/src/lib.rs +++ b/uefi/src/lib.rs @@ -142,6 +142,9 @@ //! using this feature, or no allocator at all if you don't need to //! dynamically allocate any memory. Note that even without that feature, //! some code might use the internal UEFI allocator. +//! - `jiff02`: Integration of [`runtime::Time`] with the `jiff` crate +//! (version 0.2 and possible above). Specifically, it integrates the time +//! struct with `DateTime` and `Zoned` via `TryFrom`. //! - `logger`: Logging implementation for the standard [`log`] crate //! that prints output to the UEFI console. No buffering is done; this //! is not a high-performance logger. diff --git a/uefi/src/runtime/time/integration_common.rs b/uefi/src/runtime/time/integration_common.rs index 1cfdca8b..958d3e39 100644 --- a/uefi/src/runtime/time/integration_common.rs +++ b/uefi/src/runtime/time/integration_common.rs @@ -38,6 +38,9 @@ pub(super) enum ConversionErrorInner { /// Errors raised in the [`time`] crate. #[cfg(feature = "time03")] TimeCrateError(time::Error), + /// Errors raised in the [`jiff`] crate. + #[cfg(feature = "jiff02")] + JiffCrateError(jiff::Error), } impl Display for ConversionErrorInner { @@ -48,6 +51,8 @@ impl Display for ConversionErrorInner { Self::UnspecifiedTimezone => write!(f, "Unspecified timezone"), #[cfg(feature = "time03")] Self::TimeCrateError(e) => write!(f, "Time crate error: {}", e), + #[cfg(feature = "jiff02")] + Self::JiffCrateError(e) => write!(f, "Jiff crate error: {}", e), } } } @@ -60,6 +65,9 @@ impl Error for ConversionErrorInner { Self::UnspecifiedTimezone => None, #[cfg(feature = "time03")] Self::TimeCrateError(e) => Some(e), + // None: Missing Error trait + #[cfg(feature = "jiff02")] + Self::JiffCrateError(_e) => None, } } } diff --git a/uefi/src/runtime/time/integration_jiff_crate.rs b/uefi/src/runtime/time/integration_jiff_crate.rs new file mode 100644 index 00000000..081a3192 --- /dev/null +++ b/uefi/src/runtime/time/integration_jiff_crate.rs @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! Integration of the UEFI [`Time`] type with the [`jiff`] crate. + +use super::Time; +use super::integration_common::{ConversionErrorInner, TimeConversionError}; +use jiff::Zoned; +use jiff::civil::DateTime; +use jiff::tz::{Offset, TimeZone}; +use uefi::runtime::TimeParams; + +// Timezone unaware +impl TryFrom