diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3043d22..ce023b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,64 @@ concurrency: cancel-in-progress: true jobs: + tests: + name: Unit Tests + timeout-minutes: 10 + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - uses: actions/cache@v4 + id: cache + with: + path: | + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }} + - name: Install Rust stable + uses: dtolnay/rust-toolchain@stable + - name: Install cargo-nextest + uses: taiki-e/install-action@nextest + - name: Dependency + run: cargo fetch + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + - name: Tests + run: cargo nextest run --all-features --workspace + + tests-windows: + name: Unit Tests (windows-latest) + timeout-minutes: 10 + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - uses: microsoft/setup-msbuild@v2 + - uses: actions/cache@v4 + id: cache + with: + path: | + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }} + - name: Install Rust stable + uses: dtolnay/rust-toolchain@stable + - name: Install cargo-nextest + uses: taiki-e/install-action@nextest + - name: Dependency + run: cargo fetch + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + - name: Tests + run: cargo nextest run --all-features --workspace + coverage: name: Code Coverage runs-on: ubuntu-latest @@ -23,28 +81,32 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install Rust - run: rustup update nightly + - name: Install Rust Nightly + uses: dtolnay/rust-toolchain@nightly + with: + components: llvm-tools - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov - name: Install cargo-nextest uses: taiki-e/install-action@nextest - - name: Dependency - run: cargo fetch - uses: actions/cache@v4 + id: cache with: path: | - ~/.cargo/bin/ ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ - key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }} + key: ${{ runner.os }}-cargo-cov-${{ hashFiles('**/Cargo.lock') }} + - name: Dependency + run: cargo fetch + if: ${{ steps.cache.outputs.cache-hit != 'true' }} - name: Generate code coverage - run: cargo +nightly llvm-cov nextest - --all-features --workspace --branch - --ignore-filename-regex jpegxl-sys/ - --lcov --output-path lcov.info + run: + cargo +nightly llvm-cov nextest + --all-features --workspace + --ignore-filename-regex jpegxl-sys/ + --lcov --output-path lcov.info - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: @@ -60,25 +122,28 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install Rust - run: rustup update nightly - - name: Add rust-src - run: rustup +nightly component add rust-src + - name: Install Rust Nightly + uses: dtolnay/rust-toolchain@nightly + with: + components: rust-src - name: Install cargo-nextest uses: taiki-e/install-action@nextest - - name: Dependency - run: cargo fetch - uses: actions/cache@v4 + id: cache with: path: | - ~/.cargo/bin/ ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-sanitizer-${{ hashFiles('**/Cargo.lock') }} + - name: Dependency + run: cargo fetch + if: ${{ steps.cache.outputs.cache-hit != 'true' }} - name: Address Sanitizer - run: cargo +nightly nextest run -Z build-std --target=x86_64-unknown-linux-gnu --all-features + run: + cargo +nightly nextest run + -Z build-std --target=x86_64-unknown-linux-gnu --all-features env: RUSTFLAGS: "-Z sanitizer=address" RUSTDOCFLAGS: "-Z sanitizer=address" @@ -93,17 +158,18 @@ jobs: submodules: recursive - name: Install Rust run: rustup update stable - - name: Dependency - run: cargo fetch - - uses: actions/cache@v4 + - uses: actions/cache@v3 + id: cache with: path: | - ~/.cargo/bin/ ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }} + - name: Dependency + run: cargo fetch + if: ${{ steps.cache.outputs.cache-hit != 'true' }} - name: Run Clippy with reviewdog uses: giraffate/clippy-action@v1.0.1 with: diff --git a/jpegxl-rs/src/encode.rs b/jpegxl-rs/src/encode.rs index 467e7e6..537529e 100644 --- a/jpegxl-rs/src/encode.rs +++ b/jpegxl-rs/src/encode.rs @@ -30,6 +30,8 @@ use crate::{ common::PixelType, errors::EncodeError, memory::MemoryManager, parallel::JxlParallelRunner, }; +// MARK: Utility types + /// Encoding speed #[derive(Debug, Clone, Copy)] pub enum EncoderSpeed { @@ -162,6 +164,8 @@ impl Deref for EncoderResult { } } +// MARK: Encoder + /// JPEG XL Encoder #[derive(Builder)] #[builder(build_fn(skip, error = "None"))] @@ -278,7 +282,7 @@ impl<'prl, 'mm> JxlEncoderBuilder<'prl, 'mm> { } } -// Private helper functions +// MARK: Private helper functions impl JxlEncoder<'_, '_> { /// Error mapping from underlying C const to [`EncodeError`] enum #[cfg_attr(coverage_nightly, coverage(off))] @@ -453,7 +457,7 @@ impl JxlEncoder<'_, '_> { } } -// Public interface +// MARK: Public interface impl<'prl, 'mm> JxlEncoder<'prl, 'mm> { /// Set a specific encoder frame setting /// @@ -584,6 +588,7 @@ pub fn encoder_builder<'prl, 'mm>() -> JxlEncoderBuilder<'prl, 'mm> { JxlEncoderBuilder::default() } +// MARK: Tests #[cfg(test)] mod tests { use super::*;