Skip to content

Commit 4908653

Browse files
authored
Merge pull request #141 from rust-osdev/dev
treewide: code improvements and other stuff
2 parents 714905b + 0742074 commit 4908653

24 files changed

+191
-238
lines changed

.github/workflows/_build-rust.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,27 @@ jobs:
8080
key: ${{ runner.os }}-rust-${{ inputs.rust-version }}-cargo-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
8181
- run: cargo version
8282
- name: Build (library)
83-
run: cargo build --target ${{ inputs.rust-target }} --features ${{ inputs.features }}
83+
run: cargo build --target ${{ inputs.rust-target }} --features ${{ inputs.features }} --no-default-features
8484
- name: Build (all targets)
85-
run: cargo build --all-targets --features ${{ inputs.features }}
85+
run: cargo build --all-targets --features ${{ inputs.features }} --no-default-features
8686
- name: Code Formatting
8787
if: inputs.do-style-check
8888
run: cargo fmt --all -- --check
8989
- name: Code Style and Doc Style
9090
if: inputs.do-style-check
9191
run: |
92-
cargo doc --document-private-items --features ${{ inputs.features }}
93-
cargo clippy --all-targets --features ${{ inputs.features }}
92+
cargo doc --document-private-items --features ${{ inputs.features }} --no-default-features
93+
cargo clippy --all-targets --features ${{ inputs.features }} --no-default-features
9494
- name: Unit Test (UNIX)
9595
if: inputs.do-test && runner.os != 'Windows'
9696
run: |
9797
curl -LsSf https://get.nexte.st/latest/linux | tar zxf -
9898
chmod u+x cargo-nextest
99-
./cargo-nextest nextest run --features ${{ inputs.features }}
99+
./cargo-nextest nextest run --features ${{ inputs.features }} --no-default-features
100100
- name: Unit Test (Windows)
101101
if: inputs.do-test && runner.os == 'Windows'
102102
run: |
103103
Invoke-WebRequest https://get.nexte.st/latest/windows -OutFile cargo-nextest.zip
104104
Expand-Archive .\cargo-nextest.zip
105105
cp .\cargo-nextest/cargo-nextest.exe .
106-
.\cargo-nextest.exe nextest run --features ${{ inputs.features }}
106+
.\cargo-nextest.exe nextest run --features ${{ inputs.features }} --no-default-features

.github/workflows/rust.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,36 @@ jobs:
2020
name: build (msrv)
2121
uses: ./.github/workflows/_build-rust.yml
2222
with:
23-
rust-version: 1.56.1
23+
rust-version: 1.68.0 # MSRV
2424
do-style-check: false
25+
features: builder
2526

2627
build_stable:
2728
name: build (stable)
2829
uses: ./.github/workflows/_build-rust.yml
2930
with:
3031
rust-version: stable
3132
do-style-check: false
33+
features: builder
3234

3335
build_nightly:
3436
name: build (nightly)
3537
uses: ./.github/workflows/_build-rust.yml
3638
with:
3739
rust-version: nightly
3840
do-style-check: false
39-
features: unstable
41+
features: builder,unstable
4042

4143
### no-std Build #########################
4244
build_nostd_msrv:
4345
name: build no_std (msrv)
4446
needs: build_msrv
4547
uses: ./.github/workflows/_build-rust.yml
4648
with:
47-
rust-version: 1.56.1
49+
rust-version: 1.68.0 # MSRV
4850
do-style-check: false
4951
rust-target: thumbv7em-none-eabihf
52+
features: builder
5053

5154
build_nostd_stable:
5255
name: build no_std (stable)
@@ -56,6 +59,17 @@ jobs:
5659
rust-version: stable
5760
do-style-check: false
5861
rust-target: thumbv7em-none-eabihf
62+
features: builder
63+
64+
# Also tests the build one time without the "builder" feature.
65+
build_nostd_stable_no_builder:
66+
name: build no_std (stable) [w/o builder]
67+
needs: build_stable
68+
uses: ./.github/workflows/_build-rust.yml
69+
with:
70+
rust-version: stable
71+
do-style-check: false
72+
rust-target: thumbv7em-none-eabihf
5973

6074
# We perform one single run also in Windows. This should be sufficient to
6175
# check that devs can also use this on Windows.
@@ -65,11 +79,12 @@ jobs:
6579
with:
6680
runs-on: windows-latest
6781
# Quirk for the Windows powershell and its handling of empty arguments.
68-
features: >
69-
'""'
82+
# features: >
83+
# '""'
7084
rust-version: stable
7185
do-style-check: false
7286
rust-target: thumbv7em-none-eabihf
87+
features: builder
7388

