Skip to content

ci: refactoring: less code duplication #125

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 1 commit into from
Mar 17, 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
75 changes: 75 additions & 0 deletions .github/workflows/_build-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Reusable GitHub CI workflow:
# More info: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iduses

# Common Rust CI setup that checkout the repo, installs the common toolchain
# and set's up the cargo cache. It builds, tests, and lints the code.

on:
workflow_call:
inputs:
rust-version:
type: string
required: false
default: stable
description: Rust version
rust-target:
type: string
required: false
default: x86_64-unknown-linux-gnu
description: Rust target for the build step. Clippy and tests are still executed with the default target.
do-style-check:
type: boolean
required: false
default: true
description: Whether style checks should be done.
do-test:
type: boolean
required: false
default: true
description: Whether tests should be executed.

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ inputs.rust-version }}
override: true
components: clippy, rustfmt
target: ${{ inputs.rust-target }}
- name: Set up cargo cache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- run: cargo version
- name: Code Formatting
if: ${{ inputs.do-style-check }}
run: cargo fmt --all -- --check
- name: Build (library)
run: cargo build --target ${{ inputs.rust-target }}
- name: Build (all targets)
run: cargo build --all-targets
- name: Code Style and Doc Style
if: ${{ inputs.do-style-check }}
run: |
cargo doc --document-private-items
cargo clippy --all-targets
- name: Unit Test
if: ${{ inputs.do-test }}
run: |
curl -LsSf https://get.nexte.st/latest/linux | tar zxf -
chmod u+x cargo-nextest
./cargo-nextest nextest run
166 changes: 68 additions & 98 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,107 +1,77 @@
name: Build
# CI for the whole Cargo workspace. Although having two relatively independent
# crates in this workspace (as they do not get released together, as for example
# tokio with its sub crates), a PR for a certain CI may report errors in the
# other workspace members. I think this is unfortunate. I've experimented with
# CI runs per workspace member but the complexity in the end was not worth it.
# Instead, it is the right thing that the CI always covers the whole repository
# and that it is as stable as possible.

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
name: "Cargo workspace"

# Run on every push (tag, branch) and pull_request
on: [pull_request, push, workflow_dispatch]

env:
CARGO_TERM_COLOR: always

jobs:
# Regular build (with std) + test execution
build:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- nightly
- 1.52.1 # MSVR
steps:
- uses: actions/checkout@v3
# Important preparation step: override the latest default Rust version in GitHub CI
# with the current value of the iteration in the "strategy.matrix.rust"-array.
- uses: actions-rs/toolchain@v1
with:
profile: default
toolchain: ${{ matrix.rust }}
override: true
# helps to identify if the right cargo version is actually used
- run: cargo version
- name: Build
run: cargo build --all-targets --verbose
- name: Run tests
run: cargo test --verbose
build_multiboot2_msrv:
name: "build (msrv)"
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: 1.56.1
do-style-check: false

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

build_multiboot2_nightly:
name: "build (nightly)"
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: nightly
do-style-check: false

build_nostd_multiboot2_msrv:
name: "build no_std (msrv)"
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: 1.56.1
do-style-check: false
rust-target: thumbv7em-none-eabihf

build_nostd_multiboot2_stable:
name: "build no_std (stable)"
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: stable
do-style-check: false
rust-target: thumbv7em-none-eabihf

# no-std build without tests
build_no_std:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- nightly
- 1.52.1 # MSVR
steps:
- uses: actions/checkout@v3
# Important preparation step: override the latest default Rust version in GitHub CI
# with the current value of the iteration in the "strategy.matrix.rust"-array.
- uses: actions-rs/toolchain@v1
with:
profile: default
toolchain: ${{ matrix.rust }}
override: true
# helps to identify if the right cargo version is actually used
- run: cargo version
- name: "Rustup: install some no_std target"
run: rustup target add thumbv7em-none-eabihf
- name: Build (no_std)
run: cargo build --target thumbv7em-none-eabihf
build_nostd_multiboot2_nightly:
name: "build no_std (nightly)"
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: nightly
do-style-check: false
rust-target: thumbv7em-none-eabihf

