Skip to content

Commit 3f51ffb

Browse files
authored
Merge pull request #216 from mulimoen/feature/weak_features
Use weak features in Cargo.toml
2 parents 122ecad + 44b05c1 commit 3f51ffb

File tree

6 files changed

+42
-11
lines changed

6 files changed

+42
-11
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Document workspace
4747
env:
4848
RUSTDOCFLAGS: "--cfg docsrs"
49-
run: cargo doc --features hdf5-sys/static,hdf5-sys/zlib,blosc,lzf
49+
run: cargo doc --features static,zlib,blosc,lzf
5050

5151
brew:
5252
name: brew

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@
1111
datasets. Usage via `Dataset::as_byte_reader()`.
1212
- Add `chunk_visit` to visit all chunks in a dataset.
1313
- Implement `H5Type` for `num_complex::Complex`.
14+
- Adding feature `static` for the `hdf5` crate which downloads and builds a bundled HDF5.
1415

1516
### Changed
1617

1718
- The `H5Type` derive macro now uses `proc-macro-error` to emit error messages.
1819
- MSRV is now `1.64.0` and Rust edition has now been bumped to 2021.
1920
- Types in ChunkInfo has been changed to match HDF5.
21+
- Dependencies now uses the `dep:` syntax and are only enabled through features.
22+
- Some features are made weak and will not enable e.g. static build when asking for a
23+
library which is threadsafe.
24+
- Requesting a feature which is not compiled in the dynamic HDF5 library will
25+
now cause a compile time error.
2026

2127
### Fixed
2228

hdf5-src/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ edition.workspace = true
3030

3131
[features]
3232
hl = []
33-
zlib = ["libz-sys"]
33+
zlib = ["dep:libz-sys"]
3434
deprecated = []
3535
threadsafe = []
3636

hdf5-sys/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ hdf5-src = { workspace = true, optional = true }
2323
# Please see README for further explanation of these feature flags
2424
[features]
2525
default = []
26-
mpio = ["mpi-sys"]
27-
hl = ["hdf5-src/hl"]
28-
threadsafe = ["hdf5-src/threadsafe"]
29-
zlib = ["libz-sys", "hdf5-src/zlib"]
30-
static = ["hdf5-src"]
31-
deprecated = ["hdf5-src/deprecated"]
26+
mpio = ["dep:mpi-sys"]
27+
hl = ["hdf5-src?/hl"]
28+
threadsafe = ["hdf5-src?/threadsafe"]
29+
zlib = ["libz-sys", "hdf5-src?/zlib"]
30+
static = ["dep:hdf5-src"]
31+
deprecated = ["hdf5-src?/deprecated"]
3232

3333
[build-dependencies]
3434
libloading = "0.8"

hdf5-sys/build.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ pub struct Header {
175175
pub have_direct: bool,
176176
pub have_parallel: bool,
177177
pub have_threadsafe: bool,
178+
pub have_zlib: bool,
179+
pub have_no_deprecated: bool,
178180
pub version: Version,
179181
}
180182

@@ -200,6 +202,10 @@ impl Header {
200202
hdr.have_parallel = value > 0;
201203
} else if name == "H5_HAVE_THREADSAFE" {
202204
hdr.have_threadsafe = value > 0;
205+
} else if name == "H5_HAVE_FILTER_DEFLATE" {
206+
hdr.have_zlib = value > 0;
207+
} else if name == "H5_NO_DEPRECATED_SYMBOLS" {
208+
hdr.have_no_deprecated = value > 0;
203209
}
204210
}
205211

@@ -611,6 +617,7 @@ impl LibrarySearcher {
611617
if !(self.pkg_conf_found && cfg!(windows)) {
612618
validate_runtime_version(&config);
613619
}
620+
config.check_against_features_required();
614621
config
615622
} else {
616623
panic!("Unable to determine HDF5 location (set HDF5_DIR to specify it manually).");
@@ -675,6 +682,22 @@ impl Config {
675682
println!("cargo:have_threadsafe=1");
676683
}
677684
}
685+
686+
fn check_against_features_required(&self) {
687+
let h = &self.header;
688+
for (flag, feature, native) in [
689+
(!h.have_no_deprecated, "deprecated", "HDF5_ENABLE_DEPRECATED_SYMBOLS"),
690+
(h.have_threadsafe, "threadsafe", "HDF5_ENABLE_THREADSAFE"),
691+
(h.have_zlib, "zlib", "HDF5_ENABLE_Z_LIB_SUPPORT"),
692+
] {
693+
if feature_enabled(&feature.to_ascii_uppercase()) {
694+
assert!(
695+
flag,
696+
"Enabled feature {feature:?} but the HDF5 library was not built with {native}"
697+
);
698+
}
699+
}
700+
}
678701
}
679702

680703
fn main() {

hdf5/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ edition.workspace = true
1515

1616
[features]
1717
default = []
18-
mpio = ["mpi-sys", "hdf5-sys/mpio"]
19-
lzf = ["lzf-sys", "errno"]
20-
blosc = ["blosc-sys"]
18+
mpio = ["dep:mpi-sys", "hdf5-sys/mpio"]
19+
lzf = ["dep:lzf-sys", "dep:errno"]
20+
blosc = ["dep:blosc-sys"]
21+
static = ["hdf5-sys/static"]
22+
zlib = ["hdf5-sys/zlib"]
2123
# The features with version numbers such as 1.10.3, 1.12.0 are metafeatures
2224
# and is only available when the HDF5 library is at least this version.
2325
# Features have_direct and have_parallel are also metafeatures and dependent

0 commit comments

Comments
 (0)