Skip to content

Commit

Permalink
Merge pull request #32 from qwandor/alloc
Browse files Browse the repository at this point in the history
Add feature flag for alloc dependency.
  • Loading branch information
jiegec authored Jun 30, 2024
2 parents 7b49a0e + 31c2b1e commit 12aeecc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
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

0 comments on commit 12aeecc

Please sign in to comment.