From bb4b575b7fe84238de00cd004f0d3e63b3056176 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Sun, 21 Jul 2024 09:30:37 +0200 Subject: [PATCH 1/3] uefi: mem.rs -> mem/{mod, util}.rs This is a preliminary measurement to move the types for the uefi memory map (et al.) from the boot services module to this module. --- uefi/src/mem/mod.rs | 8 ++++++++ uefi/src/{mem.rs => mem/util.rs} | 0 2 files changed, 8 insertions(+) create mode 100644 uefi/src/mem/mod.rs rename uefi/src/{mem.rs => mem/util.rs} (100%) diff --git a/uefi/src/mem/mod.rs b/uefi/src/mem/mod.rs new file mode 100644 index 000000000..81daaa50b --- /dev/null +++ b/uefi/src/mem/mod.rs @@ -0,0 +1,8 @@ +//! Types, functions, traits, and other helpers to work with memory in UEFI +//! libraries and applications. + +#[cfg(feature = "alloc")] +pub(crate) mod util; + +#[cfg(feature = "alloc")] +pub(crate) use util::*; diff --git a/uefi/src/mem.rs b/uefi/src/mem/util.rs similarity index 100% rename from uefi/src/mem.rs rename to uefi/src/mem/util.rs From 25c12dcd0b0b78b6cfbf24cb8e6ae622e931c2d7 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Sun, 21 Jul 2024 09:34:21 +0200 Subject: [PATCH 2/3] uefi: lib.rs cleanup Streamline the order of different statements. 1. extern crates 2. public modules 3. private modules 4. public uses 5. private use From my year-long experience, it is usually a better structure to group all `use` and all `mod` statements in a file. However, it is a matter of taste if `mod` or `use` comes first. --- uefi/src/lib.rs | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/uefi/src/lib.rs b/uefi/src/lib.rs index 52ff54cbb..378be3b8d 100644 --- a/uefi/src/lib.rs +++ b/uefi/src/lib.rs @@ -95,50 +95,38 @@ #[cfg(feature = "alloc")] extern crate alloc; - // allow referring to self as ::uefi for macros to work universally (from this crate and from others) // see https://github.com/rust-lang/rust/issues/54647 extern crate self as uefi; - -/// Re-export ucs2_cstr so that it can be used in the implementation of the -/// cstr16 macro. It is hidden since it's not intended to be used directly. -#[doc(hidden)] -pub use ucs2::ucs2_cstr; - #[macro_use] extern crate uefi_raw; #[macro_use] pub mod data_types; +pub mod allocator; #[cfg(feature = "alloc")] -pub use data_types::CString16; -pub use data_types::{CStr16, CStr8, Char16, Char8, Event, Guid, Handle, Identify}; -pub use uefi_macros::entry; -pub use uguid::guid; - -mod result; -pub use result::{Error, Result, ResultExt, Status, StatusExt}; - +pub mod fs; +pub mod helpers; +pub mod mem; +pub mod prelude; +pub mod proto; pub mod runtime; pub mod system; pub mod table; -pub mod proto; - -pub mod prelude; - -pub mod allocator; - -#[cfg(feature = "alloc")] -pub mod fs; - -// As long as this is behind "alloc", we can simplify cfg-feature attributes in this module. -#[cfg(feature = "alloc")] -pub(crate) mod mem; - pub(crate) mod polyfill; -pub mod helpers; - mod macros; +mod result; mod util; + +#[cfg(feature = "alloc")] +pub use data_types::CString16; +pub use data_types::{CStr16, CStr8, Char16, Char8, Event, Guid, Handle, Identify}; +pub use result::{Error, Result, ResultExt, Status, StatusExt}; +/// Re-export ucs2_cstr so that it can be used in the implementation of the +/// cstr16 macro. It is hidden since it's not intended to be used directly. +#[doc(hidden)] +pub use ucs2::ucs2_cstr; +pub use uefi_macros::entry; +pub use uguid::guid; From ef3dcb6a474637d545f03a1f0e0483eabd59b932 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Mon, 22 Jul 2024 10:01:55 +0200 Subject: [PATCH 3/3] uefi-macros: fix trybuild-based unit tests The unit tests for the compiler diagnostics are utilizing the trybuild crate. With the recent reordering of the public exports of uefi/lib.rs, the fully qualified paths have changed. To update the expected error messages, I ran: `$ TRYBUILD=overwrite cargo xtask test` I'm not sure whether the previous changes also change something observable by the public API. In the Rust reference, I couldn't find anything about the fully qualified path and how it is influenced by the order of public exports. --- uefi-macros/tests/ui/fail/entry_bad_arg.stderr | 4 ++-- uefi-macros/tests/ui/fail/entry_bad_return_type.stderr | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/uefi-macros/tests/ui/fail/entry_bad_arg.stderr b/uefi-macros/tests/ui/fail/entry_bad_arg.stderr index 2f8f96ad3..9d292cf66 100644 --- a/uefi-macros/tests/ui/fail/entry_bad_arg.stderr +++ b/uefi-macros/tests/ui/fail/entry_bad_arg.stderr @@ -4,5 +4,5 @@ error[E0308]: mismatched types 8 | fn main(_handle: Handle, _st: SystemTable, _x: usize) -> Status { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters | - = note: expected fn pointer `extern "efiapi" fn(uefi::Handle, uefi::table::SystemTable) -> uefi::Status` - found fn pointer `extern "efiapi" fn(uefi::Handle, uefi::table::SystemTable, usize) -> uefi::Status` + = note: expected fn pointer `extern "efiapi" fn(uefi::Handle, uefi::prelude::SystemTable) -> uefi::Status` + found fn pointer `extern "efiapi" fn(uefi::Handle, uefi::prelude::SystemTable, usize) -> uefi::Status` diff --git a/uefi-macros/tests/ui/fail/entry_bad_return_type.stderr b/uefi-macros/tests/ui/fail/entry_bad_return_type.stderr index 4c7d1674e..6e718c631 100644 --- a/uefi-macros/tests/ui/fail/entry_bad_return_type.stderr +++ b/uefi-macros/tests/ui/fail/entry_bad_return_type.stderr @@ -4,5 +4,5 @@ error[E0308]: mismatched types 8 | fn main(_handle: Handle, _st: SystemTable) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Status`, found `bool` | - = note: expected fn pointer `extern "efiapi" fn(uefi::Handle, uefi::table::SystemTable) -> Status` - found fn pointer `extern "efiapi" fn(uefi::Handle, uefi::table::SystemTable) -> bool` + = note: expected fn pointer `extern "efiapi" fn(uefi::Handle, uefi::prelude::SystemTable) -> Status` + found fn pointer `extern "efiapi" fn(uefi::Handle, uefi::prelude::SystemTable) -> bool`