Skip to content

Commit b15c60a

Browse files
committed
rename crate features
To prevent confusion, this renames the `alloc` crate feature to `global_allocator` and the `exts` feature to `alloc` to match the conventions of the ecosystem.
1 parent c901eda commit b15c60a

File tree

25 files changed

+108
-72
lines changed

25 files changed

+108
-72
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
### Changed
3232

33+
- Renamed crate feature `alloc` to `global_allocator`.
34+
- Renamed crate feature `exts` to `alloc`.
3335
- Fixed the definition of `AllocateType` so that `MaxAddress` and
3436
`Address` always take a 64-bit value, regardless of target platform.
3537
- The conversion methods on `DevicePathToText` and `DevicePathFromText`

README.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ Check out [the UEFI application template](template) for a quick start.
3131
This project contains multiple sub-crates:
3232

3333
- `uefi` (top directory): defines the standard UEFI tables / interfaces.
34-
The objective is to stay unopionated and safely wrap most interfaces.
34+
The objective is to stay unopinionated and safely wrap most interfaces.
3535

36-
Optional features:
37-
- `alloc`: implements a global allocator using UEFI functions.
38-
- This allows you to allocate objects on the heap.
36+
**Optional crate features:**
37+
38+
- `alloc`: Enables functionality requiring the `alloc` crate from the Rust standard library.
39+
- For example, this allows many convenient `uefi-rs` functions to operate on heap data (`Box`).
40+
- It is up to the user to provide a `#[global_allocator]`.
41+
- `global_allocator`: implements a `#[global_allocator]` using UEFI functions.
42+
- This allows you to use all abstractions from the `alloc` crate from the Rust standard library
43+
during runtime. Hence, `Vec`, `Box`, etc. will be able to allocate memory.
44+
**This is optional**, so you can provide a custom `#[global_allocator]` as well.
3945
- There's no guarantee of the efficiency of UEFI's allocator.
40-
- `logger`: logging implementation for the standard [log] crate.
41-
- Prints output to console.
46+
- `logger`: logging implementation for the standard [`log`] crate.
47+
- Prints output to UEFI console.
4248
- No buffering is done: this is not a high-performance logger.
43-
- `exts`: extensions providing utility functions for common patterns.
44-
- Requires the `alloc` crate (either enable the `alloc` optional feature or your own custom allocator).
4549

4650
- `uefi-macros`: procedural macros that are used to derive some traits in `uefi`.
4751

book/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Running in a VM](tutorial/vm.md)
88
- [How-to](how_to/introduction.md)
99
- [Using Protocols](how_to/protocols.md)
10+
- [Crate Features](how_to/crate_features.md)
1011
- [Concepts](concepts/introduction.md)
1112
- [Boot Stages](concepts/boot_stages.md)
1213
- [Tables](concepts/tables.md)

book/src/how_to/crate_features.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Optional Crate Features
2+
3+
There are several optional crate features provided by the `uefi` crate.
4+
5+
- `alloc`: Enables functionality requiring the `alloc` crate from the Rust standard library.
6+
- For example, this allows many convenient `uefi-rs` functions to operate on heap data (`Box`).
7+
- It is up to the user to provide a `#[global allocator]`.
8+
- `global_allocator`: implements a `#[global allocator]` using UEFI functions.
9+
- This allows you to use all abstractions from the `alloc` crate from the Rust standard library
10+
during runtime. Hence, `Vec`, `Box`, etc. will be able to allocate memory.
11+
**This is optional**, so you can provide a custom `#[global allocator]` as well.
12+
- There's no guarantee of the efficiency of UEFI's allocator.
13+
- `logger`: logging implementation for the standard [`log`] crate.
14+
- Prints output to the UEFI boot services standard text output.
15+
- No buffering is done: this is not a high-performance logger.

template/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ edition = "2021"
55
publish = false
66

77
[dependencies]
8-
uefi = { version = "0.18.0", features = ["exts"] }
8+
uefi = { version = "0.18.0", features = ["alloc"] }
99
uefi-services = "0.15.0"

uefi-services/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ is-it-maintained-issue-resolution = { repository = "rust-osdev/uefi-rs" }
1515
is-it-maintained-open-issues = { repository = "rust-osdev/uefi-rs" }
1616

1717
[dependencies]
18-
uefi = { version = "0.18.0", features = ["alloc"] }
18+
uefi = { version = "0.18.0", features = ["global_allocator"] }
1919
log = { version = "0.4.5", default-features = false }
2020
cfg-if = "1.0.0"
2121
qemu-exit = { version = "3.0.1", optional = true }

