Skip to content

Commit 930fc48

Browse files
authored
Merge pull request #125 from rust-osdev/ci-refactoring
ci: refactoring: less code duplication
2 parents bdb0db1 + 7ab3460 commit 930fc48

File tree

6 files changed

+150
-106
lines changed

6 files changed

+150
-106
lines changed

.github/workflows/_build-rust.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Reusable GitHub CI workflow:
2+
# More info: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iduses
3+
4+
# Common Rust CI setup that checkout the repo, installs the common toolchain
5+
# and set's up the cargo cache. It builds, tests, and lints the code.
6+
7+
on:
8+
workflow_call:
9+
inputs:
10+
rust-version:
11+
type: string
12+
required: false
13+
default: stable
14+
description: Rust version
15+
rust-target:
16+
type: string
17+
required: false
18+
default: x86_64-unknown-linux-gnu
19+
description: Rust target for the build step. Clippy and tests are still executed with the default target.
20+
do-style-check:
21+
type: boolean
22+
required: false
23+
default: true
24+
description: Whether style checks should be done.
25+
do-test:
26+
type: boolean
27+
required: false
28+
default: true
29+
description: Whether tests should be executed.
30+
31+
jobs:
32+
build:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Check out
36+
uses: actions/checkout@v3
37+
- name: Install Rust
38+
uses: actions-rs/toolchain@v1
39+
with:
40+
profile: minimal
41+
toolchain: ${{ inputs.rust-version }}
42+
override: true
43+
components: clippy, rustfmt
44+
target: ${{ inputs.rust-target }}
45+
- name: Set up cargo cache
46+
uses: actions/cache@v3
47+
continue-on-error: false
48+
with:
49+
path: |
50+
~/.cargo/bin/
51+
~/.cargo/registry/index/
52+
~/.cargo/registry/cache/
53+
~/.cargo/git/db/
54+
target/
55+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
56+
restore-keys: ${{ runner.os }}-cargo-
57+
- run: cargo version
58+
- name: Code Formatting
59+
if: ${{ inputs.do-style-check }}
60+
run: cargo fmt --all -- --check
61+
- name: Build (library)
62+
run: cargo build --target ${{ inputs.rust-target }}
63+
- name: Build (all targets)
64+
run: cargo build --all-targets
65+
- name: Code Style and Doc Style
66+
if: ${{ inputs.do-style-check }}
67+
run: |
68+
cargo doc --document-private-items
69+
cargo clippy --all-targets
70+
- name: Unit Test
71+
if: ${{ inputs.do-test }}
72+
run: |
73+
curl -LsSf https://get.nexte.st/latest/linux | tar zxf -
74+
chmod u+x cargo-nextest
75+
./cargo-nextest nextest run

.github/workflows/rust.yml

+68-98
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,77 @@
1-
name: Build
1+
# CI for the whole Cargo workspace. Although having two relatively independent
2+
# crates in this workspace (as they do not get released together, as for example
3+
# tokio with its sub crates), a PR for a certain CI may report errors in the
4+
# other workspace members. I think this is unfortunate. I've experimented with
5+
# CI runs per workspace member but the complexity in the end was not worth it.
6+
# Instead, it is the right thing that the CI always covers the whole repository
7+
# and that it is as stable as possible.
28

3-
on:
4-
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
9+
name: "Cargo workspace"
10+
11+
# Run on every push (tag, branch) and pull_request
12+
on: [pull_request, push, workflow_dispatch]
813

914
env:
1015
CARGO_TERM_COLOR: always
1116