7489
build_nostd_nightly:
7590
name: build no_std (nightly)
@@ -79,17 +94,18 @@ jobs:
7994
rust-version: nightly
8095
do-style-check: false
8196
rust-target: thumbv7em-none-eabihf
82-
features: unstable
97+
features: builder,unstable
8398

8499
### Style Checks + Doc #####################
85100
style_msrv:
86101
name: style (msrv)
87102
needs: build_msrv
88103
uses: ./.github/workflows/_build-rust.yml
89104
with:
90-
rust-version: 1.56.1
105+
rust-version: 1.68.0 # MSRV
91106
do-style-check: true
92107
do-test: false
108+
features: builder
93109

94110
style_stable:
95111
name: style (stable)
@@ -99,6 +115,7 @@ jobs:
99115
rust-version: stable
100116
do-style-check: true
101117
do-test: false
118+
features: builder
102119

103120
style_nightly:
104121
name: style (nightly)
@@ -108,4 +125,4 @@ jobs:
108125
rust-version: nightly
109126
do-style-check: true
110127
do-test: false
111-
features: unstable
128+
features: builder,unstable

Cargo.lock

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

multiboot2-header/Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ readme = "README.md"
2626
homepage = "https://github.com/rust-osdev/multiboot2-header"
2727
repository = "https://github.com/rust-osdev/multiboot2"
2828
documentation = "https://docs.rs/multiboot2-header"
29+
rust-version = "1.60"
30+
31+
[[example]]
32+
name = "minimal"
33+
required-features = ["builder"]
2934

3035
[features]
31-
# by default, builder is included
3236
default = ["builder"]
33-
std = []
34-
builder = ["std"]
37+
alloc = []
38+
builder = ["alloc"]
39+
# Nightly-only features, which will eventually be stabilized.
40+
unstable = []
3541

3642
[dependencies]
3743
# used for MBI tags

multiboot2-header/Changelog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# CHANGELOG for crate `multiboot2-header`
22

33
## Unreleased
4-
- MSRV is 1.56.1
4+
- MSRV is 1.68.0
5+
- renamed the `std` feature to `alloc`
6+
- added the optional `unstable` feature (requires nightly)
7+
- implement `core::error::Error` for `LoadError`
58

69
## v0.2.0 (2022-05-03)
710
- **BREAKING** renamed `EntryHeaderTag` to `EntryAddressHeaderTag`

multiboot2-header/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ 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.
18+
## Features and `no_std` Compatibility
19+
This library is always `no_std`. However, the default `builder`-feature requires
20+
the `alloc`-crate to be available. You need the `builder` only if you want to
21+
construct new headers at run time. For parsing, this is not relevant, and you
22+
can deactivate the default feature.
2223

