Skip to content

Use weak features in Cargo.toml #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion hdf5-src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ edition.workspace = true

[features]
hl = []
zlib = ["libz-sys"]
zlib = ["dep:libz-sys"]
deprecated = []
threadsafe = []

Expand Down
12 changes: 6 additions & 6 deletions hdf5-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions hdf5-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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).");
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 5 additions & 3 deletions hdf5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down