Skip to content

Commit

Permalink
Merge pull request #1771 from johannesvollmer/add-big-endian-ci
Browse files Browse the repository at this point in the history
Add big-endian CI
  • Loading branch information
fintelia committed Aug 27, 2022
2 parents c24aecb + 818d530 commit a1ce569
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 17 deletions.
78 changes: 76 additions & 2 deletions .github/workflows/rust.yml
@@ -1,22 +1,29 @@
name: Rust CI

on:
push:
branches: [ master, next ]
pull_request:
branches: [ master, next ]

jobs:
build:
name: Run tests and doctests on ubuntu
runs-on: ubuntu-latest
strategy:
matrix:
rust: ["1.51.0", stable, beta, nightly]
features: [ gif, jpeg, png, pnm, tga, dds, tiff, webp, hdr, farbfeld, '' ]
rust: ["1.56.1", stable, beta, nightly]
features: [gif, jpeg, png, tiff, ico, pnm, tga, webp, bmp, hdr, dxt, dds, farbfeld, openexr, jpeg_rayon, '']
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
- name: Cache Cargo Dependencies
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: build
run: cargo build -v --no-default-features --features "$FEATURES"
env:
Expand All @@ -28,6 +35,50 @@ jobs:
cargo doc -v --no-default-features --features "$FEATURES"
env:
FEATURES: ${{ matrix.features }}

build_big_endian:
name: Run tests on big endian architecture

# github actions does not support big endian systems directly, but it does support QEMU.
# so we install qemu, then build and run the tests in an emulated mips system.
# note: you can also use this approach to test for big endian locally.
runs-on: ubuntu-20.04
strategy:
matrix:
features: [gif, jpeg, png, tiff, ico, pnm, tga, webp, bmp, hdr, dxt, dds, farbfeld, openexr, jpeg_rayon, '']

# we are using the cross project for cross compilation to mips:
# https://github.com/cross-rs/cross
steps:
- uses: actions/checkout@v2

- name: Install or use cached cross-rs/cross
uses: baptiste0928/cargo-install@v1
with:
crate: cross

- name: Cache Cargo Dependencies
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true

- name: Start Docker (required for cross-rs)
run: sudo systemctl start docker

- name: Cross-Compile project to mips-unknown-linux-gnu
run: |
cross build --target=mips-unknown-linux-gnu --verbose -v --no-default-features --features "$FEATURES"
env:
FEATURES: ${{ matrix.features }}

# https://github.com/cross-rs/cross#supported-targets
- name: Cross-Run Tests in mips-unknown-linux-gnu using Qemu
continue-on-error: true
run: |
cross test --target mips-unknown-linux-gnu --verbose -v --no-default-features --features "$FEATURES"
env:
FEATURES: ${{ matrix.features }}

test_defaults:
runs-on: ubuntu-latest
steps:
Expand All @@ -40,6 +91,7 @@ jobs:
run: cargo build -v --release
- name: test
run: cargo test -v --release

test_avif:
runs-on: ubuntu-20.04
steps:
Expand All @@ -52,6 +104,7 @@ jobs:
override: true
- name: build
run: cargo build -v --no-default-features --features="avif"

test_avif_decoding:
runs-on: ubuntu-20.04
steps:
Expand All @@ -66,6 +119,7 @@ jobs:
run: cargo build -v --no-default-features --features="avif-decoder"
env:
SYSTEM_DEPS_DAV1D_BUILD_INTERNAL: always

clippy:
runs-on: ubuntu-20.04
steps:
Expand All @@ -82,6 +136,7 @@ jobs:
args: clippy --all-features -- -D warnings
env:
SYSTEM_DEPS_DAV1D_BUILD_INTERNAL: always

build_fuzz_afl:
name: "Fuzz targets (afl)"
runs-on: ubuntu-latest
Expand All @@ -103,6 +158,7 @@ jobs:
cargo afl check --bin fuzz_pnm
env:
RUSTFLAGS: "-Znew-llvm-pass-manager=no"

build_fuzz_cargo-fuzz:
name: "Fuzz targets (cargo-fuzz)"
runs-on: ubuntu-latest
Expand All @@ -121,6 +177,7 @@ jobs:
for format in $(cargo fuzz list); do
cargo fuzz run "$format" -- -runs=0;
done
public_private_dependencies:
name: "Public private dependencies"
runs-on: ubuntu-latest
Expand All @@ -136,6 +193,7 @@ jobs:
echo "#![deny(exported_private_dependencies)]" | cat - src/lib.rs > src/lib.rs.0
mv src/lib.rs.0 src/lib.rs
cargo check
build_benchmarks:
runs-on: ubuntu-latest
steps:
Expand All @@ -146,6 +204,7 @@ jobs:
override: true
- name: build
run: cargo build -v --benches --features=benchmarks

