Skip to content

Commit

Permalink
Refactoring, bug fixes and improved CI w/ cross compiling (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesgranger authored Sep 22, 2024
1 parent 4613daa commit 85165c6
Show file tree
Hide file tree
Showing 29 changed files with 2,723 additions and 382 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: CI

on:
pull_request:
push:
branches:
- main
release:
types:
- released
- prereleased

jobs:
test-cross:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-musl
- s390x-unknown-linux-gnu
- aarch64-unknown-linux-musl
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross --rev 6d097fb

- name: Build
run: cross build --target ${{ matrix.target }} --release -vv

- name: Test
run: cross test --target ${{ matrix.target }} --release -vv

test-wasm32-emscripten:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
build: [static, shared]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-unknown-emscripten

- name: Install build deps
run: sudo apt install nasm gcc-multilib

- name: Install Emscripten
uses: mymindstorm/setup-emsdk@v14

- name: Build
run: cargo build --target wasm32-unknown-emscripten --no-default-features --features ${{ matrix.build }}

test-native:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-13 # x86_64
- macos-14 # arm
- windows-latest
- ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install nasm
if: runner.os != 'macOS'
uses: ilammy/setup-nasm@v1

- name: Set MSVC developer prompt
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1.6.0

- name: Install build deps (OSX)
if: runner.os == 'macOS'
run: brew install automake autoconf coreutils libtool nasm

- name: Test (shared)
run: cargo test --no-default-features --features shared --lib --release -vv

- name: Test (static)
run: |
cargo clean # ensure we're starting fresh, no funny business
cargo test --no-default-features --features static --release -vv
74 changes: 0 additions & 74 deletions .github/workflows/ci.yml

This file was deleted.

36 changes: 25 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
[workspace]
members = [
"isal-sys",
"isal-rs"
]

[profile.release]
lto = "fat"
codegen-units = 1
opt-level = 3
debug = false
[package]
name = "isal-rs"
version = "0.1.0+62519d9"
edition = "2021"

[lib]
name = "isal"

[features]
default = ["static"]
static = ["isal-sys/static"]
shared = ["isal-sys/shared"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
isal-sys = { path = "isal-sys"}

[dev-dependencies]
criterion = "0.3"
md5 = "0.7.0"

[[bench]]
name = "igzip"
path = "benches/igzip.rs"
harness = false
17 changes: 15 additions & 2 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
[build]
pre-build = ["apt update && apt install -y llvm-dev libclang-dev clang"] # required by cbindgen
[target.x86_64-unknown-linux-musl]
pre-build = [
"apt update",
"apt install -y nasm"
]
[target.s390x-unknown-linux-gnu]
pre-build = [
"apt update",
"apt install -y nasm"
]
[target.aarch64-unknown-linux-musl]
pre-build = [
"apt update",
"apt install -y nasm"
]
50 changes: 29 additions & 21 deletions isal-rs/benches/igzip.rs → benches/igzip.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
use criterion::{criterion_group, criterion_main, Criterion};
use isal_rs::igzip::{self, read::Encoder};
use std::{fs, io};
use isal::igzip::{self, read::Encoder};
use std::io;
use std::io::Cursor;

fn get_data() -> std::result::Result<Vec<u8>, std::io::Error> {
fs::read(format!("{}/test-data/html_x_4", env!("CARGO_MANIFEST_DIR")))
fn get_data() -> Vec<u8> {
(0..10_000)
.map(|_| b"oh what a beautiful morning, oh what a beautiful day!!".to_vec())
.flat_map(|v| v)
.collect()
}

fn igzip_compress(c: &mut Criterion) {
let data = get_data().unwrap();
let data = get_data();
c.bench_function("igzip::compress", |b| {
b.iter(|| {
let _ = igzip::compress(&data, igzip::CompressionLevel::Three, true).unwrap();
let _ =
igzip::compress(Cursor::new(&data), igzip::CompressionLevel::Three, true).unwrap();
})
});
}

fn igzip_compress_into(c: &mut Criterion) {
let data = get_data().unwrap();
let compressed_len = igzip::compress(&data, igzip::CompressionLevel::Three, true)
let data = get_data();
let compressed_len = igzip::compress(Cursor::new(&data), igzip::CompressionLevel::Three, true)
.unwrap()
.len();
let mut compressed = vec![0; compressed_len];
Expand All @@ -31,19 +36,21 @@ fn igzip_compress_into(c: &mut Criterion) {
}

fn igzip_decompress(c: &mut Criterion) {
let data = get_data().unwrap();
let compressed = igzip::compress(&data, igzip::CompressionLevel::Three, true).unwrap();
let data = get_data();
let compressed =
igzip::compress(Cursor::new(&data), igzip::CompressionLevel::Three, true).unwrap();
c.bench_function("igzip::decompress", |b| {
b.iter(|| {
let _ = igzip::decompress(&compressed).unwrap();
let _ = igzip::decompress(Cursor::new(&compressed)).unwrap();
})
});
}

fn igzip_decompress_into(c: &mut Criterion) {
let data = get_data().unwrap();
let compressed = igzip::compress(&data, igzip::CompressionLevel::Three, true).unwrap();
let mut decompressed = vec![0; data.len()];
let data = get_data();
let compressed =
igzip::compress(Cursor::new(&data), igzip::CompressionLevel::Three, true).unwrap();
let mut decompressed = vec![0; data.len() + 10000];
c.bench_function("igzip::decompress_into", |b| {
b.iter(|| {
let _ = igzip::decompress_into(&compressed, &mut decompressed).unwrap();
Expand All @@ -52,18 +59,19 @@ fn igzip_decompress_into(c: &mut Criterion) {
}

fn igzip_roundtrip(c: &mut Criterion) {
let data = get_data().unwrap();
let data = get_data();
c.bench_function("igzip::roundtrip", |b| {
b.iter(|| {
let compressed = igzip::compress(&data, igzip::CompressionLevel::Three, true).unwrap();
let _ = igzip::decompress(&compressed).unwrap();
let compressed =
igzip::compress(Cursor::new(&data), igzip::CompressionLevel::Three, true).unwrap();
let _ = igzip::decompress(Cursor::new(&compressed)).unwrap();
})
});
}

fn igzip_roundtrip_into(c: &mut Criterion) {
let data = get_data().unwrap();
let compressed_len = igzip::compress(&data, igzip::CompressionLevel::Three, true)
let data = get_data();
let compressed_len = igzip::compress(Cursor::new(&data), igzip::CompressionLevel::Three, true)
.unwrap()
.len();

Expand All @@ -81,7 +89,7 @@ fn igzip_roundtrip_into(c: &mut Criterion) {
}

fn igzip_encoder(c: &mut Criterion) {
let data = get_data().unwrap();
let data = get_data();
c.bench_function("igzip::read::Encoder", |b| {
b.iter(|| {
let mut output = vec![];
Expand All @@ -93,7 +101,7 @@ fn igzip_encoder(c: &mut Criterion) {

criterion_group! {
name = benches;
config = Criterion::default().sample_size(1_000);
config = Criterion::default().sample_size(250);
targets =
igzip_compress,
igzip_compress_into,
Expand Down
6 changes: 3 additions & 3 deletions isal-rs/examples/compress.rs → examples/compress.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fs;
use std::{fs, io::Cursor};

use isal_rs::igzip;
use isal::igzip;

fn get_data() -> std::result::Result<Vec<u8>, std::io::Error> {
fs::read(format!(
Expand All @@ -12,6 +12,6 @@ fn get_data() -> std::result::Result<Vec<u8>, std::io::Error> {
fn main() {
let data = get_data().unwrap();
for _ in 0..1000 {
let _v = igzip::compress(&data, igzip::CompressionLevel::Three, true).unwrap();
let _v = igzip::compress(Cursor::new(&data), igzip::CompressionLevel::Three, true).unwrap();
}
}
17 changes: 0 additions & 17 deletions isal-rs/Cargo.toml

This file was deleted.

11 changes: 10 additions & 1 deletion isal-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ name = "isal-sys"
version = "0.1.0+62519d9"
edition = "2021"

[features]
default = ["static"]
static = []
shared = []

regenerate-bindings = ["dep:bindgen"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

[build-dependencies]
bindgen = "^0.60"
cc = "^1"
bindgen = { version = "^0.69", optional = true }
copy_dir = "0.1.3"


[package.metadata.cross.target.powerpc64le-unknown-linux-gnu]
pre-build = ["apt update && apt install -y llvm-dev libclang-dev clang"] # required by cbindgen
Loading

0 comments on commit 85165c6

Please sign in to comment.