Skip to content

Commit a3faa4c

Browse files
committed
hdf5 crate: cfg(have_*) -> feature="have-*"
1 parent 79caf1d commit a3faa4c

File tree

8 files changed

+66
-63
lines changed

8 files changed

+66
-63
lines changed

build.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
use std::env;
22

33
fn main() {
4+
let print_feature = |key: &str| println!("cargo:rustc-cfg=feature=\"{}\"", key);
5+
let print_cfg = |key: &str| println!("cargo:rustc-cfg={}", key);
46
for (key, _) in env::vars() {
5-
let key = match key.as_str() {
6-
"DEP_HDF5_HAVE_DIRECT" => "have_direct".into(),
7-
"DEP_HDF5_HAVE_STDBOOL" => "have_stdbool".into(),
8-
"DEP_HDF5_HAVE_PARALLEL" => "have_parallel".into(),
9-
"DEP_HDF5_HAVE_THREADSAFE" => "have_threadsafe".into(),
10-
"DEP_HDF5_MSVC_DLL_INDIRECTION" => "dll_indirection".into(),
7+
match key.as_str() {
8+
// public features
9+
"DEP_HDF5_HAVE_DIRECT" => print_feature("have-direct"),
10+
"DEP_HDF5_HAVE_PARALLEL" => print_feature("have-parallel"),
11+
"DEP_HDF5_HAVE_THREADSAFE" => print_feature("have-threadsafe"),
12+
// internal config flags
13+
"DEP_HDF5_MSVC_DLL_INDIRECTION" => print_cfg("msvc_dll_indirection"),
14+
// public version features
1115
key if key.starts_with("DEP_HDF5_VERSION_") => {
12-
let version = key.trim_start_matches("DEP_HDF5_VERSION_");
13-
format!("feature=\"{}\"", version.replace("_", "."))
16+
print_feature(&key.trim_start_matches("DEP_HDF5_VERSION_").replace("_", "."));
1417
}
1518
_ => continue,
16-
};
17-
println!("cargo:rustc-cfg={}", key);
19+
}
1820
}
1921
}

