Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature flag for alloc dependency. #32

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ jobs:
run: rustup default ${{ matrix.rust }}
- name: Build
run: cargo build --verbose
- name: Build without default features
run: cargo build --no-default-features --verbose
- name: Run tests
run: cargo test --verbose
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ homepage = "https://github.com/rcore-os/buddy_system_allocator"
repository = "https://github.com/rcore-os/buddy_system_allocator"
keywords = ["allocator", "no_std", "heap"]
version = "0.9.1"
authors = ["Jiajie Chen <[email protected]>", "Vinay Chandra Dommeti <[email protected]>", "Andrew Walbran <[email protected]>"]
authors = [
"Jiajie Chen <[email protected]>",
"Vinay Chandra Dommeti <[email protected]>",
"Andrew Walbran <[email protected]>",
]
edition = "2021"
license = "MIT"

[features]
default = ["use_spin"]
use_spin = ["spin"]
default = ["alloc", "use_spin"]
alloc = []
const_fn = []
use_spin = ["spin"]

[dependencies.spin]
version = "0.9.8"
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ You can also use `FrameAllocator` and `LockedHeapWithRescue`, see their document

## Features

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

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

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

[crate-img]: https://img.shields.io/crates/v/buddy_system_allocator.svg
[crate]: https://crates.io/crates/buddy_system_allocator
[docs-img]: https://docs.rs/buddy_system_allocator/badge.svg
[docs]: https://docs.rs/buddy_system_allocator
[crate-img]: https://img.shields.io/crates/v/buddy_system_allocator.svg
[crate]: https://crates.io/crates/buddy_system_allocator
[docs-img]: https://docs.rs/buddy_system_allocator/badge.svg
[docs]: https://docs.rs/buddy_system_allocator
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern crate std;
#[cfg(feature = "use_spin")]
extern crate spin;

#[cfg(feature = "alloc")]
extern crate alloc;

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

#[cfg(feature = "alloc")]
mod frame;
pub mod linked_list;
#[cfg(test)]
mod test;

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

/// A heap that uses buddy system with configurable order.
Expand Down
Loading