diff --git a/Cargo.toml b/Cargo.toml index 218a8671..c9761da4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ members = ["proj-sys"] default = ["geo-types"] bundled_proj = [ "proj-sys/bundled_proj" ] pkg_config = [ "proj-sys/pkg_config" ] -network = ["reqwest"] +network = ["reqwest", "proj-sys/network"] [dev-dependencies] approx = "0.3" diff --git a/proj-sys/Cargo.toml b/proj-sys/Cargo.toml index 024686a7..2f17bbf7 100644 --- a/proj-sys/Cargo.toml +++ b/proj-sys/Cargo.toml @@ -24,6 +24,7 @@ nobuild = [] bundled_proj = [] # `pkg_config` feature is deprecated and does nothing pkg_config = [] +network = [] [package.metadata.docs.rs] features = [ "nobuild" ] # This feature will be enabled during the docs.rs build diff --git a/proj-sys/build.rs b/proj-sys/build.rs index 05af87ce..d8ac4df1 100644 --- a/proj-sys/build.rs +++ b/proj-sys/build.rs @@ -1,6 +1,6 @@ use flate2::read::GzDecoder; -use std::fs::File; use std::env; +use std::fs::File; use std::path::PathBuf; use tar::Archive; @@ -20,6 +20,13 @@ fn main() -> Result<(), Box> { .probe("proj") .map(|pk| { eprintln!("found acceptable libproj already installed at: {:?}", pk.link_paths[0]); + if cfg!(feature = "network") { + // Generally, system proj installations have been built with tiff support + // allowing for network grid interaction. If this proves to be untrue + // could we try to determine some kind of runtime check and fall back + // to building from source? + eprintln!("assuming existing system libproj installation has network (tiff) support"); + } if let Ok(val) = &env::var("_PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC") { if val != "0" { panic!("for testing purposes: existing package was found, but should not have been"); @@ -91,6 +98,16 @@ fn build_from_source() -> Result> config.define("BUILD_PROJINFO", "OFF"); config.define("BUILD_PROJSYNC", "OFF"); config.define("ENABLE_CURL", "OFF"); + + let enable_tiff = cfg!(feature="network"); + if enable_tiff { + eprintln!("enabling tiff support"); + config.define("ENABLE_TIFF", "ON"); + } else { + eprintln!("disabling tiff support"); + config.define("ENABLE_TIFF", "OFF"); + } + let proj = config.build(); // Tell cargo to tell rustc to link libproj, and where to find it // libproj will be built in $OUT_DIR/lib @@ -105,6 +122,8 @@ fn build_from_source() -> Result> "cargo:rustc-link-search=native={}", proj.join("lib").display() ); + + // This is producing a warning - this directory doesn't exist (on aarch64 anyway) println!( "cargo:rustc-link-search={}", &out_path.join("lib64").display() @@ -113,9 +132,34 @@ fn build_from_source() -> Result> "cargo:rustc-link-search={}", &out_path.join("build/lib").display() ); + // The PROJ library needs SQLite and the C++ standard library. println!("cargo:rustc-link-lib=dylib=sqlite3"); - println!("cargo:rustc-link-lib=dylib=tiff"); + + if enable_tiff { + // On platforms like apples aarch64, users are likely to have installed libtiff with homebrew, + // which isn't in the default search path, so try to determine path from pkg-config + match pkg_config::Config::new() + .atleast_version("4.0") + .probe("libtiff-4") + { + Ok(pk) => { + eprintln!( + "found acceptable libtiff installed at: {:?}", + pk.link_paths[0] + ); + println!("cargo:rustc-link-search=native={:?}", pk.link_paths[0]); + } + Err(err) => { + // pkg-config might not even be installed. Let's try to stumble forward + // to see if the build succeeds regardless, e.g. if libtiff is installed + // in some default search path. + eprintln!("Failed to find libtiff with pkg-config: {}", err); + } + } + println!("cargo:rustc-link-lib=dylib=tiff"); + } + if cfg!(target_os = "linux") { println!("cargo:rustc-link-lib=dylib=stdc++"); } else if cfg!(target_os = "macos") {