Skip to content

Commit fd62a73

Browse files
committed
rename crate features
1 parent 1068d2e commit fd62a73

File tree

26 files changed

+111
-75
lines changed

26 files changed

+111
-75
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
### Changed
2121

22+
- renamed crate feature `alloc` to `global_allocator`
23+
- renamed crate feature `exts` to `alloc`
2224
- Fixed the definition of `AllocateType` so that `MaxAddress` and
2325
`Address` always take a 64-bit value, regardless of target platform.
2426
- The conversion methods on `DevicePathToText` and `DevicePathFromText`
@@ -34,7 +36,7 @@
3436
replaced with a derived `Debug` impl.
3537
- `CStr16::from_u16_with_nul_unchecked` and `cstr16!` are now allowed in
3638
`const` contexts.
37-
39+
3840
### Removed
3941

4042
- Removed `UnalignedCStr16`; use `UnalignedSlice` instead. An

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ license = "MPL-2.0"
2121
[features]
2222
default = ["panic-on-logger-errors"]
2323
alloc = []
24-
exts = []
24+
global_allocator = []
2525
logger = []
2626
# Ignore text output errors in logger as a workaround for firmware issues that
2727
# were observed on the VirtualBox UEFI implementation (see uefi-rs#121).

README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,20 @@ 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.
35-
36-
Optional features:
37-
- `alloc`: implements a global allocator using UEFI functions.
38-
- This allows you to allocate objects on the heap.
34+
The objective is to stay opinionated and safely wrap most interfaces.
35+
36+
**Optional Crate Features:**
37+
- `alloc`: Enables functionality requiring the `alloc` crate from the Rust standard library.
38+
- For example, this allows many convenient `uefi-rs` functions to operate on heap data (`Box`).
39+
- It is up to the user to provide a `#[global allocator]`.
40+
- `global_allocator`: implements a `#[global allocator]` using UEFI functions.
41+
- This allows you to use all abstractions from the `alloc` crate from the Rust standard library
42+
during runtime. Hence, `Vec`, `Box`, etc. will be able to allocate memory.
43+
**This is optional**, so you can provide a custom `#[global allocator]` as well.
3944
- 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.
45+
- `logger`: logging implementation for the standard [`log`] crate.
46+
- Prints output to UEFI console.
4247
- 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).
4548

4649
- `uefi-macros`: procedural macros that are used to derive some traits in `uefi`.
4750

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

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

book/src/tutorial/building.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Create `.cargo/config.toml` with these contents:
4949
target = "x86_64-unknown-uefi"
5050

5151
[unstable]
52-
build-std = ["core", "compiler_builtins", "alloc"]
52+
build-std = ["core", "compiler_builtins", "global_allocator"]
5353
build-std-features = ["compiler-builtins-mem"]
5454
```
5555

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() {

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;

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() {

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]

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.

src/lib.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
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+
//! - `alloc`: Enables functionality requiring the `alloc` crate from the Rust standard library.
20+
//! - For example, this allows many convenient `uefi-rs` functions to operate on heap data (`Box`).
21+
//! - It is up to the user to provide a `#[global allocator]`.
22+
//! - `global_allocator`: implements a `#[global allocator]` using UEFI functions.
23+
//! - This allows you to use all abstractions from the `alloc` crate from the Rust standard library
24+
//! during runtime. Hence, `Vec`, `Box`, etc. will be able to allocate memory.
25+
//! **This is optional**, so you can provide a custom `#[global allocator]` as well.
26+
//! - There's no guarantee of the efficiency of UEFI's allocator.
27+
//! - `logger`: logging implementation for the standard [`log`] crate.
28+
//! - Prints output to UEFI console.
29+
//! - No buffering is done: this is not a high-performance logger.
30+
//!
1831
//! ## Adapting to local conditions
1932
//!
2033
//! Unlike system tables, which are present on *all* UEFI implementations,
@@ -27,24 +40,25 @@
2740
#![feature(maybe_uninit_slice)]
2841
#![feature(negative_impls)]
2942
#![feature(ptr_metadata)]
30-
#![cfg_attr(feature = "exts", feature(vec_into_raw_parts))]
43+
#![cfg_attr(feature = "alloc", feature(vec_into_raw_parts))]
3144
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3245
#![no_std]
3346
// Enable some additional warnings and lints.
3447
#![warn(clippy::ptr_as_ptr, missing_docs, unused)]
3548
#![deny(clippy::all)]
3649

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

4155
// allow referring to self as ::uefi for macros to work universally (from this crate and from others)
4256
// see https://github.com/rust-lang/rust/issues/54647
4357
extern crate self as uefi;
4458

4559
#[macro_use]
4660
pub mod data_types;
47-
#[cfg(feature = "exts")]
61+
#[cfg(feature = "alloc")]
4862
pub use self::data_types::CString16;
4963
pub use self::data_types::{unsafe_guid, Identify};
5064
pub use self::data_types::{CStr16, CStr8, Char16, Char8, Event, Guid, Handle};
@@ -59,8 +73,8 @@ pub mod proto;
5973

6074
pub mod prelude;
6175

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

6579
#[cfg(feature = "logger")]
6680
pub mod logger;

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
]);

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]) {

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;

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

src/table/boot.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
use super::{Header, Revision};
44
use crate::data_types::{Align, PhysicalAddress, VirtualAddress};
55
use crate::proto::device_path::{DevicePath, FfiDevicePath};
6-
#[cfg(feature = "exts")]
6+
#[cfg(feature = "alloc")]
77
use crate::proto::{loaded_image::LoadedImage, media::fs::SimpleFileSystem};
88
use crate::proto::{Protocol, ProtocolPointer};
99
use crate::{Char16, Event, Guid, Handle, Result, Status};
10-
#[cfg(feature = "exts")]
11-
use alloc_api::vec::Vec;
10+
#[cfg(feature = "alloc")]
11+
use ::alloc::vec::Vec;
1212
use bitflags::bitflags;
1313
use core::cell::UnsafeCell;
1414
use core::ffi::c_void;
@@ -1154,7 +1154,7 @@ impl BootServices {
11541154
}
11551155
}
11561156

1157-
#[cfg(feature = "exts")]
1157+
#[cfg(feature = "alloc")]
11581158
impl BootServices {
11591159
/// Returns all the handles implementing a certain protocol.
11601160
pub fn find_handles<P: Protocol>(&self) -> Result<Vec<Handle>> {

0 commit comments

Comments
 (0)