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", 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..8cb09733 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 { + /// 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) + } +} + +pub fn cfitsio_version() -> CfitsioVersion { + CfitsioVersion { + // 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, + } +} 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;