Skip to content

Commit 994f33a

Browse files
authored
Merge pull request #181 from aldanor/feature/doc-cfg
Experimental docs.rs changes
2 parents 5b7ab7a + 4ccf8bb commit 994f33a

36 files changed

+577
-492
lines changed

.github/workflows/ci.yml

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ jobs:
3737
command: ${{matrix.command}}
3838
args: "${{matrix.command == 'fmt' && '--all -- --check' || '-- -D warnings'}}"
3939

40+
doc: # This task should mirror the procedure on docs.rs
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v2
45+
with: {submodules: true}
46+
- name: Install Rust (${{matrix.rust}})
47+
uses: actions-rs/toolchain@v1
48+
with: {toolchain: nightly, profile: minimal, override: true}
49+
- name: Document workspace
50+
run: env RUSTDOCFLAGS="--cfg docsrs" cargo doc --features hdf5-sys/static,hdf5-sys/zlib,blosc,lzf
51+
4052
brew:
4153
name: brew
4254
runs-on: macos-latest

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ default = []
1616
mpio = ["mpi-sys", "hdf5-sys/mpio"]
1717
lzf = ["lzf-sys", "errno"]
1818
blosc = ["blosc-sys"]
19+
# The features with version numbers such as 1.10.3, 1.12.0 are metafeatures
20+
# and is only available when the HDF5 library is at least this version.
21+
# Features have_direct and have_parallel are also metafeatures and dependent
22+
# on the HDF5 library which is linked against.
1923

2024
[workspace]
2125
members = [".", "hdf5-types", "hdf5-derive", "hdf5-sys", "hdf5-src"]
@@ -47,3 +51,4 @@ tempfile = "3.2"
4751

4852
[package.metadata.docs.rs]
4953
features = ["hdf5-sys/static", "hdf5-sys/zlib", "blosc", "lzf"]
54+
rustdoc-args = ["--cfg", "docsrs"]

build.rs

