From 49b7b485a9696d5234a963a83d6e9a38a0471c8d Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 9 Jun 2023 19:32:00 +0200 Subject: [PATCH 1/4] Use weak features --- .github/workflows/ci.yml | 2 +- hdf5-src/Cargo.toml | 2 +- hdf5-sys/Cargo.toml | 12 ++++++------ hdf5-sys/build.rs | 25 +++++++++++++++++++++++++ hdf5/Cargo.toml | 8 +++++--- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 329929e3d..3278dcc88 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/hdf5-src/Cargo.toml b/hdf5-src/Cargo.toml index 651ad228e..4eadb2a56 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 59ea20162..54683bf1c 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 880725b8e..71767c198 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,24 @@ impl Config { println!("cargo:have_threadsafe=1"); } } + + fn check_against_features_required(&self) { + if feature_enabled("DEPRECATED") { + assert!(!self.header.have_no_deprecated, "Required deprecated symbols are not present") + } + if feature_enabled("THREADSAFE") { + assert!( + self.header.have_threadsafe, + "Required threadsafe but library was not build using the threadsafe option" + ); + } + if feature_enabled("ZLIB") { + assert!( + self.header.have_zlib, + "Required zlib filter but library does not have builtin support for this options" + ); + } + } } fn main() { diff --git a/hdf5/Cargo.toml b/hdf5/Cargo.toml index d2073593d..714ee0567 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 From 014b43c3f79138ba37d207e9f724daa3b6554888 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Sat, 10 Jun 2023 21:39:38 +0200 Subject: [PATCH 2/4] Merge error messages for build features --- hdf5-sys/build.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/hdf5-sys/build.rs b/hdf5-sys/build.rs index 71767c198..67899ee8a 100644 --- a/hdf5-sys/build.rs +++ b/hdf5-sys/build.rs @@ -684,20 +684,18 @@ impl Config { } fn check_against_features_required(&self) { - if feature_enabled("DEPRECATED") { - assert!(!self.header.have_no_deprecated, "Required deprecated symbols are not present") - } - if feature_enabled("THREADSAFE") { - assert!( - self.header.have_threadsafe, - "Required threadsafe but library was not build using the threadsafe option" - ); - } - if feature_enabled("ZLIB") { - assert!( - self.header.have_zlib, - "Required zlib filter but library does not have builtin support for this options" - ); + 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}" + ); + } } } } From f1efafa033446509a2111d36597796b452eba8db Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Sat, 10 Jun 2023 21:46:06 +0200 Subject: [PATCH 3/4] Add to changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ace2b35de..7933919cb 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 From 44b05c109bcd432bd5de6c532b5f1bc458cf0db7 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Sat, 10 Jun 2023 23:34:14 +0200 Subject: [PATCH 4/4] Negate no-deprecated --- hdf5-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hdf5-sys/build.rs b/hdf5-sys/build.rs index 67899ee8a..9a2fbcaf7 100644 --- a/hdf5-sys/build.rs +++ b/hdf5-sys/build.rs @@ -686,7 +686,7 @@ impl Config { 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_no_deprecated, "deprecated", "HDF5_ENABLE_DEPRECATED_SYMBOLS"), (h.have_threadsafe, "threadsafe", "HDF5_ENABLE_THREADSAFE"), (h.have_zlib, "zlib", "HDF5_ENABLE_Z_LIB_SUPPORT"), ] {