# Tests that the unstable feature, which requires nightly, builds.
build_unstable:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- nightly
steps:
- uses: actions/checkout@v3
# Important preparation step: override the latest default Rust version in GitHub CI
# with the current value of the iteration in the "strategy.matrix.rust"-array.
- uses: actions-rs/toolchain@v1
with:
profile: default
toolchain: ${{ matrix.rust }}
override: true
- name: Build (unstable)
run: cargo build --all-targets --features unstable
- name: Test (unstable)
run: cargo test --all-targets --features unstable
style_multiboot2_msrv:
name: "style (msrv)"
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: 1.56.1
do-style-check: true
do-test: false

# As discussed, these tasks are optional for PRs.
style_checks:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- 1.52.1 # MSVR
steps:
- uses: actions/checkout@v3
# Important preparation step: override the latest default Rust version in GitHub CI
# with the current value of the iteration in the "strategy.matrix.rust"-array.
- uses: actions-rs/toolchain@v1
with:
profile: default
toolchain: ${{ matrix.rust }}
override: true
# helps to identify if the right cargo version is actually used
- run: cargo version
- name: Rustfmt
run: cargo fmt -- --check
- name: Clippy
run: cargo clippy --all-targets
- name: Rustdoc
run: cargo doc --document-private-items
style_multiboot2_stable:
name: "style (stable)"
uses: ./.github/workflows/_build-rust.yml
with:
rust-version: stable
do-style-check: true
do-test: false
1 change: 1 addition & 0 deletions multiboot2-header/src/builder/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ mod tests {
c: u128,
}
impl StructAsBytes for Foobar {}
#[allow(clippy::blacklisted_name)]
let foo = Foobar {
a: 11,
b: 22,
Expand Down
2 changes: 2 additions & 0 deletions multiboot2-header/src/information_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ mod tests {
use crate::InformationRequestHeaderTag;

#[test]
#[allow(clippy::erasing_op)]
#[allow(clippy::identity_op)]
fn test_assert_size() {
assert_eq!(
core::mem::size_of::<InformationRequestHeaderTag<0>>(),
Expand Down
1 change: 0 additions & 1 deletion multiboot2-header/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

#![no_std]
#![deny(rustdoc::all)]
#![allow(rustdoc::missing_doc_code_examples)]
#![deny(clippy::all)]
#![deny(clippy::missing_const_for_fn)]
#![deny(missing_debug_implementations)]
Expand Down
11 changes: 4 additions & 7 deletions multiboot2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#![deny(clippy::all)]
#![deny(rustdoc::all)]
#![allow(rustdoc::private_doc_tests)]
#![allow(rustdoc::missing_doc_code_examples)]
// --- END STYLE CHECKS ---

//! Library that helps you to parse the multiboot information structure (mbi) from
Expand Down Expand Up @@ -550,9 +549,8 @@ mod tests {
}

#[test]
/// Compile time test for `BootLoaderNameTag`.
/// Compile time test for [`BootLoaderNameTag`].
fn name_tag_size() {
use BootLoaderNameTag;
unsafe {
core::mem::transmute::<[u8; 9], BootLoaderNameTag>([0u8; 9]);
}
Expand Down Expand Up @@ -850,9 +848,8 @@ mod tests {
}

#[test]
/// Compile time test for `VBEInfoTag`.
/// Compile time test for [`VBEInfoTag`].
fn vbe_info_tag_size() {
use VBEInfoTag;
unsafe {
// 16 for the start + 512 from `VBEControlInfo` + 256 from `VBEModeInfo`.
core::mem::transmute::<[u8; 784], VBEInfoTag>([0u8; 784]);
Expand Down Expand Up @@ -1330,7 +1327,7 @@ mod tests {
let bi = bi.unwrap();
assert_eq!(addr, bi.start_address());
assert_eq!(addr + bytes.0.len(), bi.end_address());
assert_eq!(bytes.0.len(), bi.total_size() as usize);
assert_eq!(bytes.0.len(), bi.total_size());
let es = bi.elf_sections_tag().unwrap();
let mut s = es.sections();
let s1 = s.next().unwrap();
Expand Down Expand Up @@ -1384,7 +1381,7 @@ mod tests {
let bi = bi.unwrap();
assert_eq!(addr, bi.start_address());
assert_eq!(addr + bytes.0.len(), bi.end_address());
assert_eq!(bytes.0.len(), bi.total_size() as usize);
assert_eq!(bytes.0.len(), bi.total_size());
let efi_memory_map = bi.efi_memory_map_tag().unwrap();
let mut efi_mmap_iter = efi_memory_map.memory_areas();
let desc = efi_mmap_iter.next().unwrap();
Expand Down