+12-10
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" => "h5_have_direct".into(),
7-
"DEP_HDF5_HAVE_STDBOOL" => "h5_have_stdbool".into(),
8-
"DEP_HDF5_HAVE_PARALLEL" => "h5_have_parallel".into(),
9-
"DEP_HDF5_HAVE_THREADSAFE" => "h5_have_threadsafe".into(),
10-
"DEP_HDF5_MSVC_DLL_INDIRECTION" => "h5_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!("hdf5_{}", version)
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -616,23 +616,23 @@ impl Config {
616616
vs.extend((0..=7).map(|v| Version::new(1, 10, v))); // 1.10.[0-7]
617617
vs.push(Version::new(1, 12, 0)); // 1.12.0
618618
for v in vs.into_iter().filter(|&v| version >= v) {
619-
println!("cargo:rustc-cfg=hdf5_{}_{}_{}", v.major, v.minor, v.micro);
619+
println!("cargo:rustc-cfg=feature=\"{}.{}.{}\"", v.major, v.minor, v.micro);
620620
println!("cargo:version_{}_{}_{}=1", v.major, v.minor, v.micro);
621621
}
622622
if self.header.have_stdbool_h {
623-
println!("cargo:rustc-cfg=h5_have_stdbool_h");
624-
println!("cargo:have_stdbool=1");
623+
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 {
627-
println!("cargo:rustc-cfg=h5_have_direct");
627+
println!("cargo:rustc-cfg=feature=\"have-direct\"");
628628
println!("cargo:have_direct=1");
629629
}
630630
if self.header.have_parallel {
631-
println!("cargo:rustc-cfg=h5_have_parallel");
631+
println!("cargo:rustc-cfg=feature=\"have-parallel\"");
632632
println!("cargo:have_parallel=1");
633633
}
634634
if self.header.have_threadsafe {
635-
println!("cargo:rustc-cfg=h5_have_threadsafe");
635+
println!("cargo:rustc-cfg=feature=\"have-threadsafe\"");
636636
println!("cargo:have_threadsafe=1");
637637
}
638638
}

hdf5-sys/src/h5.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ pub type hsize_t = c_ulonglong;
1212
pub type hssize_t = c_longlong;
1313
pub type haddr_t = uint64_t;
1414

15-
#[cfg(all(hdf5_1_10_0, h5_have_stdbool_h))]
15+
#[cfg(all(feature = "1.10.0", have_stdbool_h))]
1616
pub type hbool_t = u8;
17-
#[cfg(any(not(hdf5_1_10_0), not(h5_have_stdbool_h)))]
17+
#[cfg(any(not(feature = "1.10.0"), not(have_stdbool_h)))]
1818
pub type hbool_t = c_uint;
1919

2020
#[repr(C)]
@@ -71,23 +71,23 @@ extern "C" {
7171
pub fn H5check_version(majnum: c_uint, minnum: c_uint, relnum: c_uint) -> herr_t;
7272
}
7373

74-
#[cfg(hdf5_1_8_13)]
74+
#[cfg(feature = "1.8.13")]
7575
extern "C" {
7676
pub fn H5free_memory(mem: *mut c_void) -> herr_t;
7777
}
7878

79-
#[cfg(hdf5_1_8_15)]
79+
#[cfg(feature = "1.8.15")]
8080
extern "C" {
8181
pub fn H5allocate_memory(size: size_t, clear: hbool_t) -> *mut c_void;
8282
pub fn H5resize_memory(mem: *mut c_void, size: size_t) -> *mut c_void;
8383
}
8484

85-
#[cfg(hdf5_1_8_16)]
85+
#[cfg(feature = "1.8.16")]
8686
extern "C" {
8787
pub fn H5is_library_threadsafe(is_ts: *mut hbool_t) -> herr_t;
8888
}
8989

90-
#[cfg(all(hdf5_1_10_7, not(hdf5_1_12_0)))]
90+
#[cfg(all(feature = "1.10.7", not(feature = "1.12.0")))]
9191
#[repr(C)]
9292
pub struct H5_alloc_stats_t {
9393
total_alloc_bytes: c_ulonglong,
@@ -99,7 +99,7 @@ pub struct H5_alloc_stats_t {
9999
peak_alloc_blocks_count: size_t,
100100
}
101101

102-
#[cfg(all(hdf5_1_10_7, not(hdf5_1_12_0)))]
102+
#[cfg(all(feature = "1.10.7", not(feature = "1.12.0")))]
103103
extern "C" {
104104
pub fn H5get_alloc_stats(stats: *mut H5_alloc_stats_t) -> herr_t;
105105
pub fn H5get_free_list_sizes(

hdf5-sys/src/h5ac.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ pub struct H5AC_cache_config_t {
4545
pub epochs_before_eviction: c_int,
4646
pub apply_empty_reserve: hbool_t,
4747
pub empty_reserve: c_double,
48-
#[cfg(not(hdf5_1_10_0))]
48+
#[cfg(not(feature = "1.10.0"))]
4949
pub dirty_bytes_threshold: c_int,
50-
#[cfg(hdf5_1_10_0)]
50+
#[cfg(feature = "1.10.0")]
5151
pub dirty_bytes_threshold: size_t,
5252
pub metadata_write_strategy: c_int,
5353
}
@@ -58,7 +58,7 @@ impl Default for H5AC_cache_config_t {
5858
}
5959
}
6060

61-
#[cfg(hdf5_1_10_1)]
61+
#[cfg(feature = "1.10.1")]
6262
mod hdf5_1_10_1 {
6363
use super::*;
6464

@@ -78,5 +78,5 @@ mod hdf5_1_10_1 {
7878
}
7979
}
8080

81-
#[cfg(hdf5_1_10_1)]
81+
#[cfg(feature = "1.10.1")]
8282
pub use self::hdf5_1_10_1::*;

hdf5-sys/src/h5d.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub const H5D_CHUNK_CACHE_NBYTES_DEFAULT: size_t = !0;
1616

1717
pub const H5D_CHUNK_CACHE_W0_DEFAULT: c_float = -1.0;
1818

19-
#[cfg(not(hdf5_1_10_0))]
19+
#[cfg(not(feature = "1.10.0"))]
2020
#[repr(C)]
2121
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
2222
pub enum H5D_layout_t {
@@ -134,15 +134,15 @@ pub type H5D_operator_t = Option<
134134
) -> herr_t,
135135
>;
136136

137-
#[cfg(hdf5_1_8_11)]
137+
#[cfg(feature = "1.8.11")]
138138
pub type H5D_scatter_func_t = Option<
139139
extern "C" fn(
140140
src_buf: *mut *const c_void,
141141
src_buf_bytes_used: *mut size_t,
142142
op_data: *mut c_void,
143143
) -> herr_t,
144144
>;
145-
#[cfg(hdf5_1_8_11)]
145+
#[cfg(feature = "1.8.11")]
146146
pub type H5D_gather_func_t = Option<
147147
extern "C" fn(
148148
dst_buf: *const c_void,
@@ -180,7 +180,7 @@ extern "C" {
180180
buf: *mut c_void, type_id: hid_t, space_id: hid_t, op: H5D_operator_t,
181181
operator_data: *mut c_void,
182182
) -> herr_t;
183-
#[cfg_attr(hdf5_1_12_0, deprecated(note = "deprecated in HDF5 1.12.0, use H5Treclaim"))]
183+
#[cfg_attr(feature = "1.12.0", deprecated(note = "deprecated in HDF5 1.12.0, use H5Treclaim"))]
184184
pub fn H5Dvlen_reclaim(
185185
type_id: hid_t, space_id: hid_t, plist_id: hid_t, buf: *mut c_void,
186186
) -> herr_t;
@@ -201,7 +201,7 @@ extern "C" {
201201
pub fn H5Dopen1(file_id: hid_t, name: *const c_char) -> hid_t;
202202
}
203203

204-
#[cfg(hdf5_1_8_11)]
204+
#[cfg(feature = "1.8.11")]
205205
extern "C" {
206206
pub fn H5Dscatter(
207207
op: H5D_scatter_func_t, op_data: *mut c_void, type_id: hid_t, dst_space_id: hid_t,
@@ -213,7 +213,7 @@ extern "C" {
213213
) -> herr_t;
214214
}
215215

216-
#[cfg(hdf5_1_10_0)]
216+
#[cfg(feature = "1.10.0")]
217217
mod hdf5_1_10_0 {
218218
use super::*;
219219

@@ -260,10 +260,10 @@ mod hdf5_1_10_0 {
260260
}
261261
}
262262

263-
#[cfg(hdf5_1_10_0)]
263+
#[cfg(feature = "1.10.0")]
264264
pub use self::hdf5_1_10_0::*;
265265

266-
#[cfg(hdf5_1_10_3)]
266+
#[cfg(feature = "1.10.3")]
267267
extern "C" {
268268
pub fn H5Dread_chunk(
269269
dset_id: hid_t, dxpl_id: hid_t, offset: *const hsize_t, filters: *mut u32, buf: *mut c_void,
@@ -274,7 +274,7 @@ extern "C" {
274274
) -> herr_t;
275275
}
276276

277-
#[cfg(hdf5_1_10_5)]
277+
#[cfg(feature = "1.10.5")]
278278
extern "C" {
279279
pub fn H5Dget_chunk_info(
280280
dset_id: hid_t, fspace_id: hid_t, index: hsize_t, offset: *mut hsize_t,

0 commit comments

Comments
 (0)