From 36643387f68909ea2af79a351b08691f665c5236 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 13 Jan 2025 14:45:32 +0100 Subject: [PATCH 1/4] Emit version as a build constant --- hdf5-sys/build.rs | 24 ++++++++++++++++++++++++ hdf5-sys/src/lib.rs | 2 ++ hdf5/src/lib.rs | 2 ++ 3 files changed, 28 insertions(+) diff --git a/hdf5-sys/build.rs b/hdf5-sys/build.rs index 7725afcd..142b1df9 100644 --- a/hdf5-sys/build.rs +++ b/hdf5-sys/build.rs @@ -6,6 +6,7 @@ use std::env; use std::error::Error; use std::fmt::{self, Debug}; use std::fs; +use std::io::Write; use std::os::raw::{c_int, c_uint}; use std::path::{Path, PathBuf}; use std::process::Command; @@ -725,6 +726,7 @@ fn main() { println!("{:#?}", config); config.emit_link_flags(); config.emit_cfg_flags(); + write_hdf5_version(config.header.version); } } @@ -755,4 +757,26 @@ fn get_build_and_emit() { let header = Header::parse(&hdf5_incdir); let config = Config { header, inc_dir: "".into(), link_paths: Vec::new() }; config.emit_cfg_flags(); + write_hdf5_version(header.version); +} + +fn write_hdf5_version(version: Version) { + let out_dir = std::env::var("OUT_DIR").unwrap(); + let destination = std::path::Path::new(&out_dir).join("version.rs"); + let mut f = std::fs::File::create(destination).unwrap(); + let (major, minor, micro) = (version.major, version.minor, version.micro); + let string = format!( + " + #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] + pub struct Version {{ + pub major: u8, + pub minor: u8, + pub micro: u8, + }} + + /// HDF5 library version used at link time ({major}.{minor}.{micro}) + pub const HDF5_VERSION: Version = Version {{ major: {major}, minor: {minor}, micro: {micro} }}; + " + ); + f.write_all(string.as_bytes()).unwrap(); } diff --git a/hdf5-sys/src/lib.rs b/hdf5-sys/src/lib.rs index 867bb14c..7e0beb4b 100644 --- a/hdf5-sys/src/lib.rs +++ b/hdf5-sys/src/lib.rs @@ -76,6 +76,8 @@ use parking_lot::ReentrantMutex; /// Lock which can be used to serialise access to the hdf5 library pub static LOCK: ReentrantMutex<()> = ReentrantMutex::new(()); +include!(concat!(env!("OUT_DIR"), "/version.rs")); + #[cfg(test)] mod tests { use super::h5::H5open; diff --git a/hdf5/src/lib.rs b/hdf5/src/lib.rs index 12a1192b..ca1bc71f 100644 --- a/hdf5/src/lib.rs +++ b/hdf5/src/lib.rs @@ -206,6 +206,8 @@ pub fn is_library_threadsafe() -> bool { } } +pub const HDF5_VERSION: hdf5_sys::Version = hdf5_sys::HDF5_VERSION; + #[cfg(test)] pub mod tests { use crate::library_version; From 4177e0c691133a19be798b10854808a02decf30e Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 13 Jan 2025 17:26:10 +0100 Subject: [PATCH 2/4] Add doc comment on hdf5::HDF5_VERSION --- hdf5/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/hdf5/src/lib.rs b/hdf5/src/lib.rs index ca1bc71f..34e0eaf2 100644 --- a/hdf5/src/lib.rs +++ b/hdf5/src/lib.rs @@ -206,6 +206,7 @@ pub fn is_library_threadsafe() -> bool { } } +/// HDF5 library version used at link time. See [`hdf5_sys::HDF5_VERSION`] pub const HDF5_VERSION: hdf5_sys::Version = hdf5_sys::HDF5_VERSION; #[cfg(test)] From c61b7b13dfbe89128c8aa0156d14506cd3884538 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 13 Jan 2025 17:40:45 +0100 Subject: [PATCH 3/4] Add test for library version --- hdf5-sys/src/lib.rs | 13 +++++++++++++ hdf5/src/lib.rs | 12 +++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/hdf5-sys/src/lib.rs b/hdf5-sys/src/lib.rs index 7e0beb4b..e02192b7 100644 --- a/hdf5-sys/src/lib.rs +++ b/hdf5-sys/src/lib.rs @@ -80,11 +80,24 @@ include!(concat!(env!("OUT_DIR"), "/version.rs")); #[cfg(test)] mod tests { + use super::h5::H5get_libversion; use super::h5::H5open; use super::h5p::H5P_CLS_ROOT; + use super::{Version, HDF5_VERSION, LOCK}; + + #[test] + fn version_test() { + let _lock = LOCK.lock(); + let (mut major, mut minor, mut micro) = (0, 0, 0); + unsafe { H5get_libversion(&mut major, &mut minor, &mut micro) }; + let runtime_version = Version { major: major as _, minor: minor as _, micro: micro as _ }; + + assert_eq!(runtime_version, HDF5_VERSION); + } #[test] pub fn test_smoke() { + let _lock = LOCK.lock(); unsafe { H5open(); assert!(*H5P_CLS_ROOT > 0); diff --git a/hdf5/src/lib.rs b/hdf5/src/lib.rs index 34e0eaf2..34d283eb 100644 --- a/hdf5/src/lib.rs +++ b/hdf5/src/lib.rs @@ -212,9 +212,19 @@ pub const HDF5_VERSION: hdf5_sys::Version = hdf5_sys::HDF5_VERSION; #[cfg(test)] pub mod tests { use crate::library_version; + use crate::HDF5_VERSION; #[test] - pub fn test_library_version() { + pub fn test_minimum_library_version() { assert!(library_version() >= (1, 8, 4)); } + + #[test] + fn library_version_eq_compile_version() { + use hdf5_sys::Version; + let (major, minor, micro) = library_version(); + let runtime_version = Version { major, minor, micro }; + + assert_eq!(runtime_version, HDF5_VERSION); + } } From ee9511b1a62baccfaea22cc5ad1b759d34368854 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 13 Jan 2025 17:57:23 +0100 Subject: [PATCH 4/4] Added to changelog --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6323557..0a0235d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,13 @@ ## hdf5-sys unreleased ## hdf5-src unreleased -## hdf5 unreleased v0.9.4 +## hdf5 unreleased +- Added `HDF5_VERSION` which contains the version used when building + +## hdf5-sys unreleased +- Added `HDF5_VERSION` which contains the version used when building + +## hdf5 v0.9.4 Release date: Jan 7, 2025. - Fixed bundled hdf5 version back to 1.14.5