Skip to content
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

Refactoring and improved CI w/ cross compiling #12

Merged
merged 32 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
70409f5
Compile in build.rs
milesgranger Sep 19, 2024
343616e
Refactoring - build.rs works for shared, not static
milesgranger Sep 19, 2024
06e1ad5
Fix static build
milesgranger Sep 20, 2024
4c89d0d
Add TryFrom<isize> for CompressionLevel
milesgranger Sep 20, 2024
c8ad34a
Wrap InflateState
milesgranger Sep 20, 2024
30ccab5
Add ZStream
milesgranger Sep 20, 2024
f950c3a
Fix logic in end_of_stream in compress
milesgranger Sep 20, 2024
0946ed5
Refactoring - level in ZStream
milesgranger Sep 20, 2024
f93fafb
Test for larger data
milesgranger Sep 20, 2024
9461100
Fixed Decoder; needs cleanup
milesgranger Sep 20, 2024
695e0b9
block_state method
milesgranger Sep 20, 2024
9acde57
Use Decoder in decompress function
milesgranger Sep 20, 2024
7815e3d
Use Encoder for compress function
milesgranger Sep 20, 2024
c332620
Fix benches
milesgranger Sep 21, 2024
0577a6c
Maybe fix CI
milesgranger Sep 21, 2024
875238a
Fixup CI
milesgranger Sep 21, 2024
afbc9b3
refactor build.rs
milesgranger Sep 21, 2024
36706b9
osx gcc and windows isal libname
milesgranger Sep 21, 2024
5533bca
maybe gcc directly, debug windows
milesgranger Sep 21, 2024
ca6b484
more debugging
milesgranger Sep 21, 2024
b4a6d8d
update libname for windows
milesgranger Sep 21, 2024
e349512
hope fix windows link search, sanity check for macos
milesgranger Sep 21, 2024
c133b41
all working except cross and osx
milesgranger Sep 21, 2024
ccf3fe7
Fix OSX builds
milesgranger Sep 21, 2024
0023e6f
Add back other builds - all work except cross
milesgranger Sep 21, 2024
1de60c4
Try to fix musl build
milesgranger Sep 21, 2024
8aab4f7
fixup
milesgranger Sep 21, 2024
e22a53b
Add missing nasm for cross builds
milesgranger Sep 21, 2024
90694bc
Ensure correct C compiler is used based on target
milesgranger Sep 21, 2024
242a77e
Try updated build for cross
milesgranger Sep 21, 2024
6d65b68
Try to run tests now on cross
milesgranger Sep 22, 2024
76171f1
Small cleanup
milesgranger Sep 22, 2024
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
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
Loading