Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "libpressio-sys/libpressio"]
path = libpressio-sys/libpressio
url = https://github.com/robertu94/libpressio.git
[submodule "libpressio-sys/std_compat"]
path = libpressio-sys/std_compat
url = https://github.com/robertu94/std_compat
43 changes: 33 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
[workspace]
resolver = "2"
members = ["libpressio-sys"]

[workspace.package]
edition = "2024"
authors = ["Robert Underwood <[email protected]>"]
repository = "https://github.com/robertu94/libpressio-rs"
rust-version = "1.85"

[workspace.dependencies]
# workspace-internal crates
libpressio = { version = "0.1", path = ".", default-features = false }
libpressio-sys = { version = "0.1", path = "libpressio-sys", default-features = false }

# crates.io third-party dependencies
bindgen = { version = "0.71", default-features = false }
cc = { version = "1.2", default-features = false }
cmake = { version = "0.1.26", default-features = false }
libc = { version = "0.2", default-features = false }
ndarray = { version = "0.16.1", default-features = false }

[package]
name = "libpressio-rs"
name = "libpressio"
version = "0.1.0"
authors = ["Robert Underwood <[email protected]>"]
edition = "2018"
edition = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
description = "High-level Rust bindings to the libpressio compression framework"
categories = ["api-bindings", "compression", "encoding"]
keywords = ["libpressio", "compression", "encoding"]

[dependencies]
ndarray = "0.14.0"
libc = "0.2.86"

[build-dependencies]
bindgen = "0.53.1"
pkg-config = "0.3.19"
ndarray = { workspace = true }
libc = { workspace = true }
libpressio-sys = { workspace = true }
29 changes: 0 additions & 29 deletions build.rs

This file was deleted.

17 changes: 17 additions & 0 deletions libpressio-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "libpressio-sys"
version = "0.1.0"
edition = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }

description = "Low-level Rust bindings to the libpressio compression framework"
readme = "README.md"
categories = ["api-bindings", "compression", "encoding"]
keywords = ["libpressio", "bindgen", "compression", "encoding"]

[build-dependencies]
bindgen = { workspace = true, features = ["runtime"] }
cc = { workspace = true }
cmake = { workspace = true }
71 changes: 71 additions & 0 deletions libpressio-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use std::{
env,
path::{Path, PathBuf},
};

fn main() {
println!("cargo::rerun-if-changed=build.rs");
println!("cargo::rerun-if-changed=wrapper.h");
println!("cargo::rerun-if-changed=libpressio");
println!("cargo::rerun-if-changed=std_compat");

// ---------------------------------------------------------
// Configure std_compat, the compiler portability layer
// ---------------------------------------------------------
let mut stdcompat_config = cmake::Config::new("std_compat");
//prefer static libraries for RUST
stdcompat_config.define("BUILD_SHARED_LIBS", "OFF");
//disable testing to avoid google-test dependency
stdcompat_config.define("BUILD_TESTING", "OFF");
// require a C++17 compiler (e.g. gcc 12 or later) for now
// this includes Ubuntu 24.04 and later, Fedora, Nyx, et al
// https://robertu94.github.io/guides/dependencies
stdcompat_config.define("STDCOMPAT_CXX_VERSION", "17");
stdcompat_config.define("STDCOMPAT_CXX_UNSTABLE", "ON");
stdcompat_config.define("STD_COMPAT_BOOST_REQUIRED", "OFF");
let stdcompat_out = stdcompat_config.build();
println!("cargo:rustc-link-search=native={}", stdcompat_out.display());

// ---------------------------------------------------------
// Configure libpressio
// ---------------------------------------------------------
let mut config = cmake::Config::new("libpressio");
config.define("BUILD_SHARED_LIBS", "OFF");
config.define("BUILD_TESTING", "OFF");
config.define("LIBPRESSIO_HAS_OPENMP", "ON");
config.define("CMAKE_PREFIX_PATH", stdcompat_out);
let libpressio_out = config.build();

println!("cargo:rustc-link-search=native={}", libpressio_out.join("lib64").display());
println!("cargo:rustc-link-lib=static=libpressio");
eprintln!("include dir {}", libpressio_out.join("include").display());

let cargo_callbacks = bindgen::CargoCallbacks::new();
let bindings = bindgen::Builder::default()
.clang_arg("-x")
.clang_arg("c++")
.clang_arg("-std=c++11")
.clang_arg(format!(
"-I{}",
libpressio_out.join("include").join("libpressio").display()
))
.header("wrapper.h")
.parse_callbacks(Box::new(cargo_callbacks))
.allowlist_function("pressio_.*")
.allowlist_var("pressio_.*")
.allowlist_type("pressio_.*")
// MSRV 1.85
.rust_target(match bindgen::RustTarget::stable(85, 0) {
Ok(target) => target,
#[expect(clippy::panic)]
Err(err) => panic!("{err}"),
})
.generate()
.expect("Unable to generate bindings");

let out_path =
PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR should be set in a build script"));
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
1 change: 1 addition & 0 deletions libpressio-sys/libpressio
Submodule libpressio added at 11a1ed
1 change: 1 addition & 0 deletions libpressio-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
1 change: 1 addition & 0 deletions libpressio-sys/std_compat
Submodule std_compat added at 76b61a
1 change: 1 addition & 0 deletions libpressio-sys/wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "libpressio/include/libpressio.h"
Loading