1217
jobs:
13-
# Regular build (with std) + test execution
14-
build:
15-
runs-on: ubuntu-latest
16-
strategy:
17-
matrix:
18-
rust:
19-
- stable
20-
- nightly
21-
- 1.52.1 # MSVR
22-
steps:
23-
- uses: actions/checkout@v3
24-
# Important preparation step: override the latest default Rust version in GitHub CI
25-
# with the current value of the iteration in the "strategy.matrix.rust"-array.
26-
- uses: actions-rs/toolchain@v1
27-
with:
28-
profile: default
29-
toolchain: ${{ matrix.rust }}
30-
override: true
31-
# helps to identify if the right cargo version is actually used
32-
- run: cargo version
33-
- name: Build
34-
run: cargo build --all-targets --verbose
35-
- name: Run tests
36-
run: cargo test --verbose
18+
build_multiboot2_msrv:
19+
name: "build (msrv)"
20+
uses: ./.github/workflows/_build-rust.yml
21+
with:
22+
rust-version: 1.56.1
23+
do-style-check: false
24+
25+
build_multiboot2_stable:
26+
name: "build (stable)"
27+
uses: ./.github/workflows/_build-rust.yml
28+
with:
29+
rust-version: stable
30+
do-style-check: false
31+
32+
build_multiboot2_nightly:
33+
name: "build (nightly)"
34+
uses: ./.github/workflows/_build-rust.yml
35+
with:
36+
rust-version: nightly
37+
do-style-check: false
38+
39+
build_nostd_multiboot2_msrv:
40+
name: "build no_std (msrv)"
41+
uses: ./.github/workflows/_build-rust.yml
42+
with:
43+
rust-version: 1.56.1
44+
do-style-check: false
45+
rust-target: thumbv7em-none-eabihf
46+
47+
build_nostd_multiboot2_stable:
48+
name: "build no_std (stable)"
49+
uses: ./.github/workflows/_build-rust.yml
50+
with:
51+
rust-version: stable
52+
do-style-check: false
53+
rust-target: thumbv7em-none-eabihf
3754

38-
# no-std build without tests
39-
build_no_std:
40-
runs-on: ubuntu-latest
41-
strategy:
42-
matrix:
43-
rust:
44-
- stable
45-
- nightly
46-
- 1.52.1 # MSVR
47-
steps:
48-
- uses: actions/checkout@v3
49-
# Important preparation step: override the latest default Rust version in GitHub CI
50-
# with the current value of the iteration in the "strategy.matrix.rust"-array.
51-
- uses: actions-rs/toolchain@v1
52-
with:
53-
profile: default
54-
toolchain: ${{ matrix.rust }}
55-
override: true
56-
# helps to identify if the right cargo version is actually used
57-
- run: cargo version
58-
- name: "Rustup: install some no_std target"
59-
run: rustup target add thumbv7em-none-eabihf
60-
- name: Build (no_std)
61-
run: cargo build --target thumbv7em-none-eabihf
55+
build_nostd_multiboot2_nightly:
56+
name: "build no_std (nightly)"
57+
uses: ./.github/workflows/_build-rust.yml
58+
with:
59+
rust-version: nightly
60+
do-style-check: false
61+
rust-target: thumbv7em-none-eabihf
6262

63-
# Tests that the unstable feature, which requires nightly, builds.
64-
build_unstable:
65-
runs-on: ubuntu-latest
66-
strategy:
67-
matrix:
68-
rust:
69-
- nightly
70-
steps:
71-
- uses: actions/checkout@v3
72-
# Important preparation step: override the latest default Rust version in GitHub CI
73-
# with the current value of the iteration in the "strategy.matrix.rust"-array.
74-
- uses: actions-rs/toolchain@v1
75-
with:
76-
profile: default
77-
toolchain: ${{ matrix.rust }}
78-
override: true
79-
- name: Build (unstable)
80-
run: cargo build --all-targets --features unstable
81-
- name: Test (unstable)
82-
run: cargo test --all-targets --features unstable
63+
style_multiboot2_msrv:
64+
name: "style (msrv)"
65+
uses: ./.github/workflows/_build-rust.yml
66+
with:
67+
rust-version: 1.56.1
68+
do-style-check: true
69+
do-test: false
8370

