Skip to content

treewide: code improvements and other stuff #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/_build-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,27 @@ jobs:
key: ${{ runner.os }}-rust-${{ inputs.rust-version }}-cargo-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
- run: cargo version
- name: Build (library)
run: cargo build --target ${{ inputs.rust-target }} --features ${{ inputs.features }}
run: cargo build --target ${{ inputs.rust-target }} --features ${{ inputs.features }} --no-default-features
- name: Build (all targets)
run: cargo build --all-targets --features ${{ inputs.features }}
run: cargo build --all-targets --features ${{ inputs.features }} --no-default-features
- name: Code Formatting
if: inputs.do-style-check
run: cargo fmt --all -- --check
- name: Code Style and Doc Style
if: inputs.do-style-check
run: |
cargo doc --document-private-items --features ${{ inputs.features }}
cargo clippy --all-targets --features ${{ inputs.features }}
cargo doc --document-private-items --features ${{ inputs.features }} --no-default-features
cargo clippy --all-targets --features ${{ inputs.features }} --no-default-features
- name: Unit Test (UNIX)
if: inputs.do-test && runner.os != 'Windows'
run: |
curl -LsSf https://get.nexte.st/latest/linux | tar zxf -
chmod u+x cargo-nextest
./cargo-nextest nextest run --features ${{ inputs.features }}
./cargo-nextest nextest run --features ${{ inputs.features }} --no-default-features
- name: Unit Test (Windows)
if: inputs.do-test && runner.os == 'Windows'
run: |
Invoke-WebRequest https://get.nexte.st/latest/windows -OutFile cargo-nextest.zip
Expand-Archive .\cargo-nextest.zip
cp .\cargo-nextest/cargo-nextest.exe .
.\cargo-nextest.exe nextest run --features ${{ inputs.features }}
.\cargo-nextest.exe nextest run --features ${{ inputs.features }} --no-default-features
33 changes: 25 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,36 @@ jobs:
name: build (msrv)
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: 1.56.1
rust-version: 1.68.0 # MSRV
do-style-check: false
features: builder

build_stable:
name: build (stable)
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: stable
do-style-check: false
features: builder

build_nightly:
name: build (nightly)
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: nightly
do-style-check: false
features: unstable
features: builder,unstable

### no-std Build #########################
build_nostd_msrv:
name: build no_std (msrv)
needs: build_msrv
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: 1.56.1
rust-version: 1.68.0 # MSRV
do-style-check: false
rust-target: thumbv7em-none-eabihf
features: builder

build_nostd_stable:
name: build no_std (stable)
Expand All @@ -56,6 +59,17 @@ jobs:
rust-version: stable
do-style-check: false
rust-target: thumbv7em-none-eabihf
features: builder

# Also tests the build one time without the "builder" feature.
build_nostd_stable_no_builder:
name: build no_std (stable) [w/o builder]
needs: build_stable
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: stable
do-style-check: false
rust-target: thumbv7em-none-eabihf

# We perform one single run also in Windows. This should be sufficient to
# check that devs can also use this on Windows.
Expand All @@ -65,11 +79,12 @@ jobs:
with:
runs-on: windows-latest
# Quirk for the Windows powershell and its handling of empty arguments.
features: >
'""'
# features: >
# '""'
rust-version: stable
do-style-check: false
rust-target: thumbv7em-none-eabihf
features: builder

build_nostd_nightly:
name: build no_std (nightly)
Expand All @@ -79,17 +94,18 @@ jobs:
rust-version: nightly
do-style-check: false
rust-target: thumbv7em-none-eabihf
features: unstable
features: builder,unstable

### Style Checks + Doc #####################
style_msrv:
name: style (msrv)
needs: build_msrv
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: 1.56.1
rust-version: 1.68.0 # MSRV
do-style-check: true
do-test: false
features: builder

style_stable:
name: style (stable)
Expand All @@ -99,6 +115,7 @@ jobs:
rust-version: stable
do-style-check: true
do-test: false
features: builder

style_nightly:
name: style (nightly)
Expand All @@ -108,4 +125,4 @@ jobs:
rust-version: nightly
do-style-check: true
do-test: false
features: unstable
features: builder,unstable
28 changes: 26 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions multiboot2-header/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ readme = "README.md"
homepage = "https://github.com/rust-osdev/multiboot2-header"
repository = "https://github.com/rust-osdev/multiboot2"
documentation = "https://docs.rs/multiboot2-header"
rust-version = "1.60"

[[example]]
name = "minimal"
required-features = ["builder"]

[features]
# by default, builder is included
default = ["builder"]
std = []
builder = ["std"]
alloc = []
builder = ["alloc"]
# Nightly-only features, which will eventually be stabilized.
unstable = []

[dependencies]
# used for MBI tags
Expand Down
5 changes: 4 additions & 1 deletion multiboot2-header/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# CHANGELOG for crate `multiboot2-header`

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

## v0.2.0 (2022-05-03)
- **BREAKING** renamed `EntryHeaderTag` to `EntryAddressHeaderTag`
Expand Down
9 changes: 5 additions & 4 deletions multiboot2-header/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ What this library is good for:
What this library is not optimal for:
- compiling a Multiboot2 header statically into an object file using only Rust code

