diff --git a/.github/workflows/_build-rust.yml b/.github/workflows/_build-rust.yml new file mode 100644 index 00000000..a294cc34 --- /dev/null +++ b/.github/workflows/_build-rust.yml @@ -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 diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1c5bdba4..f34ef430 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 diff --git a/multiboot2-header/src/builder/traits.rs b/multiboot2-header/src/builder/traits.rs index 015f84b0..02091101 100644 --- a/multiboot2-header/src/builder/traits.rs +++ b/multiboot2-header/src/builder/traits.rs @@ -60,6 +60,7 @@ mod tests { c: u128, } impl StructAsBytes for Foobar {} + #[allow(clippy::blacklisted_name)] let foo = Foobar { a: 11, b: 22, diff --git a/multiboot2-header/src/information_request.rs b/multiboot2-header/src/information_request.rs index 1837ec93..81550adf 100644 --- a/multiboot2-header/src/information_request.rs +++ b/multiboot2-header/src/information_request.rs @@ -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::>(), diff --git a/multiboot2-header/src/lib.rs b/multiboot2-header/src/lib.rs index ed30f1fb..59ab39d1 100644 --- a/multiboot2-header/src/lib.rs +++ b/multiboot2-header/src/lib.rs @@ -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)] diff --git a/multiboot2/src/lib.rs b/multiboot2/src/lib.rs index 923cff2b..36e98ff2 100644 --- a/multiboot2/src/lib.rs +++ b/multiboot2/src/lib.rs @@ -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 @@ -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]); } @@ -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]); @@ -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(); @@ -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();