diff --git a/Cargo.lock b/Cargo.lock index a74f2a8b..31584346 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,21 @@ dependencies = [ "cc", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anes" version = "0.1.6" @@ -129,12 +144,33 @@ version = "3.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" +[[package]] +name = "bytemuck" +version = "1.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbdf580320f38b612e485521afda1ee26d10cc9884efaaa750d383e13e3c5f4" + +[[package]] +name = "bytes" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" + [[package]] name = "cast" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" +[[package]] +name = "cbitset" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29b6ad25ae296159fb0da12b970b2fe179b234584d7cd294c891e2bbb284466b" +dependencies = [ + "num-traits", +] + [[package]] name = "cc" version = "1.2.24" @@ -159,6 +195,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.48.5", +] + [[package]] name = "ciborium" version = "0.2.2" @@ -252,6 +302,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "criterion" version = "0.8.1" @@ -343,12 +399,12 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -388,6 +444,7 @@ dependencies = [ "bindgen", "cmake", "pkg-config", + "rsfitsio", ] [[package]] @@ -433,6 +490,16 @@ version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" +[[package]] +name = "hcompress" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1b4a475971a05543118b8bcf8636f05240e9e57924ad2af462cd1628f77e37c" +dependencies = [ + "bytemuck", + "bytes", +] + [[package]] name = "heck" version = "0.5.0" @@ -445,6 +512,29 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "icu_collections" version = "2.0.0" @@ -619,11 +709,20 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "libbz2-rs-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c4a545a15244c7d945065b5d392b2d2d7f21526fba56ce51467b06ed445e8f7" +dependencies = [ + "libc", +] + [[package]] name = "libc" -version = "0.2.172" +version = "0.2.178" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" [[package]] name = "libloading" @@ -635,6 +734,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "libz-rs-sys" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c10501e7805cee23da17c7790e59df2870c0d4043ec6d03f67d31e2b53e77415" +dependencies = [ + "zlib-rs", +] + [[package]] name = "linux-raw-sys" version = "0.3.8" @@ -671,9 +779,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "minimal-lexical" @@ -776,6 +884,12 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "pliocomp" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1970c26a537573d5b864287a04df7f6e3aa0770577ebfa1a6a57b9f92eb35b" + [[package]] name = "plotters" version = "0.3.7" @@ -858,6 +972,16 @@ dependencies = [ "unicase", ] +[[package]] +name = "pwd" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c71c0c79b9701efe4e1e4b563b2016dd4ee789eb99badcb09d61ac4b92e4a2" +dependencies = [ + "libc", + "thiserror", +] + [[package]] name = "quote" version = "1.0.40" @@ -928,6 +1052,34 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "ricecomp" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "745d940d19d18efb7f7e47987adb6860a59fe595d868a469691bc2b181dc4883" + +[[package]] +name = "rsfitsio" +version = "0.462.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdbe688f6faa35781d16f1e5bd8a3cbf2af81f7a7129f3291ce073ef1f9188c" +dependencies = [ + "bytemuck", + "cbitset", + "chrono", + "errno", + "fastrand", + "hcompress", + "libbz2-rs-sys", + "libc", + "libz-rs-sys", + "memchr", + "pliocomp", + "pwd", + "ricecomp", + "tempfile", +] + [[package]] name = "rustc-hash" version = "2.1.1" @@ -1099,6 +1251,26 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "thiserror" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "tinystr" version = "0.8.1" @@ -1312,7 +1484,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] @@ -1321,6 +1493,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-link" version = "0.2.1" @@ -1584,3 +1765,9 @@ dependencies = [ "quote", "syn 2.0.101", ] + +[[package]] +name = "zlib-rs" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40990edd51aae2c2b6907af74ffb635029d5788228222c4bb811e9351c0caad3" diff --git a/fitsio-sys/Cargo.toml b/fitsio-sys/Cargo.toml index 63168a2b..ec2b3b9c 100644 --- a/fitsio-sys/Cargo.toml +++ b/fitsio-sys/Cargo.toml @@ -14,6 +14,7 @@ categories = ["external-ffi-bindings", "science"] links = "cfitsio" [dependencies] +rsfitsio = { version = "0.462.10", optional = true } [features] # Build, statically link, and use the vendored copy @@ -26,6 +27,9 @@ src-cmake = ["cmake"] # rather than use the manually-written bindings. # Untested; use at one's peril. with-bindgen = ["bindgen"] +# Use the pure-Rust `rsfitsio` crate as the provider of the CFITSIO-compatible C API. +# This backend avoids linking to a system-provided or vendored native `cfitsio` library. +backend-rsfitsio = ["dep:rsfitsio"] [build-dependencies] pkg-config = "0.3.16" diff --git a/fitsio-sys/build.rs b/fitsio-sys/build.rs index 06dcd857..96058aa5 100644 --- a/fitsio-sys/build.rs +++ b/fitsio-sys/build.rs @@ -29,8 +29,53 @@ fn generate_bindings<'p>(include_paths: impl Iterator) { } } -#[cfg(feature = "fitsio-src")] +fn write_default_aliases() { + let out_dir = env::var("OUT_DIR").expect("set by cargo"); + let out = PathBuf::from(out_dir).join("aliases.rs"); + match std::fs::copy("default-aliases.rs", &out) { + Ok(_) => (), + Err(e) => { + eprintln!( + "There was a problem attempting to copy from 'default-aliases.rs' to {out:?}" + ); + panic!("{}", e); + } + } +} + +fn ensure_feature_compatibility() { + if cfg!(feature = "backend-rsfitsio") { + if cfg!(feature = "fitsio-src") { + panic!("features `backend-rsfitsio` and `fitsio-src` are mutually exclusive"); + } + if cfg!(feature = "src-cmake") { + panic!( + "feature `src-cmake` requires `fitsio-src` and is not compatible with `backend-rsfitsio`" + ); + } + if cfg!(feature = "with-bindgen") { + panic!( + "feature `with-bindgen` is not supported with `backend-rsfitsio` (no native headers). Use the built-in bindings instead." + ); + } + } +} + fn main() { + ensure_feature_compatibility(); + + // Rust backend: the `rsfitsio` crate provides the CFITSIO-compatible C symbols. + // We must NOT attempt to probe/build/link a native `cfitsio` library here. + if cfg!(feature = "backend-rsfitsio") { + write_default_aliases(); + return; + } + + main_cfitsio(); +} + +#[cfg(feature = "fitsio-src")] +fn main_cfitsio() { #[cfg(not(feature = "src-cmake"))] use autotools::Config as AutoConfig; #[cfg(feature = "src-cmake")] @@ -101,7 +146,7 @@ fn main() { } #[cfg(not(feature = "fitsio-src"))] -fn main() { +fn main_cfitsio() { // `msys2` does not report the version of cfitsio correctly, so ignore the version specifier for now. let package_name = if cfg!(windows) { let msg = "No version specifier available for pkg-config on windows, so the version of cfitsio used when compiling this program is unspecified"; @@ -172,7 +217,7 @@ fn generate_aliases_mod_file<'p>(include_paths: impl Iterator(include_paths: impl Iterator(include_paths: impl Iterator