hdf5-sys/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ impl Config {
620620
println!("cargo:version_{}_{}_{}=1", v.major, v.minor, v.micro);
621621
}
622622
if self.header.have_stdbool_h {
623-
println!("cargo:have_stdbool=1");
624623
println!("cargo:rustc-cfg=have_stdbool_h");
624+
// there should be no need to export have_stdbool_h downstream
625625
}
626626
if self.header.have_direct {
627627
println!("cargo:rustc-cfg=feature=\"have-direct\"");

src/globals.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::mem;
44

55
use lazy_static::lazy_static;
66

7-
#[cfg(have_direct)]
7+
#[cfg(feature = "have-direct")]
88
use hdf5_sys::h5fd::H5FD_direct_init;
9-
#[cfg(have_parallel)]
9+
#[cfg(feature = "have-parallel")]
1010
use hdf5_sys::h5fd::H5FD_mpio_init;
1111
use hdf5_sys::h5fd::{
1212
H5FD_core_init, H5FD_family_init, H5FD_log_init, H5FD_multi_init, H5FD_sec2_init,
@@ -17,16 +17,16 @@ use hdf5_sys::{h5e, h5p, h5t};
1717
use crate::internal_prelude::*;
1818

1919
pub struct H5GlobalConstant(
20-
#[cfg(dll_indirection)] &'static usize,
21-
#[cfg(not(dll_indirection))] &'static hdf5_sys::h5i::hid_t,
20+
#[cfg(msvc_dll_indirection)] &'static usize,
21+
#[cfg(not(msvc_dll_indirection))] &'static hdf5_sys::h5i::hid_t,
2222
);
2323

2424
impl std::ops::Deref for H5GlobalConstant {
2525
type Target = hdf5_sys::h5i::hid_t;
2626
fn deref(&self) -> &Self::Target {
2727
lazy_static::initialize(&crate::sync::LIBRARY_INIT);
2828
cfg_if::cfg_if! {
29-
if #[cfg(dll_indirection)] {
29+
if #[cfg(msvc_dll_indirection)] {
3030
let dll_ptr = self.0 as *const usize;
3131
let ptr: *const *const hdf5_sys::h5i::hid_t = dll_ptr.cast();
3232
unsafe {
@@ -336,21 +336,21 @@ lazy_static! {
336336
}
337337

338338
// MPI-IO file driver
339-
#[cfg(have_parallel)]
339+
#[cfg(feature = "have-parallel")]
340340
lazy_static! {
341341
pub static ref H5FD_MPIO: hid_t = unsafe { h5lock!(H5FD_mpio_init()) };
342342
}
343-
#[cfg(not(have_parallel))]
343+
#[cfg(not(feature = "have-parallel"))]
344344
lazy_static! {
345345
pub static ref H5FD_MPIO: hid_t = H5I_INVALID_HID;
346346
}
347347

348348
// Direct VFD
349-
#[cfg(have_direct)]
349+
#[cfg(feature = "have-direct")]
350350
lazy_static! {
351351
pub static ref H5FD_DIRECT: hid_t = unsafe { h5lock!(H5FD_direct_init()) };
352352
}
353-
#[cfg(not(have_direct))]
353+
#[cfg(not(feature = "have-direct"))]
354354
lazy_static! {
355355
pub static ref H5FD_DIRECT: hid_t = H5I_INVALID_HID;
356356
}

src/hl/dataset.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ impl DatasetBuilderInner {
611611
self.with_dapl(|pl| pl.virtual_printf_gap(gap_size));
612612
}
613613

614-
#[cfg(all(feature = "1.10.0", have_parallel))]
614+
#[cfg(all(feature = "1.10.0", feature = "have-parallel"))]
615615
pub fn all_coll_metadata_ops(&mut self, is_collective: bool) {
616616
self.with_dapl(|pl| pl.all_coll_metadata_ops(is_collective));
617617
}
@@ -908,11 +908,11 @@ macro_rules! impl_builder {
908908
}
909909
};
910910
($(#[cfg(feature = $feature:literal)])*
911-
$(#[cfg(all(feature = $feature2:literal, $feature3:ident))])*
911+
$(#[cfg(all(feature = $feature2:literal, feature = $feature3:literal))])*
912912
$plist:ident: $name:ident($($var:ident: $ty:ty),*)) => {
913913
paste::paste! {
914914
$(#[cfg(feature = $feature )])*
915-
$(#[cfg(all(feature = $feature2, $feature3))])*
915+
$(#[cfg(all(feature = $feature2, feature = $feature3))])*
916916
#[inline] #[must_use] #[doc =
917917
"\u{21b3} [`" $plist "Builder::" $name "`]"
918918
"(crate::plist::" $plist "Builder::" $name ")"
@@ -947,7 +947,7 @@ macro_rules! impl_builder_methods {
947947
impl_builder!(#[cfg(feature = "1.10.0")] DatasetAccess: virtual_view(view: VirtualView));
948948
impl_builder!(#[cfg(feature = "1.10.0")] DatasetAccess: virtual_printf_gap(gap_size: usize));
949949
impl_builder!(
950-
#[cfg(all(feature = "1.10.0", have_parallel))]
950+
#[cfg(all(feature = "1.10.0", feature = "have-parallel"))]
951951
DatasetAccess: all_coll_metadata_ops(is_collective: bool)
952952
);
953953

src/hl/plist/dataset_access.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::fmt::{self, Debug};
99
use std::ops::Deref;
1010

1111
use hdf5_sys::h5p::{H5Pcreate, H5Pget_chunk_cache, H5Pset_chunk_cache};
12-
#[cfg(all(feature = "1.10.0", have_parallel))]
12+
#[cfg(all(feature = "1.10.0", feature = "have-parallel"))]
1313
use hdf5_sys::h5p::{H5Pget_all_coll_metadata_ops, H5Pset_all_coll_metadata_ops};
1414
#[cfg(feature = "1.8.17")]
1515
use hdf5_sys::h5p::{H5Pget_efile_prefix, H5Pset_efile_prefix};
@@ -62,7 +62,7 @@ impl Debug for DatasetAccess {
6262
formatter.field("virtual_view", &self.virtual_view());
6363
formatter.field("virtual_printf_gap", &self.virtual_printf_gap());
6464
}
65-
#[cfg(all(feature = "1.10.0", have_parallel))]
65+
#[cfg(all(feature = "1.10.0", feature = "have-parallel"))]
6666
formatter.field("all_coll_metadata_ops", &self.all_coll_metadata_ops());
6767
formatter.finish()
6868
}
@@ -134,7 +134,7 @@ pub struct DatasetAccessBuilder {
134134
virtual_view: Option<VirtualView>,
135135
#[cfg(feature = "1.10.0")]
136136
virtual_printf_gap: Option<usize>,
137-
#[cfg(all(feature = "1.10.0", have_parallel))]
137+
#[cfg(all(feature = "1.10.0", feature = "have-parallel"))]
138138
all_coll_metadata_ops: Option<bool>,
139139
}
140140

@@ -159,7 +159,7 @@ impl DatasetAccessBuilder {
159159
builder.virtual_view(plist.get_virtual_view()?);
160160
builder.virtual_printf_gap(plist.get_virtual_printf_gap()?);
161161
}
162-
#[cfg(all(feature = "1.10.0", have_parallel))]
162+
#[cfg(all(feature = "1.10.0", feature = "have-parallel"))]
163163
builder.all_coll_metadata_ops(plist.get_all_coll_metadata_ops()?);
164164
Ok(builder)
165165
}
@@ -187,7 +187,7 @@ impl DatasetAccessBuilder {
187187
self
188188
}
189189

190-
#[cfg(all(feature = "1.10.0", have_parallel))]
190+
#[cfg(all(feature = "1.10.0", feature = "have-parallel"))]
191191
pub fn all_coll_metadata_ops(&mut self, is_collective: bool) -> &mut Self {
192192
self.all_coll_metadata_ops = Some(is_collective);
193193
self
@@ -213,7 +213,7 @@ impl DatasetAccessBuilder {
213213
h5try!(H5Pset_virtual_printf_gap(id, v as _));
214214
}
215215
}
216-
#[cfg(all(feature = "1.10.0", have_parallel))]
216+
#[cfg(all(feature = "1.10.0", feature = "have-parallel"))]
217217
{
218218
if let Some(v) = self.all_coll_metadata_ops {
219219
h5try!(H5Pset_all_coll_metadata_ops(id, v as _));
@@ -296,13 +296,13 @@ impl DatasetAccess {
296296
self.get_virtual_printf_gap().unwrap_or(0)
297297
}
298298

299-
#[cfg(all(feature = "1.10.0", have_parallel))]
299+
#[cfg(all(feature = "1.10.0", feature = "have-parallel"))]
300300
#[doc(hidden)]
301301
pub fn get_all_coll_metadata_ops(&self) -> Result<bool> {
302302
h5get!(H5Pget_all_coll_metadata_ops(self.id()): hbool_t).map(|x| x > 0)
303303
}
304304

305-
#[cfg(all(feature = "1.10.0", have_parallel))]
305+
#[cfg(all(feature = "1.10.0", feature = "have-parallel"))]
306306
pub fn all_coll_metadata_ops(&self) -> bool {
307307
self.get_all_coll_metadata_ops().unwrap_or(false)
308308
}

0 commit comments

Comments
 (0)