Skip to content

Replace xz2 dependency by liblzma enabling WebAssembly WASI targets #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/wasi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: wasi

env:
RUST_BACKTRACE: 1

jobs:
build:
name: Build for wasm32-wasip1-threads
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
target: wasm32-wasip1-threads
- run: |
curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sysroot-25.0.tar.gz -o wasi-sysroot.tar.gz
mkdir -p wasi-sysroot
tar xf wasi-sysroot.tar.gz --strip-components=1 -C wasi-sysroot
- run: |
export "CFLAGS_wasm32_wasip1_threads=--sysroot=${{ github.workspace }}/wasi-sysroot -I${{ github.workspace }}/wasi-sysroot/include/wasm32-wasip1-threads -L-I${{ github.workspace }}/wasi-sysroot/lib/wasm32-wasip1-threads"
cargo +nightly build --lib --features all --target wasm32-wasip1-threads

on:
merge_group:
types: [checks_requested]
pull_request:
branches: [main]
types: [opened, synchronize, reopened, ready_for_review]
push:
branches:
- main
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "async-compression"
version = "0.4.19"
authors = ["Wim Looman <wim@nemo157.com>", "Allen Bui <fairingrey@gmail.com>"]
edition = "2018"
resolver = "2"
license = "MIT OR Apache-2.0"
keywords = ["compression", "gzip", "zstd", "brotli", "async"]
categories = ["compression", "asynchronous"]
Expand All @@ -24,8 +25,9 @@ all-algorithms = ["brotli", "bzip2", "deflate", "gzip", "lzma", "xz", "zlib", "z
# algorithms
deflate = ["flate2"]
gzip = ["flate2"]
lzma = ["xz2"]
xz = ["xz2"]
lzma = ["dep:liblzma"]
xz = ["lzma"]
xz2 = ["xz"]
zlib = ["flate2"]
zstd = ["libzstd", "zstd-safe"]
zstdmt = ["zstd", "zstd-safe/zstdmt"]
Expand All @@ -41,7 +43,7 @@ libzstd = { package = "zstd", version = "0.13.1", optional = true, default-featu
memchr = "2"
pin-project-lite = "0.2"
tokio = { version = "1.24.2", optional = true, default-features = false }
xz2 = { version = "0.1.6", optional = true }
liblzma = { version = "0.3.6", optional = true }
zstd-safe = { version = "7", optional = true, default-features = false }
deflate64 = { version = "0.1.5", optional = true }

Expand Down
4 changes: 2 additions & 2 deletions src/codec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod gzip;
mod lzma;
#[cfg(feature = "xz")]
mod xz;
#[cfg(feature = "xz2")]
#[cfg(feature = "lzma")]
mod xz2;
#[cfg(feature = "zlib")]
mod zlib;
Expand All @@ -40,7 +40,7 @@ pub(crate) use self::gzip::{GzipDecoder, GzipEncoder};
pub(crate) use self::lzma::{LzmaDecoder, LzmaEncoder};
#[cfg(feature = "xz")]
pub(crate) use self::xz::{XzDecoder, XzEncoder};
#[cfg(feature = "xz2")]
#[cfg(feature = "lzma")]
pub(crate) use self::xz2::{Xz2Decoder, Xz2Encoder, Xz2FileFormat};
#[cfg(feature = "zlib")]
pub(crate) use self::zlib::{ZlibDecoder, ZlibEncoder};
Expand Down
2 changes: 1 addition & 1 deletion src/codec/xz2/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fmt, io};

use xz2::stream::{Action, Status, Stream};
use liblzma::stream::{Action, Status, Stream};

use crate::{codec::Decode, util::PartialBuffer};

Expand Down
2 changes: 1 addition & 1 deletion src/codec/xz2/encoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fmt, io};

use xz2::stream::{Action, Check, LzmaOptions, Status, Stream};
use liblzma::stream::{Action, Check, LzmaOptions, Status, Stream};

use crate::{
codec::{Encode, Xz2FileFormat},
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
)]
#![cfg_attr(not(all), allow(unused))]

#[cfg(any(feature = "bzip2", feature = "flate2", feature = "xz2"))]
#[cfg(any(feature = "bzip2", feature = "flate2", feature = "lzma"))]
use std::convert::TryInto;

#[macro_use]
Expand Down Expand Up @@ -242,7 +242,7 @@ impl Level {
}
}

#[cfg(feature = "xz2")]
#[cfg(feature = "lzma")]
fn into_xz2(self) -> u32 {
match self {
Self::Fastest => 0,
Expand Down
12 changes: 6 additions & 6 deletions tests/utils/algos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ algos! {
pub use crate::utils::impls::sync::to_vec;

pub fn compress(bytes: &[u8]) -> Vec<u8> {
use xz2::bufread::XzEncoder;
use liblzma::bufread::XzEncoder;

to_vec(XzEncoder::new(bytes, 0))
}

pub fn decompress(bytes: &[u8]) -> Vec<u8> {
use xz2::bufread::XzDecoder;
use liblzma::bufread::XzDecoder;

to_vec(XzDecoder::new(bytes))
}
Expand All @@ -187,8 +187,8 @@ algos! {
pub use crate::utils::impls::sync::to_vec;

pub fn compress(bytes: &[u8]) -> Vec<u8> {
use xz2::bufread::XzEncoder;
use xz2::stream::{LzmaOptions, Stream};
use liblzma::bufread::XzEncoder;
use liblzma::stream::{LzmaOptions, Stream};

to_vec(XzEncoder::new_stream(
bytes,
Expand All @@ -197,8 +197,8 @@ algos! {
}

pub fn decompress(bytes: &[u8]) -> Vec<u8> {
use xz2::bufread::XzDecoder;
use xz2::stream::Stream;
use liblzma::bufread::XzDecoder;
use liblzma::stream::Stream;

to_vec(XzDecoder::new_stream(
bytes,
Expand Down
Loading