uefi-services/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn init(st: &mut SystemTable<Boot>) -> Result {
8383
init_logger(st);
8484

8585
let boot_services = st.boot_services();
86-
uefi::alloc::init(boot_services);
86+
uefi::global_allocator::init(boot_services);
8787

8888
// Schedule these tools to be disabled on exit from UEFI boot services
8989
boot_services
@@ -181,7 +181,7 @@ unsafe extern "efiapi" fn exit_boot_services(_e: Event, _ctx: Option<NonNull<c_v
181181
logger.disable();
182182
}
183183

184-
uefi::alloc::exit_boot_services();
184+
uefi::global_allocator::exit_boot_services();
185185
}
186186

187187
#[cfg(feature = "panic_handler")]

uefi-test-runner/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ publish = false
66
edition = "2021"
77

88
[dependencies]
9-
uefi = { path = "../uefi", features = ['exts'] }
9+
uefi = { path = "../uefi", features = ['alloc'] }
1010
uefi-services = { path = "../uefi-services" }
1111

1212
log = { version = "0.4.11", default-features = false }

uefi/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ license = "MPL-2.0"
1313
[features]
1414
default = ["panic-on-logger-errors"]
1515
alloc = []
16-
exts = []
16+
global_allocator = []
1717
logger = []
1818
# Ignore text output errors in logger as a workaround for firmware issues that
1919
# were observed on the VirtualBox UEFI implementation (see uefi-rs#121).

uefi/src/data_types/guid.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ pub use uefi_macros::unsafe_guid;
141141

