use bindgen;
#[cfg(all(
not(feature = "pkg_config"),
feature = "bundled_proj",
not(feature = "nobuild")
))]
use cmake;
#[cfg(all(
not(feature = "pkg_config"),
feature = "bundled_proj",
not(feature = "nobuild")
))]
use flate2::read::GzDecoder;
#[cfg(all(
not(feature = "pkg_config"),
feature = "bundled_proj",
not(feature = "nobuild")
))]
use std::fs::File;
#[cfg(all(
feature = "pkg_config",
not(feature = "bundled_proj"),
not(feature = "nobuild")
))]
use pkg_config;
use std::env;
use std::path::PathBuf;
#[cfg(all(
not(feature = "pkg_config"),
feature = "bundled_proj",
not(feature = "nobuild")
))]
use tar::Archive;
#[cfg(all(
feature = "pkg_config",
not(feature = "bundled_proj"),
not(feature = "nobuild")
))]
const MINIMUM_PROJ_VERSION: &str = "7.0.1";
#[cfg(feature = "nobuild")]
fn main() {}
#[cfg(all(
feature = "pkg_config",
not(feature = "nobuild"),
not(feature = "bundled_proj")
))]
fn main() {
let pk = pkg_config::Config::new()
.atleast_version(MINIMUM_PROJ_VERSION)
.probe("proj")
.expect(&format!(
"Your PROJ version may be too old. You need at least version {}",
MINIMUM_PROJ_VERSION
));
println!("cargo:rustc-link-search=native={:?}", pk.link_paths[0]);
println!("cargo:rustc-link-lib=proj");
let include_path = pk.include_paths[0].to_string_lossy();
let bindings = bindgen::Builder::default()
.clang_arg(format!("-I{}", include_path))
.trust_clang_mangling(false)
.blacklist_type("max_align_t")
.header("wrapper.h")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
#[cfg(all(
not(feature = "pkg_config"),
not(feature = "nobuild"),
not(feature = "bundled_proj")
))]
fn main() {
println!("cargo:rustc-link-lib=proj");
let bindings = bindgen::Builder::default()
.trust_clang_mangling(false)
.blacklist_type("max_align_t")
.header("wrapper.h")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
#[cfg(all(
not(feature = "pkg-config"),
not(feature = "nobuild"),
feature = "bundled_proj"
))]
fn main() {
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
if &target_os != "linux" {
panic!(
"The bundled_proj feature currently only supports Linux, but Your target platform is {}",
target_os
);
}
let path = "PROJSRC/proj-7.0.1.tar.gz";
let tar_gz = File::open(path).expect("Couldn't open PROJ source tar");
let tar = GzDecoder::new(tar_gz);
let mut archive = Archive::new(tar);
archive.unpack("PROJSRC/proj").expect("Couldn't unpack tar");
let mut config = cmake::Config::new("PROJSRC/proj/proj-7.0.1");
let proj = config.build();
println!(
"cargo:rustc-link-search=native={}",
proj.join("lib").display()
);
println!("cargo:rustc-link-lib=dylib=proj");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindgen::builder()
.header(proj.join("include").join("proj.h").to_str().unwrap())
.trust_clang_mangling(false)
.blacklist_type("max_align_t")
.generate()
.expect("Unable to generate bindings")
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}