rustfmt:
runs-on: ubuntu-latest
steps:
Expand All @@ -160,8 +219,23 @@ jobs:
with:
command: fmt
args: -- --check

cargo-deny:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: EmbarkStudios/cargo-deny-action@v1

verify_msrv:
name: Verify Minimum Supported Rust Version in Cargo.toml
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install or use cached `cargo-msrv`
uses: baptiste0928/cargo-install@v1
with:
crate: cargo-msrv

- name: Verify Minimum Rust Version
run: cargo-msrv verify
10 changes: 4 additions & 6 deletions Cargo.toml
Expand Up @@ -2,9 +2,11 @@
name = "image"
version = "0.24.3"
edition = "2018"
rust-version = "1.56"
resolver = "2"

# note: when changed, also update test runner in `.github/workflows/rust.yml`
rust-version = "1.56.1"

license = "MIT"
description = "Imaging library written in Rust. Provides basic filters and decoders for the most common image formats."
authors = ["The image-rs Developers"]
Expand Down Expand Up @@ -43,11 +45,7 @@ mp4parse = { version = "0.12.0", optional = true }
dav1d = { version = "0.6.0", optional = true }
dcv-color-primitives = { version = "0.4.0", optional = true }
color_quant = "1.1"

# These appear as an empty dependency on other platforms.
# See: <https://github.com/rust-lang/cargo/issues/1197#issuecomment-901794879>
[target.'cfg(target_endian = "little")'.dependencies]
exr = { version = "1.4.2", optional = true }
exr = { version = "1.5.0", optional = true }

[dev-dependencies]
crc32fast = "1.2.0"
Expand Down
7 changes: 3 additions & 4 deletions src/codecs/openexr.rs
Expand Up @@ -455,10 +455,9 @@ mod test {

#[test]
fn compare_exr_hdr() {
assert!(
cfg!(feature = "hdr"),
"to run all the openexr tests, activate the hdr feature flag"
);
if cfg!(not(feature = "hdr")) {
eprintln!("warning: to run all the openexr tests, activate the hdr feature flag");
}

#[cfg(feature = "hdr")]
{
Expand Down
2 changes: 0 additions & 2 deletions src/image.rs
Expand Up @@ -291,7 +291,6 @@ pub enum ImageOutputFormat {
Tga,

#[cfg(feature = "exr")]
#[cfg(target_endian = "little")]
/// An Image in OpenEXR Format
OpenExr,

Expand Down Expand Up @@ -329,7 +328,6 @@ impl From<ImageFormat> for ImageOutputFormat {
#[cfg(feature = "tga")]
ImageFormat::Tga => ImageOutputFormat::Tga,
#[cfg(feature = "exr")]
#[cfg(target_endian = "little")]
ImageFormat::OpenExr => ImageOutputFormat::OpenExr,
#[cfg(feature = "tiff")]
ImageFormat::Tiff => ImageOutputFormat::Tiff,
Expand Down
2 changes: 0 additions & 2 deletions src/io/free_functions.rs
Expand Up @@ -73,7 +73,6 @@ pub(crate) fn load_decoder<R: BufRead + Seek, V: DecoderVisitor>(
#[cfg(feature = "hdr")]
image::ImageFormat::Hdr => visitor.visit_decoder(hdr::HdrAdapter::new(BufReader::new(r))?),
#[cfg(feature = "exr")]
#[cfg(target_endian = "little")]
image::ImageFormat::OpenExr => visitor.visit_decoder(openexr::OpenExrDecoder::new(r)?),
#[cfg(feature = "pnm")]
image::ImageFormat::Pnm => visitor.visit_decoder(pnm::PnmDecoder::new(r)?),
Expand Down Expand Up @@ -232,7 +231,6 @@ pub(crate) fn write_buffer_impl<W: std::io::Write + Seek>(
tga::TgaEncoder::new(buffered_write).write_image(buf, width, height, color)
}
#[cfg(feature = "exr")]
#[cfg(target_endian = "little")]
ImageOutputFormat::OpenExr => {
openexr::OpenExrEncoder::new(buffered_write).write_image(buf, width, height, color)
}
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Expand Up @@ -235,7 +235,6 @@ pub mod codecs {
#[cfg(feature = "jpeg")]
pub mod jpeg;
#[cfg(feature = "exr")]
#[cfg(target_endian = "little")]
pub mod openexr;
#[cfg(feature = "png")]
pub mod png;
Expand Down

0 comments on commit a1ce569

Please sign in to comment.