From f35df97ba646b3e7ae9f570fd2eafd18c55f83f3 Mon Sep 17 00:00:00 2001 From: Miles Date: Thu, 25 Apr 2024 06:27:39 +0200 Subject: [PATCH] Only build shared/static as requested by feature flags (#10) * Explicitly only shared, static or both * Small fix for musl env builds --- .github/workflows/CI.yml | 20 ++++++++++++++++++-- Cargo.toml | 6 +++--- blosc2-sys/build.rs | 37 ++++++++++++------------------------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 85ff2fb..054410e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 @@ -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: @@ -82,7 +98,7 @@ jobs: - windows-latest - ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive diff --git a/Cargo.toml b/Cargo.toml index 67722f3..7bec91e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/blosc2-sys/build.rs b/blosc2-sys/build.rs index 45b3799..a3a4dad 100644 --- a/blosc2-sys/build.rs +++ b/blosc2-sys/build.rs @@ -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() { @@ -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"] {