84-
# As discussed, these tasks are optional for PRs.
85-
style_checks:
86-
runs-on: ubuntu-latest
87-
strategy:
88-
matrix:
89-
rust:
90-
- 1.52.1 # MSVR
91-
steps:
92-
- uses: actions/checkout@v3
93-
# Important preparation step: override the latest default Rust version in GitHub CI
94-
# with the current value of the iteration in the "strategy.matrix.rust"-array.
95-
- uses: actions-rs/toolchain@v1
96-
with:
97-
profile: default
98-
toolchain: ${{ matrix.rust }}
99-
override: true
100-
# helps to identify if the right cargo version is actually used
101-
- run: cargo version
102-
- name: Rustfmt
103-
run: cargo fmt -- --check
104-
- name: Clippy
105-
run: cargo clippy --all-targets
106-
- name: Rustdoc
107-
run: cargo doc --document-private-items
71+
style_multiboot2_stable:
72+
name: "style (stable)"
73+
uses: ./.github/workflows/_build-rust.yml
74+
with:
75+
rust-version: stable
76+
do-style-check: true
77+
do-test: false

multiboot2-header/src/builder/traits.rs

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ mod tests {
6060
c: u128,
6161
}
6262
impl StructAsBytes for Foobar {}
63+
#[allow(clippy::blacklisted_name)]
6364
let foo = Foobar {
6465
a: 11,
6566
b: 22,

multiboot2-header/src/information_request.rs

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ mod tests {
136136
use crate::InformationRequestHeaderTag;
137137

138138
#[test]
139+
#[allow(clippy::erasing_op)]
140+
#[allow(clippy::identity_op)]
139141
fn test_assert_size() {
140142
assert_eq!(
141143
core::mem::size_of::<InformationRequestHeaderTag<0>>(),

multiboot2-header/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
3636
#![no_std]
3737
#![deny(rustdoc::all)]
38-
#![allow(rustdoc::missing_doc_code_examples)]
3938
#![deny(clippy::all)]
4039
#![deny(clippy::missing_const_for_fn)]
4140
#![deny(missing_debug_implementations)]

multiboot2/src/lib.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#![deny(clippy::all)]
88
#![deny(rustdoc::all)]
99
#![allow(rustdoc::private_doc_tests)]
10-
#![allow(rustdoc::missing_doc_code_examples)]
1110
// --- END STYLE CHECKS ---
1211

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

552551
#[test]
553-
/// Compile time test for `BootLoaderNameTag`.
552+
/// Compile time test for [`BootLoaderNameTag`].
554553
fn name_tag_size() {
555-
use BootLoaderNameTag;
556554
unsafe {
557555
core::mem::transmute::<[u8; 9], BootLoaderNameTag>([0u8; 9]);
558556
}
@@ -850,9 +848,8 @@ mod tests {
850848
}
851849

852850
#[test]
853-
/// Compile time test for `VBEInfoTag`.
851+
/// Compile time test for [`VBEInfoTag`].
854852
fn vbe_info_tag_size() {
855-
use VBEInfoTag;
856853
unsafe {
857854
// 16 for the start + 512 from `VBEControlInfo` + 256 from `VBEModeInfo`.
858855
core::mem::transmute::<[u8; 784], VBEInfoTag>([0u8; 784]);
@@ -1330,7 +1327,7 @@ mod tests {
13301327
let bi = bi.unwrap();
13311328
assert_eq!(addr, bi.start_address());
13321329
assert_eq!(addr + bytes.0.len(), bi.end_address());
1333-
assert_eq!(bytes.0.len(), bi.total_size() as usize);
1330+
assert_eq!(bytes.0.len(), bi.total_size());
13341331
let es = bi.elf_sections_tag().unwrap();
13351332
let mut s = es.sections();
13361333
let s1 = s.next().unwrap();
@@ -1384,7 +1381,7 @@ mod tests {
13841381
let bi = bi.unwrap();
13851382
assert_eq!(addr, bi.start_address());
13861383
assert_eq!(addr + bytes.0.len(), bi.end_address());
1387-
assert_eq!(bytes.0.len(), bi.total_size() as usize);
1384+
assert_eq!(bytes.0.len(), bi.total_size());
13881385
let efi_memory_map = bi.efi_memory_map_tag().unwrap();
13891386
let mut efi_mmap_iter = efi_memory_map.memory_areas();
13901387
let desc = efi_mmap_iter.next().unwrap();

0 commit comments

Comments
 (0)