Skip to content

Commit

Permalink
Only build shared/static as requested by feature flags (#10)
Browse files Browse the repository at this point in the history
* Explicitly only shared, static or both
* Small fix for musl env builds
  • Loading branch information
milesgranger authored Apr 25, 2024
1 parent 35ee5f6 commit f35df97
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
flags:
- --features use-system-blosc2
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: conda-incubator/setup-miniconda@v3
Expand Down Expand Up @@ -71,6 +71,22 @@ jobs:
shell: bash -el {0}
run: cargo test ${{ matrix.flags }}

test-musllinux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross --rev 6d097fb

- name: Test
run: cross test --target x86_64-unknown-linux-musl --no-default-features --features static

test-native:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -82,7 +98,7 @@ jobs:
- windows-latest
- ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ name = "blosc2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["shared"]
use-system-blosc2 = ["shared", "blosc2-sys/use-system-blosc2"]
static = []
shared = []
use-system-blosc2 = ["blosc2-sys/use-system-blosc2"]
static = ["blosc2-sys/static"]
shared = ["blosc2-sys/shared"]

[dependencies]
blosc2-sys = { path = "blosc2-sys", version = "0.2.3+2.14.3" }
Expand Down
37 changes: 12 additions & 25 deletions blosc2-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,18 @@ fn main() {
.define("BUILD_FUZZERS", "OFF")
.define("BUILD_BENCHMARKS", "OFF")
.define("BUILD_EXAMPLES", "OFF")
.define("BUILD_STATIC", "ON")
.define("BUILD_SHARED", "ON")
.define("BUILD_STATIC", "OFF")
.define("BUILD_SHARED", "OFF")
.define("BUILD_TESTS", "OFF")
.define("BUILD_PLUGINS", "OFF")
.define("CMAKE_C_FLAGS", cmake_c_flags)
.always_configure(true);

if cfg!(target_feature = "sse2") {
cmake_conf.define("SHUFFLE_SSE2_ENABLED", "1");
if cfg!(target_env = "msvc") {
if cfg!(target_pointer_width = "32") {
cmake_conf.cflag("/arch:SSE2");
}
} else if cfg!(target_arch = "x86_64")
|| cfg!(target_arch = "x86")
|| cfg!(target_arch = "i686")
{
cmake_conf.cflag("-msse2");
}
if cfg!(feature = "static") {
cmake_conf.define("BUILD_STATIC", "ON");
}

if cfg!(target_feature = "avx2") {
cmake_conf.define("SHUFFLE_AVX2_ENABLED", "1");
if cfg!(target_env = "msvc") {
cmake_conf.cflag("/arch:AVX2");
} else if cfg!(target_arch = "x86_64")
|| cfg!(target_arch = "x86")
|| cfg!(target_arch = "i686")
{
cmake_conf.cflag("-mavx2");
}
if cfg!(feature = "shared") {
cmake_conf.define("BUILD_SHARED", "ON");
}

if std::env::var("BLOSC2_INSTALL_PREFIX").is_ok() {
Expand All @@ -60,6 +41,12 @@ fn main() {
.define("BLOSC_INSTALL", "ON");
}

// Solves undefined reference to __cpu_model when using __builtin_cpu_supports() in shuffle.c
if let Ok(true) = std::env::var("CARGO_CFG_TARGET_ENV").map(|v| v == "musl") {
// TODO: maybe not always libgcc? I'm not sure.
println!("cargo:rustc-link-lib=gcc");
}

cmake_conf.build();

for subdir in &["lib64", "lib", "bin"] {
Expand Down

0 comments on commit f35df97

Please sign in to comment.