Skip to content

Commit

Permalink
Merge pull request #3 from mulimoen/feature/cc
Browse files Browse the repository at this point in the history
Switch build system from cmake to cc
  • Loading branch information
mulimoen authored Mar 31, 2023
2 parents d6f3ee2 + 9f9593f commit 509187f
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 326 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ jobs:
toolchain: '${{matrix.rust}}'
- name: Build and test
run: cargo test
- name: Build and test (all features)
run: cargo test --all-features
13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@
name = "blosc-src"
version = "0.1.1"
authors = ["Magnus Ulimoen <[email protected]>"]
edition = "2018"
edition = "2021"
build = "build.rs"
links = "blosc"
license-file = "c-blosc/LICENSES/BLOSC.txt"
exclude = [
"c-blosc/compat/**",
"c-blosc/tests/**",
"c-blosc/bench/**",
"c-blosc/internal-complibs/zlib-1.2.11/contrib/**",
"c-blosc/internal-complibs/zlib-1.2.11/examples/**",
"c-blosc/internal-complibs/zlib-1.2.11/doc/**",
"c-blosc/internal-complibs/zstd-1.5.2/legacy/**",
]
repository = "https://github.com/mulimoen/rust-blosc-src"
keywords = ["compression"]
categories = ["external-ffi-bindings", "compression"]
description = "FFI bindings for blosc-c"

[dependencies]
[features]
lz4 = []
zstd = []
zlib = []

[build-dependencies]
cmake = "0.1.46"
cc = "1.0"
10 changes: 5 additions & 5 deletions bindgen.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#! /bin/sh
bindgen --no-rustfmt-bindings \
--blacklist-type __uint64_t \
--blacklist-type __size_t \
--whitelist-type '.*BLOSC.*' \
--whitelist-function '.*blosc.*' \
--whitelist-var '.*BLOSC.*' \
--blocklist-type __uint64_t \
--blocklist-type __size_t \
--allowlist-type '.*BLOSC.*' \
--allowlist-function '.*blosc.*' \
--allowlist-var '.*BLOSC.*' \
--size_t-is-usize \
c-blosc/blosc/blosc.h > src/bindgen.rs
rustfmt src/bindgen.rs
64 changes: 42 additions & 22 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
use std::fs;

use cc::Build;

fn main() {
println!("cargo:rerun-if-changed=build.rs");
let mut cfg = cmake::Config::new("c-blosc");

for option in &[
"BUILD_SHARED",
"BUILD_TESTS",
"BUILD_FUZZERS",
"BUILD_BENCHMARKS",
"DEACTIVATE_ZSTD",
] {
cfg.define(option, "OFF");
}
let mut build = cc::Build::new();

let target_mscv = cfg!(target_env = "msvc");
let add_file = |builder: &mut Build, folder: &str| {
for entry in fs::read_dir(folder).unwrap() {
let path = entry.unwrap().path();
if let Some(extension) = path.extension() {
if extension == "c" || extension == "cpp" || (!target_mscv && extension == "S") {
builder.file(path);
}
}
}
};

add_file(&mut build, "c-blosc/blosc");

if !cfg!(target_feature = "sse2") {
cfg.define("DEACTIVATE_SSE2", "OFF");
if cfg!(feature = "lz4") {
add_file(&mut build, "c-blosc/internal-complibs/lz4-1.9.3");
build.include("c-blosc/internal-complibs/lz4-1.9.3");
build.define("HAVE_LZ4", None);
}
if !cfg!(target_feature = "avx") {
cfg.define("DEACTIVATE_AVX", "OFF");
if cfg!(feature = "zlib") {
add_file(&mut build, "c-blosc/internal-complibs/zlib-1.2.11");
build.include("c-blosc/internal-complibs/zlib-1.2.11");
build.define("HAVE_ZLIB", None);
}
if cfg!(feature = "zstd") {
add_file(&mut build, "c-blosc/internal-complibs/zstd-1.5.2/common");
add_file(&mut build, "c-blosc/internal-complibs/zstd-1.5.2/compress");
add_file(
&mut build,
"c-blosc/internal-complibs/zstd-1.5.2/decompress",
);
add_file(
&mut build,
"c-blosc/internal-complibs/zstd-1.5.2/dictBuilder",
);
build.include("c-blosc/internal-complibs/zstd-1.5.2");
build.define("HAVE_ZSTD", None);
}

let dst = cfg.build();
println!("cargo:root={}", dst.display());
let incdir = format!("{}/include", dst.display());
println!("cargo:include={}", incdir);
let linklib = if cfg!(target_env = "msvc") {
"libblosc"
} else {
"blosc"
};
println!("cargo:library={}", linklib);

println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo:rustc-link-lib=static={}", linklib);
build.compile(linklib);
}
2 changes: 1 addition & 1 deletion c-blosc
Submodule c-blosc updated 132 files
Loading

0 comments on commit 509187f

Please sign in to comment.