Skip to content

Commit 31c2b1e

Browse files
committed
Add feature flag for alloc dependency.
This allows parts of the crate to be used without a global allocator. This can be useful for programs which need some limited allocation without allowing arbitrary allocation.
1 parent 7b49a0e commit 31c2b1e

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ jobs:
2222
run: rustup default ${{ matrix.rust }}
2323
- name: Build
2424
run: cargo build --verbose
25+
- name: Build without default features
26+
run: cargo build --no-default-features --verbose
2527
- name: Run tests
2628
run: cargo test --verbose

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ homepage = "https://github.com/rcore-os/buddy_system_allocator"
66
repository = "https://github.com/rcore-os/buddy_system_allocator"
77
keywords = ["allocator", "no_std", "heap"]
88
version = "0.9.1"
9-
authors = ["Jiajie Chen <c@jia.je>", "Vinay Chandra Dommeti <github@vinay.vc>", "Andrew Walbran <qwandor@google.com>"]
9+
authors = [
10+
"Jiajie Chen <c@jia.je>",
11+
"Vinay Chandra Dommeti <github@vinay.vc>",
12+
"Andrew Walbran <qwandor@google.com>",
13+
]
1014
edition = "2021"
1115
license = "MIT"
1216

1317
[features]
14-
default = ["use_spin"]
15-
use_spin = ["spin"]
18+
default = ["alloc", "use_spin"]
19+
alloc = []
1620
const_fn = []
21+
use_spin = ["spin"]
1722

1823
[dependencies.spin]
1924
version = "0.9.8"

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ You can also use `FrameAllocator` and `LockedHeapWithRescue`, see their document
3030

3131
## Features
3232

33-
- **`use_spin`** (default): Provide a `LockedHeap` type that implements the [`GlobalAlloc`] trait by using a spinlock.
33+
- **`alloc`** (default): Provide `FrameAllocator` and `LockedFrameAllocator`, which depend on a
34+
global allocator.
35+
- **`use_spin`** (default): Provide a `LockedHeap` type that implements the [`GlobalAlloc`] trait by
36+
using a spinlock.
3437
- **`const_fn`** (nightly only): Provide const fn version of `LockedHeapWithRescue::new`.
3538

3639
[`GlobalAlloc`]: https://doc.rust-lang.org/nightly/core/alloc/trait.GlobalAlloc.html
@@ -41,7 +44,7 @@ Some code comes from phil-opp's linked-list-allocator.
4144

4245
Licensed under MIT License. Thanks phill-opp's linked-list-allocator for inspirations and interface.
4346

44-
[crate-img]: https://img.shields.io/crates/v/buddy_system_allocator.svg
45-
[crate]: https://crates.io/crates/buddy_system_allocator
46-
[docs-img]: https://docs.rs/buddy_system_allocator/badge.svg
47-
[docs]: https://docs.rs/buddy_system_allocator
47+
[crate-img]: https://img.shields.io/crates/v/buddy_system_allocator.svg
48+
[crate]: https://crates.io/crates/buddy_system_allocator
49+
[docs-img]: https://docs.rs/buddy_system_allocator/badge.svg
50+
[docs]: https://docs.rs/buddy_system_allocator

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern crate std;
88
#[cfg(feature = "use_spin")]
99
extern crate spin;
1010

11+
#[cfg(feature = "alloc")]
1112
extern crate alloc;
1213

1314
#[cfg(feature = "use_spin")]
@@ -22,11 +23,13 @@ use core::ptr::NonNull;
2223
#[cfg(feature = "use_spin")]
2324
use spin::Mutex;
2425

26+
#[cfg(feature = "alloc")]
2527
mod frame;
2628
pub mod linked_list;
2729
#[cfg(test)]
2830
mod test;
2931

32+
#[cfg(feature = "alloc")]
3033
pub use frame::*;
3134

3235
/// A heap that uses buddy system with configurable order.

0 commit comments

Comments
 (0)