Skip to content

Commit 7f2361b

Browse files
committed
Emit check-cfg
1 parent 0e01290 commit 7f2361b

File tree

5 files changed

+98
-54
lines changed

5 files changed

+98
-54
lines changed

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]>",

hdf5-sys/build.rs

Lines changed: 57 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,69 @@ 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+
println!("cargo::rustc-check-cfg=cfg(hdf5_{}_{}_{})", v.major, v.minor, v.micro);
665+
}
666+
for v in known_hdf5_versions().into_iter().filter(|&v| version >= v) {
667+
println!("cargo::rustc-cfg=feature=\"{}.{}.{}\"", v.major, v.minor, v.micro);
668+
println!("cargo::metadata=version_{}_{}_{}=1", v.major, v.minor, v.micro);
666669
}
670+
671+
println!("cargo::rustc-check-cfg=cfg(have_stdbool_h)");
667672
if self.header.have_stdbool_h {
668-
println!("cargo:rustc-cfg=have_stdbool_h");
673+
println!("cargo::rustc-cfg=have_stdbool_h");
669674
// there should be no need to export have_stdbool_h downstream
670675
}
676+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"have-direct\"))");
671677
if self.header.have_direct {
672-
println!("cargo:rustc-cfg=feature=\"have-direct\"");
673-
println!("cargo:have_direct=1");
678+
println!("cargo::rustc-cfg=feature=\"have-direct\"");
679+
println!("cargo::metadata=have_direct=1");
674680
}
681+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"have-parallel\"))");
675682
if self.header.have_parallel {
676-
println!("cargo:rustc-cfg=feature=\"have-parallel\"");
677-
println!("cargo:have_parallel=1");
683+
println!("cargo::rustc-cfg=feature=\"have-parallel\"");
684+
println!("cargo::metadata=have_parallel=1");
678685
}
686+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"have-threadsafe\"))");
679687
if self.header.have_threadsafe {
680-
println!("cargo:rustc-cfg=feature=\"have-threadsafe\"");
681-
println!("cargo:have_threadsafe=1");
688+
println!("cargo::rustc-cfg=feature=\"have-threadsafe\"");
689+
println!("cargo::metadata=have_threadsafe=1");
682690
}
691+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"have-filter-deflate\"))");
683692
if self.header.have_filter_deflate {
684-
println!("cargo:rustc-cfg=feature=\"have-filter-deflate\"");
685-
println!("cargo:have_filter_deflate=1");
693+
println!("cargo::rustc-cfg=feature=\"have-filter-deflate\"");
694+
println!("cargo::metadata=have_filter_deflate=1");
686695
}
687696

688697
if cfg!(windows) && version >= Version::new(1, 14, 0) {
689-
println!("cargo:rustc-link-lib=shlwapi");
698+
println!("cargo::rustc-link-lib=shlwapi");
690699
}
691700
}
692701

@@ -721,31 +730,31 @@ fn main() {
721730
}
722731

723732
fn get_build_and_emit() {
724-
println!("cargo:rerun-if-changed=build.rs");
733+
println!("cargo::rerun-if-changed=build.rs");
725734

726735
if feature_enabled("ZLIB") {
727736
let zlib_lib = env::var("DEP_HDF5SRC_ZLIB").unwrap();
728-
println!("cargo:zlib={}", &zlib_lib);
737+
println!("cargo::metadata=zlib={}", &zlib_lib);
729738
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);
739+
println!("cargo::metadata=zlib={}", &zlib_lib_header);
740+
println!("cargo::rustc-link-lib=static={}", &zlib_lib);
732741
}
733742

734743
if feature_enabled("HL") {
735744
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);
745+
println!("cargo::rustc-link-lib=static={}", &hdf5_hl_lib);
746+
println!("cargo::metadata=hl_library={}", &hdf5_hl_lib);
738747
}
739748

740749
let hdf5_root = env::var("DEP_HDF5SRC_ROOT").unwrap();
741-
println!("cargo:root={}", &hdf5_root);
750+
println!("cargo::metadata=root={}", &hdf5_root);
742751
let hdf5_incdir = env::var("DEP_HDF5SRC_INCLUDE").unwrap();
743-
println!("cargo:include={}", &hdf5_incdir);
752+
println!("cargo::metadata=include={}", &hdf5_incdir);
744753
let hdf5_lib = env::var("DEP_HDF5SRC_LIBRARY").unwrap();
745-
println!("cargo:library={}", &hdf5_lib);
754+
println!("cargo::metadata=library={}", &hdf5_lib);
746755

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

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

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)