Skip to content

Commit

Permalink
Use anaconda dist of c-blosc2
Browse files Browse the repository at this point in the history
  • Loading branch information
milesgranger committed Mar 16, 2024
1 parent a1cb273 commit e510983
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 55 deletions.
49 changes: 12 additions & 37 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,24 @@ on:
- prereleased

jobs:
macos:
runs-on: macos-latest
build-and-test:
runs-on: ${{ matrix.os }}
matrix:
os:
- macos-latest
- windows-latest
- ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo build
- name: Test
run: cargo test -- --test-threads 1

windows:
runs-on: windows-latest
# TODO: https://github.com/rust-lang/rust-bindgen/issues/2179
continue-on-error: true
steps:
- uses: actions/checkout@v3
- uses: mamba-org/setup-micromamba@v1
with:
submodules: recursive
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: "x86_64-pc-windows-gnu"
- name: Set up MinGW
uses: egor-tensin/setup-mingw@v2
with:
platform: x64
- name: Build
run: cargo build --target x86_64-pc-windows-gnu
- name: Test
run: cargo test --target x86_64-pc-windows-gnu

linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
environment-file: environment.yml
enviornment-name: blosc2
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo build
run: cargo build --features use-system-blosc2
- name: Test
run: cargo test
run: cargo test --features use-system-blosc2
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "blosc2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
defaults = []
system-lib = []
use-system-blosc2 = ["blosc2-sys/use-system-blosc2"]

[dependencies]
blosc2-sys = { path = "blosc2-sys" }
Expand Down
9 changes: 8 additions & 1 deletion blosc2-sys/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions blosc2-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ links = "blosc2"

[dependencies]

[features]
defaults = []
use-system-blosc2 = []

[build-dependencies]
cmake = "^0.1"
bindgen = "^0.64"
pkg-config = "^0.3"
55 changes: 39 additions & 16 deletions blosc2-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
use std::path::PathBuf;

const BLOSC2_VERSION: &'static str = "2.13.2";

fn main() {
let lib = cmake::Config::new("c-blosc2")
.define("CMAKE_POSITION_INDEPENDENT_CODE", "ON")
.define("CMAKE_C_FLAGS", "-Ofast")
.define("STATIC_LIB", "ON")
.define("SHARED_LIB", "ON")
.define("BLOSC_INSTALL", "ON")
.define("BUILD_TESTS", "OFF")
.define("BUILD_EXAMPLES", "OFF")
.define("BUILD_BENCHMARKS", "OFF")
.define("BUILD_FUZZERS", "OFF")
.always_configure(true)
.build();
let header = {
// build blosc2 from source
#[cfg(not(feature = "use-system-blosc2"))]
{
let lib = cmake::Config::new("c-blosc2")
.define("CMAKE_POSITION_INDEPENDENT_CODE", "ON")
.define("CMAKE_C_FLAGS", "-Ofast")
.define("STATIC_LIB", "ON")
.define("SHARED_LIB", "ON")
.define("BLOSC_INSTALL", "ON")
.define("BUILD_TESTS", "OFF")
.define("BUILD_EXAMPLES", "OFF")
.define("BUILD_BENCHMARKS", "OFF")
.define("BUILD_FUZZERS", "OFF")
.always_configure(true)
.build();

println!("cargo:rustc-link-search={}/lib64", lib.display());
println!("cargo:rustc-link-search={}/lib", lib.display());
println!("cargo:rustc-link-lib=static=blosc2");
format!("{}/include/blosc2.h", lib.display())
}

println!("cargo:rustc-link-search={}/lib64", lib.display());
println!("cargo:rustc-link-search={}/lib", lib.display());
println!("cargo:rustc-link-lib=static=blosc2");
// Use system blosc2
#[cfg(feature = "use-system-blosc2")]
{
let lib = pkg_config::Config::new()
.exactly_version(BLOSC2_VERSION)
.probe("blosc2")
.unwrap();
for linkpath in lib.link_paths {
println!("cargo:rustc-link-search={}", linkpath.display());
}
println!("cargo:rustc-link-lib=blosc2");
format!("{}/blosc2.h", lib.include_paths[0].display())
}
};

let out = PathBuf::from(&(format!("{}/bindings.rs", std::env::var("OUT_DIR").unwrap())));
bindgen::Builder::default()
.header(&format!("{}/include/blosc2.h", lib.display()))
.header(header)
.layout_tests(false)
.no_default("tagMONITORINFOEXA") // Windows specific, no default [u8;40usize]
.opaque_type("_IMAGE_TLS_DIRECTORY64") // Windows specific, error[E0588]: packed type cannot transitively contain a #[repr(align)] type
Expand Down
6 changes: 6 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: blosc2
channels:
- conda-forge
dependencies:
- pkg-config
- c-blosc2 ==2.13.2

0 comments on commit e510983

Please sign in to comment.