Skip to content

Commit 77893f9

Browse files
authored
Merge pull request #326 from surban/main
Replace xz2 dependency by liblzma enabling WebAssembly WASI targets
2 parents bc4eccd + 04b854e commit 77893f9

File tree

7 files changed

+49
-15
lines changed

7 files changed

+49
-15
lines changed

.github/workflows/wasi.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: wasi
2+
3+
env:
4+
RUST_BACKTRACE: 1
5+
6+
jobs:
7+
build:
8+
name: Build for wasm32-wasip1-threads
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions-rust-lang/setup-rust-toolchain@v1
13+
with:
14+
toolchain: nightly
15+
target: wasm32-wasip1-threads
16+
- run: |
17+
curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sysroot-25.0.tar.gz -o wasi-sysroot.tar.gz
18+
mkdir -p wasi-sysroot
19+
tar xf wasi-sysroot.tar.gz --strip-components=1 -C wasi-sysroot
20+
- run: |
21+
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"
22+
cargo +nightly build --lib --features all --target wasm32-wasip1-threads
23+
24+
on:
25+
merge_group:
26+
types: [checks_requested]
27+
pull_request:
28+
branches: [main]
29+
types: [opened, synchronize, reopened, ready_for_review]
30+
push:
31+
branches:
32+
- main

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "async-compression"
33
version = "0.4.19"
44
authors = ["Wim Looman <[email protected]>", "Allen Bui <[email protected]>"]
55
edition = "2018"
6+
resolver = "2"
67
license = "MIT OR Apache-2.0"
78
keywords = ["compression", "gzip", "zstd", "brotli", "async"]
89
categories = ["compression", "asynchronous"]
@@ -24,8 +25,9 @@ all-algorithms = ["brotli", "bzip2", "deflate", "gzip", "lzma", "xz", "zlib", "z
2425
# algorithms
2526
deflate = ["flate2"]
2627
gzip = ["flate2"]
27-
lzma = ["xz2"]
28-
xz = ["xz2"]
28+
lzma = ["dep:liblzma"]
29+
xz = ["lzma"]
30+
xz2 = ["xz"]
2931
zlib = ["flate2"]
3032
zstd = ["libzstd", "zstd-safe"]
3133
zstdmt = ["zstd", "zstd-safe/zstdmt"]
@@ -41,7 +43,7 @@ libzstd = { package = "zstd", version = "0.13.1", optional = true, default-featu
4143
memchr = "2"
4244
pin-project-lite = "0.2"
4345
tokio = { version = "1.24.2", optional = true, default-features = false }
44-
xz2 = { version = "0.1.6", optional = true }
46+
liblzma = { version = "0.3.6", optional = true }
4547
zstd-safe = { version = "7", optional = true, default-features = false }
4648
deflate64 = { version = "0.1.5", optional = true }
4749

src/codec/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod gzip;
1717
mod lzma;
1818
#[cfg(feature = "xz")]
1919
mod xz;
20-
#[cfg(feature = "xz2")]
20+
#[cfg(feature = "lzma")]
2121
mod xz2;
2222
#[cfg(feature = "zlib")]
2323
mod zlib;
@@ -40,7 +40,7 @@ pub(crate) use self::gzip::{GzipDecoder, GzipEncoder};
4040
pub(crate) use self::lzma::{LzmaDecoder, LzmaEncoder};
4141
#[cfg(feature = "xz")]
4242
pub(crate) use self::xz::{XzDecoder, XzEncoder};
43-
#[cfg(feature = "xz2")]
43+
#[cfg(feature = "lzma")]
4444
pub(crate) use self::xz2::{Xz2Decoder, Xz2Encoder, Xz2FileFormat};
4545
#[cfg(feature = "zlib")]
4646
pub(crate) use self::zlib::{ZlibDecoder, ZlibEncoder};

src/codec/xz2/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{fmt, io};
22

3-
use xz2::stream::{Action, Status, Stream};
3+
use liblzma::stream::{Action, Status, Stream};
44

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

src/codec/xz2/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{fmt, io};
22

3-
use xz2::stream::{Action, Check, LzmaOptions, Status, Stream};
3+
use liblzma::stream::{Action, Check, LzmaOptions, Status, Stream};
44

55
use crate::{
66
codec::{Encode, Xz2FileFormat},

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
)]
140140
#![cfg_attr(not(all), allow(unused))]
141141

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

145145
#[macro_use]
@@ -242,7 +242,7 @@ impl Level {
242242
}
243243
}
244244

245-
#[cfg(feature = "xz2")]
245+
#[cfg(feature = "lzma")]
246246
fn into_xz2(self) -> u32 {
247247
match self {
248248
Self::Fastest => 0,

tests/utils/algos.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ algos! {
169169
pub use crate::utils::impls::sync::to_vec;
170170

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

174174
to_vec(XzEncoder::new(bytes, 0))
175175
}
176176

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

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

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

193193
to_vec(XzEncoder::new_stream(
194194
bytes,
@@ -197,8 +197,8 @@ algos! {
197197
}
198198

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

203203
to_vec(XzDecoder::new_stream(
204204
bytes,

0 commit comments

Comments
 (0)