From edd4966cea4559a22bdfe764ca1995a24080cf19 Mon Sep 17 00:00:00 2001 From: Josh Holmer Date: Sun, 16 Sep 2018 14:43:08 -0400 Subject: [PATCH] Fix compilation error on i686 due to cfzlib incompat (#138) Closes #137 --- Cargo.toml | 4 ++-- src/deflate/mod.rs | 30 +++++++++++++++++++----------- src/lib.rs | 1 + 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f60446d3..cca6184d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,8 +47,8 @@ version = "^2.10.0" optional = true version = "1.0.1" -[dependencies.cloudflare-zlib-sys] -version = "^0.1.2" +[target.'cfg(any(target_arch = "x86_64", target_arch = "aarch64"))'.dependencies] +cloudflare-zlib-sys = "^0.1.2" [dependencies.image] default-features = false diff --git a/src/deflate/mod.rs b/src/deflate/mod.rs index 273cb66c..71c6bc65 100644 --- a/src/deflate/mod.rs +++ b/src/deflate/mod.rs @@ -15,6 +15,7 @@ pub fn inflate(data: &[u8]) -> PngResult> { } /// Compress a data stream using the DEFLATE algorithm +#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] pub fn deflate(data: &[u8], zc: u8, zs: u8, zw: u8, max_size: &AtomicMin) -> PngResult> { if is_cfzlib_supported() { return cfzlib_deflate(data, zc, zs, zw, max_size); @@ -23,22 +24,29 @@ pub fn deflate(data: &[u8], zc: u8, zs: u8, zw: u8, max_size: &AtomicMin) -> Png miniz_stream::compress_to_vec_oxipng(data, zc, zw.into(), zs.into(), max_size) } +/// Compress a data stream using the DEFLATE algorithm +#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))] +pub fn deflate(data: &[u8], zc: u8, zs: u8, zw: u8, max_size: &AtomicMin) -> PngResult> { + miniz_stream::compress_to_vec_oxipng(data, zc, zw.into(), zs.into(), max_size) +} + +#[cfg(target_arch = "x86_64")] fn is_cfzlib_supported() -> bool { - #[cfg(target_arch = "x86_64")] - { - if is_x86_feature_detected!("sse4.2") && is_x86_feature_detected!("pclmulqdq") { - return true; - } - } - #[cfg(target_arch = "aarch64")] - { - if is_arm_feature_detected!("neon") && is_arm_feature_detected!("crc") { - return true; - } + if is_x86_feature_detected!("sse4.2") && is_x86_feature_detected!("pclmulqdq") { + return true; } false } +#[cfg(target_arch = "aarch64")] +fn is_cfzlib_supported() -> bool { + if is_arm_feature_detected!("neon") && is_arm_feature_detected!("crc") { + return true; + } + false +} + +#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] pub fn cfzlib_deflate( data: &[u8], level: u8, diff --git a/src/lib.rs b/src/lib.rs index 6882f00a..ce9a1764 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ extern crate bit_vec; extern crate byteorder; +#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] extern crate cloudflare_zlib_sys; extern crate crc; extern crate image;