From ceb199a627b598fda40f7a22a491bf986ac97c51 Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Mon, 30 Dec 2024 17:49:15 +0000 Subject: [PATCH 1/3] Include function to get cfitsio version Note: currently only works on cfitsio >= v4.0.0 since versions previous to this don't include the `CFITSIO_MICRO` symbol used in this function. TODO: update this --- fitsio-sys/examples/print_version.rs | 5 +++++ fitsio-sys/src/lib.rs | 26 ++++++++++++++++++++++++++ fitsio/src/lib.rs | 3 +++ 3 files changed, 34 insertions(+) create mode 100644 fitsio-sys/examples/print_version.rs diff --git a/fitsio-sys/examples/print_version.rs b/fitsio-sys/examples/print_version.rs new file mode 100644 index 00000000..0b594d09 --- /dev/null +++ b/fitsio-sys/examples/print_version.rs @@ -0,0 +1,5 @@ +use fitsio_sys::cfitsio_version; + +fn main() { + println!("cfitsio version: {}", cfitsio_version()); +} diff --git a/fitsio-sys/src/lib.rs b/fitsio-sys/src/lib.rs index ed931e7d..da71d6cf 100644 --- a/fitsio-sys/src/lib.rs +++ b/fitsio-sys/src/lib.rs @@ -98,3 +98,29 @@ mod sys { } pub use sys::*; + +// global functions + +/// Representation of the version of cfitsio used within bindings +pub struct CfitsioVersion { + /// Patch version + pub patch: u32, + /// Minor version + pub minor: u32, + /// Major version + pub major: u32, +} + +impl std::fmt::Display for CfitsioVersion { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}.{}.{}", self.major, self.minor, self.patch) + } +} + +pub fn cfitsio_version() -> CfitsioVersion { + CfitsioVersion { + patch: CFITSIO_MICRO, + minor: CFITSIO_MINOR, + major: CFITSIO_MAJOR, + } +} diff --git a/fitsio/src/lib.rs b/fitsio/src/lib.rs index 35f05b94..93d3ce16 100644 --- a/fitsio/src/lib.rs +++ b/fitsio/src/lib.rs @@ -1049,6 +1049,9 @@ let _hdu = t.hdu(hdu_num).unwrap(); pub use fitsio_sys as sys; +// re-export version information +pub use sys::{cfitsio_version, CfitsioVersion}; + #[macro_use] mod macros; mod fitsfile; From 76eb6b92d0c7dd2c24d998d5696846259c545da1 Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Tue, 31 Dec 2024 23:09:04 +0000 Subject: [PATCH 2/3] Don't use patch version --- fitsio-sys/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fitsio-sys/src/lib.rs b/fitsio-sys/src/lib.rs index da71d6cf..8cb09733 100644 --- a/fitsio-sys/src/lib.rs +++ b/fitsio-sys/src/lib.rs @@ -103,8 +103,6 @@ pub use sys::*; /// Representation of the version of cfitsio used within bindings pub struct CfitsioVersion { - /// Patch version - pub patch: u32, /// Minor version pub minor: u32, /// Major version @@ -113,13 +111,15 @@ pub struct CfitsioVersion { impl std::fmt::Display for CfitsioVersion { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}.{}.{}", self.major, self.minor, self.patch) + write!(f, "{}.{}", self.major, self.minor) } } pub fn cfitsio_version() -> CfitsioVersion { CfitsioVersion { - patch: CFITSIO_MICRO, + // TODO: we need to detect the version of cfitsio we are binding to. Version >=4 supports + // this field, but earlier versions don't. + // patch: CFITSIO_MICRO, minor: CFITSIO_MINOR, major: CFITSIO_MAJOR, } From 1001232191e644c0f46f583de6ac58dd5127ec83 Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Tue, 31 Dec 2024 23:19:36 +0000 Subject: [PATCH 3/3] Add pre-command for printing cfitsio version This is mostly useful for CI --- bin/test | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bin/test b/bin/test index 2da962dd..64295042 100755 --- a/bin/test +++ b/bin/test @@ -52,7 +52,17 @@ class TestRunner: sys.exit(e.returncode) print() + def _print_cfitsio_version_with_features(self, *features: str, default_features: bool = True): + cmd = ["cargo", "run", "--package", "fitsio-sys", "--example", "print_version"] + for feature in features: + cmd.extend(["--features", feature]) + if not default_features: + cmd.append("--no-default-features") + print(f"Running {' '.join(cmd)}") + sp.check_call(cmd) + def _run_test_workspace(self): + self._print_cfitsio_version_with_features() self._run_cargo("test", "--locked", "--", "--test-threads", "1") def _run_test_clippy(self, extra_clippy_flags: str): @@ -75,6 +85,7 @@ class TestRunner: self._run_cargo("test", "--locked", "--manifest-path", "fitsio/Cargo.toml", "--features", "array", "--", "--test-threads", "1") def _run_test_fitsio_src(self): + self._print_cfitsio_version_with_features("fitsio-src") self._run_cargo( "test", "--locked", @@ -88,6 +99,7 @@ class TestRunner: ) def _run_test_fitsio_src_and_bindgen(self): + self._print_cfitsio_version_with_features("fitsio-src", "with-bindgen") self._run_cargo( "test", "--locked", @@ -103,6 +115,7 @@ class TestRunner: ) def _run_test_bindgen(self): + self._print_cfitsio_version_with_features("with-bindgen", default_features=False) self._run_cargo( "test", "--locked",