|
1 | | -use std::os::raw::{c_int, c_uint}; |
2 | | - |
3 | | -extern "C" { |
4 | | - pub fn H5open() -> c_int; |
5 | | - pub fn H5get_libversion(majnum: *mut c_uint, minnum: *mut c_uint, relnum: *mut c_uint) |
6 | | - -> c_int; |
7 | | -} |
8 | | - |
9 | | -pub fn hdf5_version() -> Result<(u8, u8, u8), &'static str> { |
10 | | - let mut v: (c_uint, c_uint, c_uint) = (0, 0, 0); |
11 | | - unsafe { |
12 | | - if H5open() != 0 { |
13 | | - Err("cannot open HDF5 library") |
14 | | - } else if H5get_libversion(&mut v.0, &mut v.1, &mut v.2) != 0 { |
15 | | - Err("cannot get HDF5 version") |
16 | | - } else { |
17 | | - Ok((v.0 as _, v.1 as _, v.2 as _)) |
| 1 | +macro_rules! check_and_emit { |
| 2 | + ($flag:ident) => { |
| 3 | + if cfg!($flag) { |
| 4 | + println!("cargo:rustc-cfg={}", stringify!($flag)); |
18 | 5 | } |
19 | | - } |
| 6 | + }; |
20 | 7 | } |
21 | 8 |
|
22 | | -pub fn dump_build_flags() { |
23 | | - let version = hdf5_version().unwrap(); |
24 | | - assert!(version >= (1, 8, 4)); |
25 | | - let mut vs: Vec<_> = (5..=21).map(|v| (1, 8, v)).collect(); |
26 | | - vs.extend((0..=1).map(|v| (1, 10, v))); |
27 | | - for v in vs.into_iter().filter(|&v| version >= v) { |
28 | | - println!("cargo:rustc-cfg=hdf5_{}_{}_{}", v.0, v.1, v.2); |
29 | | - } |
30 | | -} |
31 | | - |
32 | | -#[cfg(test)] |
33 | | -pub mod tests { |
34 | | - use super::hdf5_version; |
35 | | - |
36 | | - #[test] |
37 | | - fn test_version() { |
38 | | - assert!(hdf5_version().unwrap() >= (1, 8, 4)); |
39 | | - } |
| 9 | +pub fn emit_cfg_flags() { |
| 10 | + check_and_emit!(hdf5_1_8_5); |
| 11 | + check_and_emit!(hdf5_1_8_6); |
| 12 | + check_and_emit!(hdf5_1_8_7); |
| 13 | + check_and_emit!(hdf5_1_8_8); |
| 14 | + check_and_emit!(hdf5_1_8_9); |
| 15 | + check_and_emit!(hdf5_1_8_10); |
| 16 | + check_and_emit!(hdf5_1_8_11); |
| 17 | + check_and_emit!(hdf5_1_8_12); |
| 18 | + check_and_emit!(hdf5_1_8_13); |
| 19 | + check_and_emit!(hdf5_1_8_14); |
| 20 | + check_and_emit!(hdf5_1_8_15); |
| 21 | + check_and_emit!(hdf5_1_8_16); |
| 22 | + check_and_emit!(hdf5_1_8_17); |
| 23 | + check_and_emit!(hdf5_1_8_18); |
| 24 | + check_and_emit!(hdf5_1_8_19); |
| 25 | + check_and_emit!(hdf5_1_8_20); |
| 26 | + check_and_emit!(hdf5_1_8_21); |
| 27 | + check_and_emit!(hdf5_1_10_0); |
| 28 | + check_and_emit!(hdf5_1_10_1); |
| 29 | + check_and_emit!(hdf5_1_10_2); |
| 30 | + check_and_emit!(hdf5_1_10_3); |
| 31 | + check_and_emit!(hdf5_1_10_4); |
40 | 32 | } |
0 commit comments