142142
#[cfg(test)]
143143
mod tests {
144-
use uefi::{guid, unsafe_guid};
145-
extern crate alloc;
146144
use super::*;
145+
use uefi::{guid, unsafe_guid};
147146

148147
#[test]
149148
fn test_guid_display() {

uefi/src/data_types/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ pub use self::strs::{
132132
CStr16, CStr8, EqStrUntilNul, FromSliceWithNulError, FromStrWithBufError, UnalignedCStr16Error,
133133
};
134134

135-
#[cfg(feature = "exts")]
135+
#[cfg(feature = "alloc")]
136136
mod owned_strs;
137-
#[cfg(feature = "exts")]
137+
#[cfg(feature = "alloc")]
138138
pub use self::owned_strs::{CString16, FromStrError};
139139

140140
mod unaligned_slice;

uefi/src/data_types/owned_strs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::chars::{Char16, NUL_16};
22
use super::strs::{CStr16, FromSliceWithNulError};
3-
use crate::alloc_api::vec::Vec;
3+
use crate::alloc::vec::Vec;
44
use crate::data_types::strs::EqStrUntilNul;
55
use crate::data_types::UnalignedSlice;
66
use core::fmt;
@@ -138,8 +138,8 @@ impl<StrType: AsRef<str>> EqStrUntilNul<StrType> for CString16 {
138138
#[cfg(test)]
139139
mod tests {
140140
use super::*;
141-
use crate::alloc_api::string::String;
142-
use crate::alloc_api::vec;
141+
use crate::alloc::string::String;
142+
use crate::alloc::vec;
143143

144144
#[test]
145145
fn test_cstring16_from_str() {

uefi/src/data_types/strs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::mem::MaybeUninit;
66
use core::result::Result;
77
use core::slice;
88

9-
#[cfg(feature = "exts")]
9+
#[cfg(feature = "alloc")]
1010
use super::CString16;
1111

1212
/// Errors which can occur during checked `[uN]` -> `CStrN` conversions
@@ -397,7 +397,7 @@ impl fmt::Display for CStr16 {
397397
}
398398
}
399399

400-
#[cfg(feature = "exts")]
400+
#[cfg(feature = "alloc")]
401401
impl PartialEq<CString16> for &CStr16 {
402402
fn eq(&self, other: &CString16) -> bool {
403403
PartialEq::eq(*self, other.as_ref())
@@ -447,7 +447,7 @@ where
447447
#[cfg(test)]
448448
mod tests {
449449
use super::*;
450-
use crate::alloc_api::string::String;
450+
use crate::alloc::string::String;
451451
use uefi_macros::{cstr16, cstr8};
452452

453453
#[test]

uefi/src/data_types/unaligned_slice.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use core::marker::PhantomData;
22
use core::mem::MaybeUninit;
33

4-
#[cfg(feature = "exts")]
5-
use crate::alloc_api::vec::Vec;
4+
#[cfg(feature = "alloc")]
5+
use crate::alloc::vec::Vec;
66

77
/// Slice backed by a potentially-unaligned pointer.
88
///
@@ -110,7 +110,7 @@ impl<'a, T: Copy> UnalignedSlice<'a, T> {
110110
}
111111

112112
/// Copies `self` into a new `Vec`.
113-
#[cfg(feature = "exts")]
113+
#[cfg(feature = "alloc")]
114114
pub fn to_vec(&self) -> Vec<T> {
115115
let len = self.len();
116116
let mut v = Vec::with_capacity(len);
@@ -122,7 +122,7 @@ impl<'a, T: Copy> UnalignedSlice<'a, T> {
122122
}
123123
}
124124

125-
#[cfg(feature = "exts")]
125+
#[cfg(feature = "alloc")]
126126
impl<'a, T: Copy> From<UnalignedSlice<'a, T>> for Vec<T> {
127127
fn from(input: UnalignedSlice<'a, T>) -> Self {
128128
input.to_vec()
@@ -185,7 +185,7 @@ impl<'a, T: Copy> Iterator for UnalignedSliceIter<'a, T> {
185185
#[cfg(test)]
186186
mod tests {
187187
use super::*;
188-
use alloc_api::vec::Vec;
188+
use alloc::vec::Vec;
189189

190190
#[test]
191191
fn test_unaligned_slice() {
File renamed without changes.

uefi/src/lib.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
//! The `proto` module contains the standard UEFI protocols, which are normally provided
1616
//! by the various UEFI drivers and firmware layers.
1717
//!
18+
//! ## Optional crate features:
19+
//!
20+
//! - `alloc`: Enables functionality requiring the `alloc` crate from the Rust standard library.
21+
//! - For example, this allows many convenient `uefi-rs` functions to operate on heap data (`Box`).
22+
//! - It is up to the user to provide a `#[global_allocator]`.
23+
//! - `global_allocator`: implements a `#[global_allocator]` using UEFI functions.
24+
//! - This allows you to use all abstractions from the `alloc` crate from the Rust standard library
25+
//! during runtime. Hence, `Vec`, `Box`, etc. will be able to allocate memory.
26+
//! **This is optional**, so you can provide a custom `#[global_allocator]` as well.
27+
//! - There's no guarantee of the efficiency of UEFI's allocator.
28+
//! - `logger`: logging implementation for the standard [`log`] crate.
29+
//! - Prints output to UEFI console.
30+
//! - No buffering is done: this is not a high-performance logger.
31+
//!
1832
//! ## Adapting to local conditions
1933
//!
2034
//! Unlike system tables, which are present on *all* UEFI implementations,
@@ -27,24 +41,25 @@
2741
#![feature(maybe_uninit_slice)]
2842
#![feature(negative_impls)]
2943
#![feature(ptr_metadata)]
30-
#![cfg_attr(feature = "exts", feature(vec_into_raw_parts))]
44+
#![cfg_attr(feature = "alloc", feature(vec_into_raw_parts))]
3145
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3246
#![no_std]
3347
// Enable some additional warnings and lints.
3448
#![warn(clippy::ptr_as_ptr, missing_docs, unused)]
3549
#![deny(clippy::all)]
3650

37-
// `uefi-exts` requires access to memory allocation APIs.
38-
#[cfg(feature = "exts")]
39-
extern crate alloc as alloc_api;
51+
// Enable once we use vec![] or similar
52+
// #[cfg_attr(feature = "alloc", macro_use)]
53+
#[cfg(feature = "alloc")]
54+
extern crate alloc;
4055

4156
// allow referring to self as ::uefi for macros to work universally (from this crate and from others)
4257
// see https://github.com/rust-lang/rust/issues/54647
4358
extern crate self as uefi;
4459

4560
#[macro_use]
4661
pub mod data_types;
47-
#[cfg(feature = "exts")]
62+
#[cfg(feature = "alloc")]
4863
pub use self::data_types::CString16;
4964
pub use self::data_types::{unsafe_guid, Identify};
5065
pub use self::data_types::{CStr16, CStr8, Char16, Char8, Event, Guid, Handle};
@@ -59,8 +74,8 @@ pub mod proto;
5974

6075
pub mod prelude;
6176

62-
#[cfg(feature = "alloc")]
63-
pub mod alloc;
77+
#[cfg(feature = "global_allocator")]
78+
pub mod global_allocator;
6479

6580
#[cfg(feature = "logger")]
6681
pub mod logger;

uefi/src/proto/device_path/build.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ use crate::proto::device_path::{DevicePath, DevicePathNode};
1111
use core::mem::MaybeUninit;
1212
use core::ptr;
1313

14-
#[cfg(feature = "exts")]
15-
use alloc_api::vec::Vec;
14+
#[cfg(feature = "alloc")]
15+
use alloc::vec::Vec;
1616

1717
/// A builder for [`DevicePaths`].
1818
///
1919
/// The builder can be constructed with either a fixed-length buffer or
20-
/// (if the `exts` feature is enabled) a `Vec`.
20+
/// (if the `alloc` feature is enabled) a `Vec`.
2121
///
2222
/// Nodes are added via the [`push`] method. To construct a node, use one
2323
/// of the structs in these submodules:
@@ -82,7 +82,7 @@ impl<'a> DevicePathBuilder<'a> {
8282
}
8383

8484
/// Create a builder backed by a `Vec`.
85-
#[cfg(feature = "exts")]
85+
#[cfg(feature = "alloc")]
8686
pub fn with_vec(v: &'a mut Vec<u8>) -> Self {
8787
Self {
8888
storage: BuilderStorage::Vec(v),
@@ -107,7 +107,7 @@ impl<'a> DevicePathBuilder<'a> {
107107
);
108108
*offset += node_size;
109109
}
110-
#[cfg(feature = "exts")]
110+
#[cfg(feature = "alloc")]
111111
BuilderStorage::Vec(vec) => {
112112
let old_size = vec.len();
113113
vec.reserve(node_size);
@@ -134,7 +134,7 @@ impl<'a> DevicePathBuilder<'a> {
134134
BuilderStorage::Buf { buf, offset } => unsafe {
135135
MaybeUninit::slice_assume_init_ref(&buf[..*offset])
136136
},
137-
#[cfg(feature = "exts")]
137+
#[cfg(feature = "alloc")]
138138
BuilderStorage::Vec(vec) => vec,
139139
};
140140

@@ -149,7 +149,7 @@ enum BuilderStorage<'a> {
149149
offset: usize,
150150
},
151151

152-
#[cfg(feature = "exts")]
152+
#[cfg(feature = "alloc")]
153153
Vec(&'a mut Vec<u8>),
154154
}
155155

@@ -450,7 +450,7 @@ mod tests {
450450
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
451451
// Logical unit number
452452
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
453-
453+
454454
// End-entire node
455455
0x7f, 0xff, 0x04, 0x00,
456456
]);

uefi/src/proto/device_path/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ pub enum NodeConversionError {
558558
#[cfg(test)]
559559
mod tests {
560560
use super::*;
561-
use alloc_api::vec::Vec;
561+
use alloc::vec::Vec;
562562

563563
/// Create a node to `path` from raw data.
564564
fn add_node(path: &mut Vec<u8>, device_type: u8, sub_type: u8, node_data: &[u8]) {

uefi/src/proto/media/file/info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ impl FileProtocolInfo for FileSystemVolumeLabel {}
375375
#[cfg(test)]
376376
mod tests {
377377
use super::*;
378-
use crate::alloc_api::vec;
378+
use crate::alloc::vec;
379379
use crate::table::runtime::TimeParams;
380380
use crate::table::runtime::{Daylight, Time};
381381
use crate::CString16;

uefi/src/proto/media/file/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use core::ffi::c_void;
1616
use core::fmt::Debug;
1717
use core::mem;
1818
use core::ptr;
19-
#[cfg(feature = "exts")]
19+
#[cfg(feature = "alloc")]
2020
use {
2121
crate::ResultExt,
22-
alloc_api::{alloc, alloc::Layout, boxed::Box},
22+
::alloc::{alloc, alloc::Layout, boxed::Box},
2323
core::slice,
2424
};
2525

@@ -165,7 +165,7 @@ pub trait File: Sized {
165165
(self.imp().flush)(self.imp()).into()
166166
}
167167

168-
#[cfg(feature = "exts")]
168+
#[cfg(feature = "alloc")]
169169
/// Get the dynamically allocated info for a file
170170
fn get_boxed_info<Info: FileProtocolInfo + ?Sized + Debug>(&mut self) -> Result<Box<Info>> {
171171
// Initially try get_info with an empty array, this should always fail
@@ -408,7 +408,7 @@ mod tests {
408408
use super::*;
409409
use crate::table::runtime::Time;
410410
use crate::{CString16, Identify};
411-
use alloc_api::vec;
411+
use ::alloc::vec;
412412

413413
// Test `get_boxed_info` by setting up a fake file, which is mostly
414414
// just function pointers. Most of the functions can be empty, only

0 commit comments

Comments
 (0)