Skip to content

Commit cf6c1c6

Browse files
authored
Merge pull request #102 from rust-osdev/mb2-hdr-no-std-fix
multiboot2-header: fix `no_std`-build + v0.1.1
2 parents 8adc3e0 + 72bf91d commit cf6c1c6

16 files changed

+79
-32
lines changed

multiboot2-header/Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description = """
44
Library with type definitions and parsing functions for Multiboot2 headers.
55
This library is `no_std` and can be used in bootloaders.
66
"""
7-
version = "0.1.0"
7+
version = "0.1.1"
88
authors = [
99
"Philipp Schuster <phip1611@gmail.com>"
1010
]
@@ -27,6 +27,12 @@ homepage = "https://github.com/rust-osdev/multiboot2-header"
2727
repository = "https://github.com/rust-osdev/multiboot2"
2828
documentation = "https://docs.rs/multiboot2-header"
2929

30+
[features]
31+
# by default, builder is included
32+
default = ["builder"]
33+
std = []
34+
builder = ["std"]
35+
3036
[dependencies]
3137
# used for MBI tags
32-
multiboot2 = "0.12.2"
38+
multiboot2 = "0.13.2"

multiboot2-header/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ What this library is good for:
1515
What this library is not optimal for:
1616
- compiling a Multiboot2 header statically into an object file using only Rust code
1717

18+
## Features and Usage in `no_std`
19+
This library is always `no_std`. However, the `builder`-feature requires the `alloc`-crate
20+
to be available. You need the `builder` only if you want to construct new headers. For parsing,
21+
this is not relevant.
22+
23+
```toml
24+
# without `builder`-feature (and without `alloc`-crate)
25+
multiboot2-header = { version = "<latest>", default-features = false }
26+
# else (requires `alloc`-crate)
27+
multiboot2-header = "<latest>"
28+
```
29+
1830
## Example 1: Builder + Parse
1931
```rust
2032
use multiboot2_header::builder::Multiboot2HeaderBuilder;

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.

0 commit comments

Comments
 (0)