Skip to content

Commit a2f88d1

Browse files
committed
Use weak features
1 parent b229be7 commit a2f88d1

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
uses: actions-rs/toolchain@v1
4848
with: {toolchain: nightly, profile: minimal, override: true}
4949
- name: Document workspace
50-
run: env RUSTDOCFLAGS="--cfg docsrs" cargo doc --features hdf5-sys/static,hdf5-sys/zlib,blosc,lzf
50+
run: env RUSTDOCFLAGS="--cfg docsrs" cargo doc --features static,zlib,blosc,lzf
5151

5252
brew:
5353
name: brew

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ pub struct Header {
168168
pub have_direct: bool,
169169
pub have_parallel: bool,
170170
pub have_threadsafe: bool,
171+
pub have_zlib: bool,
172+
pub have_no_deprecated: bool,
171173
pub version: Version,
172174
}
173175

@@ -193,6 +195,10 @@ impl Header {
193195
hdr.have_parallel = value > 0;
194196
} else if name == "H5_HAVE_THREADSAFE" {
195197
hdr.have_threadsafe = value > 0;
198+
} else if name == "H5_HAVE_FILTER_DEFLATE" {
199+
hdr.have_zlib = value > 0;
200+
} else if name == "H5_NO_DEPRECATED_SYMBOLS" {
201+
hdr.have_no_deprecated = value > 0;
196202
}
197203
}
198204

@@ -571,6 +577,7 @@ impl LibrarySearcher {
571577
}
572578
let config = Config { inc_dir: inc_dir.clone(), link_paths, header };
573579
validate_runtime_version(&config);
580+
config.check_against_features_required();
574581
config
575582
} else {
576583
panic!("Unable to determine HDF5 location (set HDF5_DIR to specify it manually).");
@@ -634,6 +641,24 @@ impl Config {
634641
println!("cargo:have_threadsafe=1");
635642
}
636643
}
644+
645+
fn check_against_features_required(&self) {
646+
if feature_enabled("DEPRECATED") {
647+
assert!(!self.header.have_no_deprecated, "Required deprecated symbols are not present")
648+
}
649+
if feature_enabled("THREADSAFE") {
650+
assert!(
651+
self.header.have_threadsafe,
652+
"Required threadsafe but library was not build using the threadsafe option"
653+
);
654+
}
655+
if feature_enabled("ZLIB") {
656+
assert!(
657+
self.header.have_zlib,
658+
"Required zlib filter but library does not have builtin support for this options"
659+
);
660+
}
661+
}
637662
}
638663

639664
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)