2324
```toml
2425
# without `builder`-feature (and without `alloc`-crate)

multiboot2-header/src/builder/traits.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
EntryAddressHeaderTag, EntryEfi32HeaderTag, EntryEfi64HeaderTag, FramebufferHeaderTag,
66
InformationRequestHeaderTag, ModuleAlignHeaderTag, Multiboot2BasicHeader, RelocatableHeaderTag,
77
};
8+
use alloc::vec::Vec;
89
use core::mem::size_of;
910

1011
/// Trait for all tags that helps to create a byte array from the tag.
@@ -24,13 +25,10 @@ pub(crate) trait StructAsBytes: Sized {
2425

2526
/// Returns the structure as a vector of its bytes.
2627
/// The length is determined by [`Self::byte_size`].
27-
fn struct_as_bytes(&self) -> alloc::vec::Vec<u8> {
28+
fn struct_as_bytes(&self) -> Vec<u8> {
2829
let ptr = self.as_ptr();
29-
let mut vec = alloc::vec::Vec::with_capacity(self.byte_size());
30-
for i in 0..self.byte_size() {
31-
vec.push(unsafe { *ptr.add(i) })
32-
}
33-
vec
30+
let bytes = unsafe { core::slice::from_raw_parts(ptr, self.byte_size()) };
31+
Vec::from(bytes)
3432
}
3533
}
3634

multiboot2-header/src/header.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
RelocatableHeaderTag,
66
};
77
use core::convert::TryInto;
8-
use core::fmt::{Debug, Formatter};
8+
use core::fmt::{Debug, Display, Formatter};
99
use core::mem::size_of;
1010

1111
/// Magic value for a [`Multiboot2Header`], as defined in spec.
@@ -212,6 +212,15 @@ pub enum LoadError {
212212
TooSmall,
213213
}
214214

215+
impl Display for LoadError {
216+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
217+
write!(f, "{:?}", self)
218+
}
219+
}
220+
221+
#[cfg(feature = "unstable")]
222+
impl core::error::Error for LoadError {}
223+
215224
/// **Use this only if you know what you do. You probably want to use
216225
/// [`Multiboot2Header`] instead.**
217226
///

multiboot2-header/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
//! The MSRV is 1.56.1 stable.
3535
3636
#![no_std]
37+
#![cfg_attr(feature = "unstable", feature(error_in_core))]
3738
#![deny(rustdoc::all)]
3839
#![deny(clippy::all)]
3940
#![deny(clippy::missing_const_for_fn)]
@@ -77,6 +78,5 @@ pub use self::relocatable::*;
7778
pub use self::tags::*;
7879
pub use self::uefi_bs::*;
7980

80-
/// Re-export of [`multiboot2::TagType`] from `multiboot2`-crate as `MbiTagType`, i.e. tags that
81-
/// describe the entries in the Multiboot2 Information Structure (MBI).
81+
/// Re-export of [`multiboot2::TagType`] from `multiboot2`-crate.
8282
pub use multiboot2::TagType as MbiTagType;

multiboot2/Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,26 @@ keywords = [
2323
"Multiboot2",
2424
"kernel",
2525
"boot",
26+
"bootloader",
2627
]
2728
# without this, sometimes crates.io doesn't show the preview of the README
2829
# I expeciended this multiple times in the past
2930
readme = "README.md"
3031
homepage = "https://github.com/rust-osdev/multiboot2"
3132
repository = "https://github.com/rust-osdev/multiboot2"
3233
documentation = "https://docs.rs/multiboot2"
34+
rust-version = "1.60"
3335

3436
[features]
35-
# by default, builder is included
3637
default = ["builder"]
37-
std = []
38-
builder = ["std"]
39-
# Nightly-only features that will eventually be stabilized.
38+
alloc = []
39+
builder = ["alloc"]
40+
# Nightly-only features, which will eventually be stabilized.
4041
unstable = []
4142

4243
[dependencies]
43-
bitflags = "1"
44+
bitflags = "2"
4445
derive_more = { version = "0.99", default-features = false, features = ["display"] }
4546
log = { version = "0.4", default-features = false }
47+
uefi-raw = { version = "0.2.0", default-features = false }
4648
ptr_meta = { version = "0.2.0", default-features = false }

multiboot2/Changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
name tag. However, this might also be relevant for users of custom multiboot2
77
tags that use DSTs as types. See the example provided in the doc of the
88
`get_tag` method.
9+
- renamed `MULTIBOOT2_BOOTLOADER_MAGIC` to `MAGIC`
10+
- added a `builder` feature and a `builder` module with a `Multiboot2InformationBuilder`
11+
struct
12+
- `EFIMemoryDesc` was removed and is now an alias of
13+
`uefi_raw::table::boot::MemoryDescriptor`
14+
- `EFIMemoryAreaType` was removed and is now an alias of
15+
`uefi_raw::table::boot::MemoryType`
16+
- MSRV is 1.68.0
917

1018
## 0.15.1 (2023-03-18)
1119
- **BREAKING** `MemoryMapTag::all_memory_areas()` was renamed to `memory_areas`

multiboot2/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ used in a Multiboot2-kernel.
1010

1111
It follows the Multiboot 2.0 specification at https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html and the ELF 64 specification at http://www.uclibc.org/docs/elf-64-gen.pdf.
1212

13+
## Features and `no_std` Compatibility
14+
This library is always `no_std`. However, the default `builder`-feature requires
15+
the `alloc`-crate to be available. You need the `builder` only if you want to
16+
construct new boot information structures at run time. For parsing, this is not
17+
relevant, and you can deactivate the default feature.
18+
1319
## Background: The Multiboot 2 Information Structure
1420
The Multiboot information structure looks like this:
1521

multiboot2/src/boot_loader_name.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use crate::{Tag, TagTrait, TagType, TagTypeId};
1+
use crate::{Tag, TagTrait, TagTypeId};
22
use core::fmt::{Debug, Formatter};
33
use core::mem::size_of;
44
use core::str::Utf8Error;
55

66
#[cfg(feature = "builder")]
77
use {
8-
crate::builder::boxed_dst_tag, crate::builder::traits::StructAsBytes, alloc::boxed::Box,
9-
alloc::vec::Vec,
8+
crate::builder::boxed_dst_tag, crate::builder::traits::StructAsBytes, crate::TagType,
9+
alloc::boxed::Box, alloc::vec::Vec,
1010
};
1111

1212
const METADATA_SIZE: usize = size_of::<TagTypeId>() + size_of::<u32>();

0 commit comments

Comments
 (0)