Skip to content

Commit 0a9cc9e

Browse files
committed
multiboot2-header: no_std works + builder-feature
1 parent 8adc3e0 commit 0a9cc9e

File tree

14 files changed

+59
-30
lines changed

14 files changed

+59
-30
lines changed

multiboot2-header/src/address.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{HeaderTagFlag, HeaderTagType, StructAsBytes};
1+
use crate::{HeaderTagFlag, HeaderTagType};
22
use core::mem::size_of;
33

44
/// This information does not need to be provided if the kernel image is in ELF
@@ -65,4 +65,5 @@ impl AddressHeaderTag {
6565
}
6666
}
6767

68-
impl StructAsBytes for AddressHeaderTag {}
68+
#[cfg(feature = "builder")]
69+
impl crate::StructAsBytes for AddressHeaderTag {}

multiboot2-header/src/console.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{HeaderTagFlag, HeaderTagType, StructAsBytes};
1+
use crate::{HeaderTagFlag, HeaderTagType};
22
use core::mem::size_of;
33

44
/// Possible flags for [`ConsoleHeaderTag`].
@@ -46,7 +46,8 @@ impl ConsoleHeaderTag {
4646
}
4747
}
4848

49-
impl StructAsBytes for ConsoleHeaderTag {}
49+
#[cfg(feature = "builder")]
50+
impl crate::StructAsBytes for ConsoleHeaderTag {}
5051

5152
#[cfg(test)]
5253
mod tests {

multiboot2-header/src/end.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{HeaderTagFlag, HeaderTagType, StructAsBytes};
1+
use crate::{HeaderTagFlag, HeaderTagType};
22
use core::mem::size_of;
33

44
/// Terminates a list of optional tags
@@ -33,4 +33,5 @@ impl EndHeaderTag {
3333
}
3434
}
3535

36-
impl StructAsBytes for EndHeaderTag {}
36+
#[cfg(feature = "builder")]
37+
impl crate::StructAsBytes for EndHeaderTag {}

multiboot2-header/src/entry_efi_32.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{HeaderTagFlag, HeaderTagType, StructAsBytes};
1+
use crate::{HeaderTagFlag, HeaderTagType};
22
use core::fmt;
33
use core::fmt::{Debug, Formatter};
44
use core::mem::size_of;
@@ -50,4 +50,5 @@ impl Debug for EntryEfi32HeaderTag {
5050
}
5151
}
5252

53-
impl StructAsBytes for EntryEfi32HeaderTag {}
53+
#[cfg(feature = "builder")]
54+
impl crate::StructAsBytes for EntryEfi32HeaderTag {}

multiboot2-header/src/entry_efi_64.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{HeaderTagFlag, HeaderTagType, StructAsBytes};
1+
use crate::{HeaderTagFlag, HeaderTagType};
22
use core::fmt;
33
use core::fmt::{Debug, Formatter};
44
use core::mem::size_of;
@@ -50,4 +50,5 @@ impl Debug for EntryEfi64HeaderTag {
5050
}
5151
}
5252

53-
impl StructAsBytes for EntryEfi64HeaderTag {}
53+
#[cfg(feature = "builder")]
54+
impl crate::StructAsBytes for EntryEfi64HeaderTag {}

multiboot2-header/src/entry_header.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{HeaderTagFlag, HeaderTagType, StructAsBytes};
1+
use crate::{HeaderTagFlag, HeaderTagType};
22
use core::fmt;
33
use core::fmt::{Debug, Formatter};
44
use core::mem::size_of;
@@ -50,4 +50,5 @@ impl Debug for EntryHeaderTag {
5050
}
5151
}
5252

53-
impl StructAsBytes for EntryHeaderTag {}
53+
#[cfg(feature = "builder")]
54+
impl crate::StructAsBytes for EntryHeaderTag {}

