fn main() {
let mut build = cc::Build::new();
#[cfg(target_os = "macos")]
{
if let Ok(llvm_path) = std::env::var("HOMEBREW_PREFIX") {
let llvm_bin = format!("{}/opt/llvm/bin/clang", llvm_path);
if std::path::Path::new(&llvm_bin).exists() {
build.compiler(&llvm_bin);
println!("cargo:rustc-link-search={}/opt/llvm/lib", llvm_path);
}
} else {
for prefix in &["/opt/homebrew", "/usr/local"] {
let llvm_bin = format!("{}/opt/llvm/bin/clang", prefix);
if std::path::Path::new(&llvm_bin).exists() {
build.compiler(&llvm_bin);
println!("cargo:rustc-link-search={}/opt/llvm/lib", prefix);
break;
}
}
}
}
let zlib = pkg_config::Config::new().probe("zlib").ok();
let lz4 = pkg_config::Config::new().probe("liblz4").ok();
let zstd = pkg_config::Config::new().probe("libzstd").ok();
build
.file("c_src/fits_processor.c")
.file("c_src/fits_reader.c")
.file("c_src/jpeg_writer.c")
.file("c_src/xisf_reader.c")
.file("c_src/base64.c")
.include("c_src")
.opt_level(3);
let is_msvc = build.get_compiler().is_like_msvc();
if is_msvc {
build.flag("/fp:fast"); build.flag("/Oy"); } else {
build.flag("-ffast-math"); build.flag("-ftree-vectorize"); build.flag("-funroll-loops"); build.flag("-fomit-frame-pointer");
if std::env::var("RUSTAFITS_PORTABLE").is_err() {
build.flag("-march=native"); build.flag("-mtune=native"); }
}
build.warnings(false);
if let Some(ref z) = zlib {
for path in &z.include_paths {
build.include(path);
}
}
if let Some(ref l) = lz4 {
for path in &l.include_paths {
build.include(path);
}
}
if let Some(ref z) = zstd {
for path in &z.include_paths {
build.include(path);
}
}
build.compile("fits_processor");
#[cfg(not(target_os = "windows"))]
println!("cargo:rustc-link-lib=m");
if zlib.is_none() {
println!("cargo:rustc-link-lib=z"); }
if lz4.is_none() {
println!("cargo:rustc-link-lib=lz4"); }
if zstd.is_none() {
println!("cargo:rustc-link-lib=zstd"); }
println!("cargo:rerun-if-changed=c_src/compat.h");
println!("cargo:rerun-if-changed=c_src/fits_processor.c");
println!("cargo:rerun-if-changed=c_src/fits_processor.h");
println!("cargo:rerun-if-changed=c_src/fits_reader.c");
println!("cargo:rerun-if-changed=c_src/fits_reader.h");
println!("cargo:rerun-if-changed=c_src/jpeg_writer.c");
println!("cargo:rerun-if-changed=c_src/xisf_reader.c");
println!("cargo:rerun-if-changed=c_src/xisf_reader.h");
println!("cargo:rerun-if-changed=c_src/base64.c");
}