## Features and Usage in `no_std`
This library is always `no_std`. However, the `builder`-feature requires the `alloc`-crate
to be available. You need the `builder` only if you want to construct new headers. For parsing,
this is not relevant.
## Features and `no_std` Compatibility
This library is always `no_std`. However, the default `builder`-feature requires
the `alloc`-crate to be available. You need the `builder` only if you want to
construct new headers at run time. For parsing, this is not relevant, and you
can deactivate the default feature.

```toml
# without `builder`-feature (and without `alloc`-crate)
Expand Down
10 changes: 4 additions & 6 deletions multiboot2-header/src/builder/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
EntryAddressHeaderTag, EntryEfi32HeaderTag, EntryEfi64HeaderTag, FramebufferHeaderTag,
InformationRequestHeaderTag, ModuleAlignHeaderTag, Multiboot2BasicHeader, RelocatableHeaderTag,
};
use alloc::vec::Vec;
use core::mem::size_of;

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

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

Expand Down
11 changes: 10 additions & 1 deletion multiboot2-header/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
RelocatableHeaderTag,
};
use core::convert::TryInto;
use core::fmt::{Debug, Formatter};
use core::fmt::{Debug, Display, Formatter};
use core::mem::size_of;

/// Magic value for a [`Multiboot2Header`], as defined in spec.
Expand Down Expand Up @@ -212,6 +212,15 @@ pub enum LoadError {
TooSmall,
}

impl Display for LoadError {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{:?}", self)
}
}

#[cfg(feature = "unstable")]
impl core::error::Error for LoadError {}

/// **Use this only if you know what you do. You probably want to use
/// [`Multiboot2Header`] instead.**
///
Expand Down
4 changes: 2 additions & 2 deletions multiboot2-header/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
//! The MSRV is 1.56.1 stable.
#![no_std]
#![cfg_attr(feature = "unstable", feature(error_in_core))]
#![deny(rustdoc::all)]
#![deny(clippy::all)]
#![deny(clippy::missing_const_for_fn)]
Expand Down Expand Up @@ -77,6 +78,5 @@ pub use self::relocatable::*;
pub use self::tags::*;
pub use self::uefi_bs::*;

/// Re-export of [`multiboot2::TagType`] from `multiboot2`-crate as `MbiTagType`, i.e. tags that
/// describe the entries in the Multiboot2 Information Structure (MBI).
/// Re-export of [`multiboot2::TagType`] from `multiboot2`-crate.
pub use multiboot2::TagType as MbiTagType;
12 changes: 7 additions & 5 deletions multiboot2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@ keywords = [
"Multiboot2",
"kernel",
"boot",
"bootloader",
]
# without this, sometimes crates.io doesn't show the preview of the README
# I expeciended this multiple times in the past
readme = "README.md"
homepage = "https://github.com/rust-osdev/multiboot2"
repository = "https://github.com/rust-osdev/multiboot2"
documentation = "https://docs.rs/multiboot2"
rust-version = "1.60"

[features]
# by default, builder is included
default = ["builder"]
std = []
builder = ["std"]
# Nightly-only features that will eventually be stabilized.
alloc = []
builder = ["alloc"]
# Nightly-only features, which will eventually be stabilized.
unstable = []

[dependencies]
bitflags = "1"
bitflags = "2"
derive_more = { version = "0.99", default-features = false, features = ["display"] }
log = { version = "0.4", default-features = false }
uefi-raw = { version = "0.2.0", default-features = false }
ptr_meta = { version = "0.2.0", default-features = false }
8 changes: 8 additions & 0 deletions multiboot2/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
name tag. However, this might also be relevant for users of custom multiboot2
tags that use DSTs as types. See the example provided in the doc of the
`get_tag` method.
- renamed `MULTIBOOT2_BOOTLOADER_MAGIC` to `MAGIC`
- added a `builder` feature and a `builder` module with a `Multiboot2InformationBuilder`
struct
- `EFIMemoryDesc` was removed and is now an alias of
`uefi_raw::table::boot::MemoryDescriptor`
- `EFIMemoryAreaType` was removed and is now an alias of
`uefi_raw::table::boot::MemoryType`
- MSRV is 1.68.0

## 0.15.1 (2023-03-18)
- **BREAKING** `MemoryMapTag::all_memory_areas()` was renamed to `memory_areas`
Expand Down
6 changes: 6 additions & 0 deletions multiboot2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ used in a Multiboot2-kernel.

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.

## Features and `no_std` Compatibility
This library is always `no_std`. However, the default `builder`-feature requires
the `alloc`-crate to be available. You need the `builder` only if you want to
construct new boot information structures at run time. For parsing, this is not
relevant, and you can deactivate the default feature.

## Background: The Multiboot 2 Information Structure
The Multiboot information structure looks like this:

Expand Down
6 changes: 3 additions & 3 deletions multiboot2/src/boot_loader_name.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{Tag, TagTrait, TagType, TagTypeId};
use crate::{Tag, TagTrait, TagTypeId};
use core::fmt::{Debug, Formatter};
use core::mem::size_of;
use core::str::Utf8Error;

#[cfg(feature = "builder")]
use {
crate::builder::boxed_dst_tag, crate::builder::traits::StructAsBytes, alloc::boxed::Box,
alloc::vec::Vec,
crate::builder::boxed_dst_tag, crate::builder::traits::StructAsBytes, crate::TagType,
alloc::boxed::Box, alloc::vec::Vec,
};

const METADATA_SIZE: usize = size_of::<TagTypeId>() + size_of::<u32>();
Expand Down
Loading