Skip to content

Commit 8edce51

Browse files
authored
Merge pull request aldanor#5 from metno/feature/check-cfg
Emit check-cfg
2 parents 0e01290 + e84fda7 commit 8edce51

File tree

10 files changed

+106
-63
lines changed

10 files changed

+106
-63
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ jobs:
279279
with: {submodules: true}
280280
- name: Install Rust
281281
uses: dtolnay/rust-toolchain@stable
282-
with: {toolchain: "1.70"}
282+
with: {toolchain: "1.77"}
283283
- name: Build and test all crates
284284
run:
285285
cargo test --workspace -vv --features=hdf5-sys/static,hdf5-sys/zlib --exclude=hdf5-derive

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ default-members = ["hdf5", "hdf5-types", "hdf5-derive", "hdf5-sys"]
55

66
[workspace.package]
77
version = "0.8.1" # !V
8-
rust-version = "1.64.0"
8+
rust-version = "1.77.0"
99
authors = [
1010
"Ivan Smirnov <[email protected]>",
1111
"Magnus Ulimoen <[email protected]>",

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ HDF5 for Rust.
66
[![Latest Version](https://img.shields.io/crates/v/hdf5.svg)](https://crates.io/crates/hdf5)
77
[![Documentation](https://docs.rs/hdf5/badge.svg)](https://docs.rs/hdf5)
88
[![Changelog](https://img.shields.io/github/v/release/aldanor/hdf5-rust)](https://github.com/aldanor/hdf5-rust/blob/master/CHANGELOG.md)
9-
![hdf5: rustc 1.51+](https://img.shields.io/badge/hdf5-rustc_1.51+-lightblue.svg)
9+
![hdf5: rustc 1.77+](https://img.shields.io/badge/hdf5-rustc_1.77+-lightblue.svg)
1010
[![Total Lines](https://tokei.rs/b1/github/aldanor/hdf5-rust)](https://github.com/aldanor/hdf5-rust)
1111
[![Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
1212
[![MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
@@ -112,7 +112,7 @@ toolchains; macOS Catalina).
112112
### Rust
113113

114114
`hdf5` crate is tested continuously for all three official release channels, and
115-
requires a reasonably recent Rust compiler (e.g. of version 1.51 or newer).
115+
requires a reasonably recent Rust compiler (e.g. of version 1.77 or newer).
116116

117117
### HDF5
118118

hdf5-sys/build.rs

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::convert::TryInto;
55
use std::env;
66
use std::error::Error;
7-
use std::fmt::{self, Debug, Display};
7+
use std::fmt::{self, Debug};
88
use std::fs;
99
use std::os::raw::{c_int, c_uint};
1010
use std::path::{Path, PathBuf};
@@ -49,6 +49,16 @@ impl Debug for Version {
4949
}
5050
}
5151

52+
fn known_hdf5_versions() -> Vec<Version> {
53+
// Keep up to date with known_versions in hdf5
54+
let mut vs = Vec::new();
55+
vs.extend((5..=21).map(|v| Version::new(1, 8, v))); // 1.8.[5-23]
56+
vs.extend((0..=8).map(|v| Version::new(1, 10, v))); // 1.10.[0-10]
57+
vs.extend((0..=2).map(|v| Version::new(1, 12, v))); // 1.12.[0-2]
58+
vs.extend((0..=4).map(|v| Version::new(1, 14, v))); // 1.14.[0-4]
59+
vs
60+
}
61+
5262
#[allow(dead_code)]
5363
fn run_command(cmd: &str, args: &[&str]) -> Option<String> {
5464
let out = Command::new(cmd).args(args).output();
@@ -80,17 +90,6 @@ fn is_msvc() -> bool {
8090
std::env::var("CARGO_CFG_TARGET_ENV").unwrap() == "msvc"
8191
}
8292

83-
#[derive(Clone, Debug)]
84-
struct RuntimeError(String);
85-
86-
impl Error for RuntimeError {}
87-
88-
impl Display for RuntimeError {
89-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
90-
write!(f, "HDF5 runtime error: {}", self.0)
91-
}
92-
}
93-
9493
#[allow(non_snake_case, non_camel_case_types)]
9594
fn get_runtime_version_single<P: AsRef<Path>>(path: P) -> Result<Version, Box<dyn Error>> {
9695
type H5open_t = unsafe extern "C" fn() -> c_int;
@@ -634,59 +633,68 @@ pub struct Config {
634633

635634
impl Config {
636635
pub fn emit_link_flags(&self) {
637-
println!("cargo:rustc-link-lib=dylib=hdf5");
636+
println!("cargo::rustc-link-lib=dylib=hdf5");
638637
for dir in &self.link_paths {
639-
println!("cargo:rustc-link-search=native={}", dir.to_str().unwrap());
638+
println!("cargo::rustc-link-search=native={}", dir.to_str().unwrap());
640639
}
641-
println!("cargo:rerun-if-env-changed=HDF5_DIR");
642-
println!("cargo:rerun-if-env-changed=HDF5_VERSION");
640+
println!("cargo::rerun-if-env-changed=HDF5_DIR");
641+
println!("cargo::rerun-if-env-changed=HDF5_VERSION");
643642

644643
if is_msvc() {
645-
println!("cargo:msvc_dll_indirection=1");
644+
println!("cargo::metadata=msvc_dll_indirection=1");
646645
}
647-
println!("cargo:include={}", self.inc_dir.to_str().unwrap());
646+
println!("cargo::metadata=include={}", self.inc_dir.to_str().unwrap());
648647

649-
println!("cargo:library=hdf5");
648+
println!("cargo::metadata=library=hdf5");
650649

651650
if feature_enabled("HL") {
652-
println!("cargo:hl_library=hdf5_hl");
651+
println!("cargo::metadata=hl_library=hdf5_hl");
653652
}
654653
}
655654

656655
pub fn emit_cfg_flags(&self) {
657656
let version = self.header.version;
658657
assert!(version >= Version::new(1, 8, 4), "required HDF5 version: >=1.8.4");
659-
let mut vs: Vec<_> = (5..=21).map(|v| Version::new(1, 8, v)).collect(); // 1.8.[5-23]
660-
vs.extend((0..=8).map(|v| Version::new(1, 10, v))); // 1.10.[0-10]
661-
vs.extend((0..=2).map(|v| Version::new(1, 12, v))); // 1.12.[0-2]
662-
vs.extend((0..=4).map(|v| Version::new(1, 14, v))); // 1.14.[0-4]
663-
for v in vs.into_iter().filter(|&v| version >= v) {
664-
println!("cargo:rustc-cfg=feature=\"{}.{}.{}\"", v.major, v.minor, v.micro);
665-
println!("cargo:version_{}_{}_{}=1", v.major, v.minor, v.micro);
658+
659+
for v in known_hdf5_versions() {
660+
println!(
661+
"cargo::rustc-check-cfg=cfg(feature, values(\"{}.{}.{}\"))",
662+
v.major, v.minor, v.micro
663+
);
664+
}
665+
for v in known_hdf5_versions().into_iter().filter(|&v| version >= v) {
666+
println!("cargo::rustc-cfg=feature=\"{}.{}.{}\"", v.major, v.minor, v.micro);
667+
println!("cargo::metadata=version_{}_{}_{}=1", v.major, v.minor, v.micro);
666668
}
669+
670+
println!("cargo::rustc-check-cfg=cfg(have_stdbool_h)");
667671
if self.header.have_stdbool_h {
668-
println!("cargo:rustc-cfg=have_stdbool_h");
672+
println!("cargo::rustc-cfg=have_stdbool_h");
669673
// there should be no need to export have_stdbool_h downstream
670674
}
675+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"have-direct\"))");
671676
if self.header.have_direct {
672-
println!("cargo:rustc-cfg=feature=\"have-direct\"");
673-
println!("cargo:have_direct=1");
677+
println!("cargo::rustc-cfg=feature=\"have-direct\"");
678+
println!("cargo::metadata=have_direct=1");
674679
}
680+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"have-parallel\"))");
675681
if self.header.have_parallel {
676-
println!("cargo:rustc-cfg=feature=\"have-parallel\"");
677-
println!("cargo:have_parallel=1");
682+
println!("cargo::rustc-cfg=feature=\"have-parallel\"");
683+
println!("cargo::metadata=have_parallel=1");
678684
}
685+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"have-threadsafe\"))");
679686
if self.header.have_threadsafe {
680-
println!("cargo:rustc-cfg=feature=\"have-threadsafe\"");
681-
println!("cargo:have_threadsafe=1");
687+
println!("cargo::rustc-cfg=feature=\"have-threadsafe\"");
688+
println!("cargo::metadata=have_threadsafe=1");
682689
}
690+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"have-filter-deflate\"))");
683691
if self.header.have_filter_deflate {
684-
println!("cargo:rustc-cfg=feature=\"have-filter-deflate\"");
685-
println!("cargo:have_filter_deflate=1");
692+
println!("cargo::rustc-cfg=feature=\"have-filter-deflate\"");
693+
println!("cargo::metadata=have_filter_deflate=1");
686694
}
687695

688696
if cfg!(windows) && version >= Version::new(1, 14, 0) {
689-
println!("cargo:rustc-link-lib=shlwapi");
697+
println!("cargo::rustc-link-lib=shlwapi");
690698
}
691699
}
692700

@@ -721,31 +729,31 @@ fn main() {
721729
}
722730

723731
fn get_build_and_emit() {
724-
println!("cargo:rerun-if-changed=build.rs");
732+
println!("cargo::rerun-if-changed=build.rs");
725733

726734
if feature_enabled("ZLIB") {
727735
let zlib_lib = env::var("DEP_HDF5SRC_ZLIB").unwrap();
728-
println!("cargo:zlib={}", &zlib_lib);
736+
println!("cargo::metadata=zlib={}", &zlib_lib);
729737
let zlib_lib_header = env::var("DEP_HDF5SRC_ZLIB").unwrap();
730-
println!("cargo:zlib={}", &zlib_lib_header);
731-
println!("cargo:rustc-link-lib=static={}", &zlib_lib);
738+
println!("cargo::metadata=zlib={}", &zlib_lib_header);
739+
println!("cargo::rustc-link-lib=static={}", &zlib_lib);
732740
}
733741

734742
if feature_enabled("HL") {
735743
let hdf5_hl_lib = env::var("DEP_HDF5SRC_HL_LIBRARY").unwrap();
736-
println!("cargo:rustc-link-lib=static={}", &hdf5_hl_lib);
737-
println!("cargo:hl_library={}", &hdf5_hl_lib);
744+
println!("cargo::rustc-link-lib=static={}", &hdf5_hl_lib);
745+
println!("cargo::metadata=hl_library={}", &hdf5_hl_lib);
738746
}
739747

740748
let hdf5_root = env::var("DEP_HDF5SRC_ROOT").unwrap();
741-
println!("cargo:root={}", &hdf5_root);
749+
println!("cargo::metadata=root={}", &hdf5_root);
742750
let hdf5_incdir = env::var("DEP_HDF5SRC_INCLUDE").unwrap();
743-
println!("cargo:include={}", &hdf5_incdir);
751+
println!("cargo::metadata=include={}", &hdf5_incdir);
744752
let hdf5_lib = env::var("DEP_HDF5SRC_LIBRARY").unwrap();
745-
println!("cargo:library={}", &hdf5_lib);
753+
println!("cargo::metadata=library={}", &hdf5_lib);
746754

747-
println!("cargo:rustc-link-search=native={}/lib", &hdf5_root);
748-
println!("cargo:rustc-link-lib=static={}", &hdf5_lib);
755+
println!("cargo::rustc-link-search=native={}/lib", &hdf5_root);
756+
println!("cargo::rustc-link-lib=static={}", &hdf5_lib);
749757

750758
let header = Header::parse(&hdf5_incdir);
751759
let config = Config { header, inc_dir: "".into(), link_paths: Vec::new() };

hdf5-sys/src/h5f.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl Default for H5F_libver_t {
144144

145145
extern "C" {
146146
#[cfg_attr(
147-
hdf5_1_10_2,
147+
feature = "1.10.2",
148148
deprecated(note = "deprecated in HDF5 1.10.2, use H5Fset_libver_bounds()")
149149
)]
150150
pub fn H5Fset_latest_format(file_id: hid_t, latest_format: hbool_t) -> herr_t;

hdf5-sys/src/h5l.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ extern "C" {
275275
loc_id: hid_t, name: *const c_char, linfo: *mut H5L_info2_t, lapl_id: hid_t,
276276
) -> herr_t;
277277
#[cfg_attr(
278-
hdf5_1_12_0,
278+
feature = "1.12.0",
279279
deprecated(note = "deprecated in HDF5 1.12.0, use H5Lget_info_by_idx2()")
280280
)]
281281
#[cfg_attr(not(feature = "1.12.0"), link_name = "H5Lget_info_by_idx")]
@@ -307,7 +307,7 @@ extern "C" {
307307
op: H5L_iterate2_t, op_data: *mut c_void,
308308
) -> herr_t;
309309
#[cfg_attr(
310-
hdf5_1_12_0,
310+
feature = "1.12.0",
311311
deprecated(note = "deprecated in HDF5 1.12.0, use H5Literate_by_name2()")
312312
)]
313313
#[cfg_attr(not(feature = "1.12.0"), link_name = "H5Literate_by_name")]
@@ -332,7 +332,7 @@ extern "C" {
332332
op_data: *mut c_void,
333333
) -> herr_t;
334334
#[cfg_attr(
335-
hdf5_1_12_0,
335+
feature = "1.12.0",
336336
deprecated(note = "deprecated in HDF5 1.12.0, use H5Lvisit_by_name2()")
337337
)]
338338
#[cfg_attr(not(feature = "1.12.0"), link_name = "H5Lvisit_by_name")]

hdf5-sys/src/h5p.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,14 +709,14 @@ extern "C" {
709709
) -> herr_t;
710710
pub fn H5Pdecode(buf: *const c_void) -> hid_t;
711711
#[cfg_attr(
712-
hdf5_1_10_1,
712+
feature = "1.10.1",
713713
deprecated(note = "deprecated in HDF5 1.10.1, use H5Pset_file_space_strategy()")
714714
)]
715715
pub fn H5Pset_file_space(
716716
plist_id: hid_t, strategy: H5F_file_space_type_t, threshold: hsize_t,
717717
) -> herr_t;
718718
#[cfg_attr(
719-
hdf5_1_10_1,
719+
feature = "1.10.1",
720720
deprecated(note = "deprecated in HDF5 1.10.1, use H5Pget_file_space_strategy()")
721721
)]
722722
pub fn H5Pget_file_space(

hdf5-types/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
fn main() {
2-
println!("cargo:rerun-if-changed=build.rs");
2+
println!("cargo::rerun-if-changed=build.rs");
3+
println!("cargo::rustc-check-cfg=cfg(windows_dll)");
34
if std::env::var_os("DEP_HDF5_MSVC_DLL_INDIRECTION").is_some() {
4-
println!("cargo:rustc-cfg=windows_dll");
5+
println!("cargo::rustc-cfg=windows_dll");
56
}
67
}

hdf5/build.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
11
use std::env;
22

3+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
4+
pub struct Version {
5+
pub major: u8,
6+
pub minor: u8,
7+
pub micro: u8,
8+
}
9+
10+
impl Version {
11+
pub const fn new(major: u8, minor: u8, micro: u8) -> Self {
12+
Self { major, minor, micro }
13+
}
14+
}
15+
16+
fn known_hdf5_versions() -> Vec<Version> {
17+
// Keep up to date with known_hdf5_versions in hdf5-sys
18+
let mut vs = Vec::new();
19+
vs.extend((5..=21).map(|v| Version::new(1, 8, v))); // 1.8.[5-23]
20+
vs.extend((0..=8).map(|v| Version::new(1, 10, v))); // 1.10.[0-10]
21+
vs.extend((0..=2).map(|v| Version::new(1, 12, v))); // 1.12.[0-2]
22+
vs.extend((0..=4).map(|v| Version::new(1, 14, v))); // 1.14.[0-4]
23+
vs
24+
}
25+
326
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);
27+
for version in known_hdf5_versions() {
28+
println!(
29+
"cargo::rustc-check-cfg=cfg(feature, values(\"{}.{}.{}\"))",
30+
version.major, version.minor, version.micro
31+
);
32+
}
33+
for feature in ["have-direct", "have-parallel", "have-threadsafe", "have-filter-deflate"] {
34+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"{feature}\"))");
35+
}
36+
println!("cargo::rustc-check-cfg=cfg(msvc_dll_indirection)");
37+
38+
let print_feature = |key: &str| println!("cargo::rustc-cfg=feature=\"{}\"", key);
39+
let print_cfg = |key: &str| println!("cargo::rustc-cfg={}", key);
640
for (key, _) in env::vars() {
741
match key.as_str() {
842
// public features

hdf5/src/hl/location.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub enum LocationType {
160160
Dataset,
161161
NamedDatatype,
162162
#[cfg(feature = "1.12.0")]
163-
#[cfg_attr(docrs, doc(cfg(feature = "1.12.0")))]
163+
#[cfg_attr(docsrs, doc(cfg(feature = "1.12.0")))]
164164
TypeMap,
165165
}
166166

0 commit comments

Comments
 (0)