diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 329929e3..3278dcc8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: - name: Document workspace env: RUSTDOCFLAGS: "--cfg docsrs" - run: cargo doc --features hdf5-sys/static,hdf5-sys/zlib,blosc,lzf + run: cargo doc --features static,zlib,blosc,lzf brew: name: brew diff --git a/CHANGELOG.md b/CHANGELOG.md index ace2b35d..7933919c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,18 @@ datasets. Usage via `Dataset::as_byte_reader()`. - Add `chunk_visit` to visit all chunks in a dataset. - Implement `H5Type` for `num_complex::Complex`. +- Adding feature `static` for the `hdf5` crate which downloads and builds a bundled HDF5. ### Changed - The `H5Type` derive macro now uses `proc-macro-error` to emit error messages. - MSRV is now `1.64.0` and Rust edition has now been bumped to 2021. - Types in ChunkInfo has been changed to match HDF5. +- Dependencies now uses the `dep:` syntax and are only enabled through features. +- Some features are made weak and will not enable e.g. static build when asking for a + library which is threadsafe. +- Requesting a feature which is not compiled in the dynamic HDF5 library will + now cause a compile time error. ### Fixed diff --git a/hdf5-src/Cargo.toml b/hdf5-src/Cargo.toml index 651ad228..4eadb2a5 100644 --- a/hdf5-src/Cargo.toml +++ b/hdf5-src/Cargo.toml @@ -30,7 +30,7 @@ edition.workspace = true [features] hl = [] -zlib = ["libz-sys"] +zlib = ["dep:libz-sys"] deprecated = [] threadsafe = [] diff --git a/hdf5-sys/Cargo.toml b/hdf5-sys/Cargo.toml index 59ea2016..54683bf1 100644 --- a/hdf5-sys/Cargo.toml +++ b/hdf5-sys/Cargo.toml @@ -23,12 +23,12 @@ hdf5-src = { workspace = true, optional = true } # Please see README for further explanation of these feature flags [features] default = [] -mpio = ["mpi-sys"] -hl = ["hdf5-src/hl"] -threadsafe = ["hdf5-src/threadsafe"] -zlib = ["libz-sys", "hdf5-src/zlib"] -static = ["hdf5-src"] -deprecated = ["hdf5-src/deprecated"] +mpio = ["dep:mpi-sys"] +hl = ["hdf5-src?/hl"] +threadsafe = ["hdf5-src?/threadsafe"] +zlib = ["libz-sys", "hdf5-src?/zlib"] +static = ["dep:hdf5-src"] +deprecated = ["hdf5-src?/deprecated"] [build-dependencies] libloading = "0.8" diff --git a/hdf5-sys/build.rs b/hdf5-sys/build.rs index 880725b8..9a2fbcaf 100644 --- a/hdf5-sys/build.rs +++ b/hdf5-sys/build.rs @@ -175,6 +175,8 @@ pub struct Header { pub have_direct: bool, pub have_parallel: bool, pub have_threadsafe: bool, + pub have_zlib: bool, + pub have_no_deprecated: bool, pub version: Version, } @@ -200,6 +202,10 @@ impl Header { hdr.have_parallel = value > 0; } else if name == "H5_HAVE_THREADSAFE" { hdr.have_threadsafe = value > 0; + } else if name == "H5_HAVE_FILTER_DEFLATE" { + hdr.have_zlib = value > 0; + } else if name == "H5_NO_DEPRECATED_SYMBOLS" { + hdr.have_no_deprecated = value > 0; } } @@ -611,6 +617,7 @@ impl LibrarySearcher { if !(self.pkg_conf_found && cfg!(windows)) { validate_runtime_version(&config); } + config.check_against_features_required(); config } else { panic!("Unable to determine HDF5 location (set HDF5_DIR to specify it manually)."); @@ -675,6 +682,22 @@ impl Config { println!("cargo:have_threadsafe=1"); } } + + fn check_against_features_required(&self) { + let h = &self.header; + for (flag, feature, native) in [ + (!h.have_no_deprecated, "deprecated", "HDF5_ENABLE_DEPRECATED_SYMBOLS"), + (h.have_threadsafe, "threadsafe", "HDF5_ENABLE_THREADSAFE"), + (h.have_zlib, "zlib", "HDF5_ENABLE_Z_LIB_SUPPORT"), + ] { + if feature_enabled(&feature.to_ascii_uppercase()) { + assert!( + flag, + "Enabled feature {feature:?} but the HDF5 library was not built with {native}" + ); + } + } + } } fn main() { diff --git a/hdf5/Cargo.toml b/hdf5/Cargo.toml index d2073593..714ee056 100644 --- a/hdf5/Cargo.toml +++ b/hdf5/Cargo.toml @@ -15,9 +15,11 @@ edition.workspace = true [features] default = [] -mpio = ["mpi-sys", "hdf5-sys/mpio"] -lzf = ["lzf-sys", "errno"] -blosc = ["blosc-sys"] +mpio = ["dep:mpi-sys", "hdf5-sys/mpio"] +lzf = ["dep:lzf-sys", "dep:errno"] +blosc = ["dep:blosc-sys"] +static = ["hdf5-sys/static"] +zlib = ["hdf5-sys/zlib"] # The features with version numbers such as 1.10.3, 1.12.0 are metafeatures # and is only available when the HDF5 library is at least this version. # Features have_direct and have_parallel are also metafeatures and dependent