multiboot2-header/src/framebuffer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{HeaderTagFlag, HeaderTagType, StructAsBytes};
1+
use crate::{HeaderTagFlag, HeaderTagType};
22
use core::mem::size_of;
33

44
/// Specifies the preferred graphics mode. If this tag
@@ -48,4 +48,5 @@ impl FramebufferHeaderTag {
4848
}
4949
}
5050

51-
impl StructAsBytes for FramebufferHeaderTag {}
51+
#[cfg(feature = "builder")]
52+
impl crate::StructAsBytes for FramebufferHeaderTag {}

multiboot2-header/src/header/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
EntryEfi64HeaderTag, EntryHeaderTag, FramebufferHeaderTag, InformationRequestHeaderTagBuilder,
77
ModuleAlignHeaderTag, Multiboot2BasicHeader, RelocatableHeaderTag, StructAsBytes,
88
};
9+
use alloc::vec::Vec;
910
use core::mem::size_of;
1011

1112
/// Builder to construct a valid Multiboot2 header dynamically at runtime.

multiboot2-header/src/header/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pub mod builder;
55

66
pub use self::builder::*;
7-
use crate::{AddressHeaderTag, InformationRequestHeaderTag, RelocatableHeaderTag, StructAsBytes};
7+
use crate::{AddressHeaderTag, InformationRequestHeaderTag, RelocatableHeaderTag};
88
use crate::{ConsoleHeaderTag, EntryHeaderTag};
99
use crate::{EfiBootServiceHeaderTag, FramebufferHeaderTag};
1010
use crate::{EndHeaderTag, HeaderTagType};
@@ -194,7 +194,8 @@ impl Debug for Multiboot2BasicHeader {
194194
}
195195
}
196196

197-
impl StructAsBytes for Multiboot2BasicHeader {}
197+
#[cfg(feature = "builder")]
198+
impl crate::StructAsBytes for Multiboot2BasicHeader {}
198199

199200
/// Iterator over all tags of a Multiboot2 header. The number of items is derived
200201
/// by the size/length of the header.

multiboot2-header/src/information_request.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
use crate::HeaderTagType;
2+
#[cfg(feature = "builder")]
3+
use crate::StructAsBytes;
14
use crate::{HeaderTagFlag, MbiTagType};
2-
use crate::{HeaderTagType, StructAsBytes};
5+
#[cfg(feature = "builder")]
6+
use alloc::collections::BTreeSet;
7+
#[cfg(feature = "builder")]
8+
use alloc::vec::Vec;
39
use core::fmt;
410
use core::fmt::{Debug, Formatter};
511
use core::marker::PhantomData;
612
use core::mem::size_of;
7-
use std::collections::HashSet;
813

914
/// Specifies what specific tag types the bootloader should provide
1015
/// inside the mbi.
@@ -87,21 +92,24 @@ impl<const N: usize> Debug for InformationRequestHeaderTag<N> {
8792
}
8893
}
8994

90-
impl<const N: usize> StructAsBytes for InformationRequestHeaderTag<N> {}
95+
#[cfg(feature = "builder")]
96+
impl<const N: usize> crate::StructAsBytes for InformationRequestHeaderTag<N> {}
9197

9298
/// Helper to build the dynamically sized [`InformationRequestHeaderTag`]
9399
/// at runtime.
94100
#[derive(Debug)]
101+
#[cfg(feature = "builder")]
95102
pub struct InformationRequestHeaderTagBuilder {
96103
flag: HeaderTagFlag,
97-
irs: HashSet<MbiTagType>,
104+
irs: BTreeSet<MbiTagType>,
98105
}
99106

107+
#[cfg(feature = "builder")]
100108
impl InformationRequestHeaderTagBuilder {
101109
/// New builder.
102110
pub fn new(flag: HeaderTagFlag) -> Self {
103111
Self {
104-
irs: HashSet::new(),
112+
irs: BTreeSet::new(),
105113
flag,
106114
}
107115
}

0 commit comments

Comments
 (0)