diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3043d22..b7a79d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,15 +6,42 @@ on: pull_request: env: - CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 - CARGO_INCREMENTAL: 0 concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: + tests: + name: Unit Tests + timeout-minutes: 20 + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Install Rust stable + uses: dtolnay/rust-toolchain@stable + - name: Install cargo-nextest + uses: taiki-e/install-action@nextest + - name: Dependency + run: cargo fetch + - 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: Tests + run: cargo nextest run --all-features --workspace + coverage: name: Code Coverage runs-on: ubuntu-latest @@ -23,8 +50,10 @@ 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 @@ -32,19 +61,20 @@ jobs: - 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: 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 +90,27 @@ 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: 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" @@ -95,10 +127,10 @@ jobs: 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/ 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::*; diff --git a/jpegxl-src/Cargo.toml b/jpegxl-src/Cargo.toml index 6359d39..a41bd87 100644 --- a/jpegxl-src/Cargo.toml +++ b/jpegxl-src/Cargo.toml @@ -33,6 +33,9 @@ exclude = [ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lints.clippy] +pedantic = "warn" + [dependencies] cmake = "0.1.50" diff --git a/jpegxl-src/src/lib.rs b/jpegxl-src/src/lib.rs index 57d0141..2bd7fe9 100644 --- a/jpegxl-src/src/lib.rs +++ b/jpegxl-src/src/lib.rs @@ -17,11 +17,12 @@ pub fn build() { let source = source_dir(); if let Ok(p) = std::thread::available_parallelism() { - env::set_var("CMAKE_BUILD_PARALLEL_LEVEL", format!("{}", p)) + env::set_var("CMAKE_BUILD_PARALLEL_LEVEL", format!("{p}")); } let mut config = cmake::Config::new(source); config + .define("CMAKE_INSTALL_LIBDIR", "lib") .define("BUILD_SHARED_LIBS", "OFF") .define("BUILD_TESTING", "OFF") .define("JPEGXL_ENABLE_TOOLS", "OFF") @@ -34,6 +35,12 @@ pub fn build() { .define("JPEGXL_ENABLE_OPENEXR", "OFF") .define("JPEGXL_ENABLE_JPEGLI", "OFF"); + #[cfg(target_os = "windows")] + config + .generator("Visual Studio 17 2022") + .generator_toolset("ClangCL") + .define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreadedDLL"); + let mut prefix = config.build(); prefix.push("lib"); println!("cargo:rustc-link-search=native={}", prefix.display());