Skip to content

Commit f0bb5a6

Browse files
authored
feat(stable): Build on stable without features (rust-osdev#43)
To built on stable, the `const_mut_refs` feature cannot be used, so introduce a crate feature `const_mut_refs`, which is on by default.
1 parent e29d3af commit f0bb5a6

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

.github/workflows/build.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,35 @@ jobs:
4343
- name: 'Deny Warnings'
4444
run: cargo rustc -- -D warnings
4545

46+
test-stable:
47+
name: "Test stable without features"
48+
49+
strategy:
50+
matrix:
51+
platform: [
52+
ubuntu-latest,
53+
macos-latest,
54+
windows-latest
55+
]
56+
57+
runs-on: ${{ matrix.platform }}
58+
timeout-minutes: 15
59+
60+
steps:
61+
- name: "Checkout Repository"
62+
uses: actions/checkout@v1
63+
64+
- name: "Print Rust Version"
65+
run: |
66+
rustc -Vv
67+
cargo -Vv
68+
69+
- name: "Build without feature on stable"
70+
run: cargo +stable build --no-default-features
71+
72+
- name: "Run cargo test without features on stable"
73+
run: cargo +stable test --no-default-features
74+
4675
test-unstable:
4776
name: "Test unstable features"
4877

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ documentation = "https://docs.rs/crate/linked_list_allocator"
1212
homepage = "http://os.phil-opp.com/kernel-heap.html#a-better-allocator"
1313

1414
[features]
15-
default = ["use_spin"]
15+
default = ["use_spin", "const_mut_refs"]
1616
use_spin = ["spinning_top"]
1717
alloc_ref = []
18+
const_mut_refs = []
1819

1920
[dependencies.spinning_top]
2021
version = "0.1.0"

src/hole.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ pub struct HoleList {
1111

1212
impl HoleList {
1313
/// Creates an empty `HoleList`.
14+
#[cfg(not(feature = "const_mut_refs"))]
15+
pub fn empty() -> HoleList {
16+
HoleList {
17+
first: Hole {
18+
size: 0,
19+
next: None,
20+
},
21+
}
22+
}
23+
24+
/// Creates an empty `HoleList`.
25+
#[cfg(feature = "const_mut_refs")]
1426
pub const fn empty() -> HoleList {
1527
HoleList {
1628
first: Hole {
@@ -26,7 +38,7 @@ impl HoleList {
2638
///
2739
/// The pointer to `hole_addr` is automatically aligned.
2840
pub unsafe fn new(hole_addr: usize, hole_size: usize) -> HoleList {
29-
assert!(size_of::<Hole>() == Self::min_size());
41+
assert_eq!(size_of::<Hole>(), Self::min_size());
3042

3143
let aligned_hole_addr = align_up(hole_addr, align_of::<Hole>());
3244
let ptr = aligned_hole_addr as *mut Hole;

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(const_mut_refs)]
1+
#![cfg_attr(feature = "const_mut_refs", feature(const_mut_refs))]
22
#![cfg_attr(
33
feature = "alloc_ref",
44
feature(allocator_api, alloc_layout_extra, nonnull_slice_from_raw_parts)
@@ -41,6 +41,17 @@ pub struct Heap {
4141

4242
impl Heap {
4343
/// Creates an empty heap. All allocate calls will return `None`.
44+
#[cfg(not(feature = "const_mut_refs"))]
45+
pub fn empty() -> Heap {
46+
Heap {
47+
bottom: 0,
48+
size: 0,
49+
used: 0,
50+
holes: HoleList::empty(),
51+
}
52+
}
53+
54+
#[cfg(feature = "const_mut_refs")]
4455
pub const fn empty() -> Heap {
4556
Heap {
4657
bottom: 0,

0 commit comments

Comments
 (0)