diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8246ad2..abeecd9 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 diff --git a/Cargo.toml b/Cargo.toml index ca30ef3..8920b3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/blosc2-sys/Cargo.lock b/blosc2-sys/Cargo.lock index 4cbffa5..696f97c 100644 --- a/blosc2-sys/Cargo.lock +++ b/blosc2-sys/Cargo.lock @@ -32,10 +32,11 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "blosc2-sys" -version = "0.1.0+2.8.0" +version = "0.2.0+2.13.2" dependencies = [ "bindgen", "cmake", + "pkg-config", ] [[package]] @@ -162,6 +163,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + [[package]] name = "proc-macro2" version = "1.0.55" diff --git a/blosc2-sys/Cargo.toml b/blosc2-sys/Cargo.toml index a633aad..6cd30d6 100644 --- a/blosc2-sys/Cargo.toml +++ b/blosc2-sys/Cargo.toml @@ -8,6 +8,11 @@ links = "blosc2" [dependencies] +[features] +defaults = [] +use-system-blosc2 = [] + [build-dependencies] cmake = "^0.1" bindgen = "^0.64" +pkg-config = "^0.3" diff --git a/blosc2-sys/build.rs b/blosc2-sys/build.rs index 40ee3f6..04b78cf 100644 --- a/blosc2-sys/build.rs +++ b/blosc2-sys/build.rs @@ -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 diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..a780e0b --- /dev/null +++ b/environment.yml @@ -0,0 +1,6 @@ +name: blosc2 +channels: + - conda-forge +dependencies: + - pkg-config + - c-blosc2 ==2.13.2