diff --git a/Cargo.toml b/Cargo.toml index 1cbdc84..c9cbbea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mwalib" -version = "0.4.1" +version = "0.4.2" homepage = "https://github.com/MWATelescope/mwalib" authors = ["Greg Sleap ", "Christopher H. Jordan "] diff --git a/README.md b/README.md index b746d54..1b64f6c 100644 --- a/README.md +++ b/README.md @@ -77,8 +77,8 @@ You can build mwalib from source: `cargo build --release` -- MWALIB_LINK_STATIC_CFITSIO environment variable - If this environment variable exists and is set to a non-zero value, rustc will statically link libcfitsio. If the environment variable does not exist or is 0, rustc will dynamically link libcfitsio. This is an attempt to give developers the choice of having a static or dynamic link of the fits library to ease the build and deploy process. +- Statically-linking cfitsio + If any of the MWALIB_LINK_STATIC_CFITSIO, STATIC_CFITSIO or PKG_CONFIG_ALL_STATIC environment variables exist and are set to a non-zero value, rustc will statically link libcfitsio. The default is to dynamically link libcfitsio. This is an attempt to give developers the choice of having a static or dynamic link of the fits library to ease the build and deploy process. - Use the dynamic-shared and/or static objects in the `target/release` directory diff --git a/build.rs b/build.rs index 8fa573a..21f4bc5 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,22 @@ use std::env; +// This code is adapted from pkg-config-rs +// (https://github.com/rust-lang/pkg-config-rs). +fn infer_static(name: &str) -> bool { + #[allow(clippy::if_same_then_else, clippy::needless_bool)] + if env::var(&format!("{}_STATIC", name.to_uppercase())).is_ok() { + true + } else if env::var(&format!("{}_DYNAMIC", name.to_uppercase())).is_ok() { + false + } else if env::var("PKG_CONFIG_ALL_STATIC").is_ok() { + true + } else if env::var("PKG_CONFIG_ALL_DYNAMIC").is_ok() { + false + } else { + false + } +} + fn main() { // // Link to shared or static CFITSIO @@ -11,10 +28,7 @@ fn main() { // AND // 2. libcfitsio.a needs to have been built with the following ./configure statement: // ./configure --disable-curl --prefix=/usr/local --enable-reentrant - if let Ok(val) = env::var("MWALIB_LINK_STATIC_CFITSIO") { - match val.as_str() { - "0" => (), - _ => println!("cargo:rustc-link-lib=static=cfitsio"), - } + if env::var("MWALIB_LINK_STATIC_CFITSIO") == Ok("1".to_string()) || infer_static("cfitsio") { + println!("cargo:rustc-link-lib=static=cfitsio"); } } diff --git a/src/lib.rs b/src/lib.rs index b48aaff..3e9bb62 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,3 +32,7 @@ pub use context::{mwalibContext, CorrelatorVersion}; pub use error::MwalibError; pub use fits_read::*; pub use rfinput::*; + +// So that callers don't use a different version of fitsio, export them here. +pub use fitsio; +pub use fitsio_sys;