From c4970e356f0ac65a9a7407bead13c5801c33eb66 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 19 Nov 2021 12:51:01 -0800 Subject: [PATCH 1/2] Fix source build on aarch64/homebrew On apple platforms, libtiff is not installed by the operating system. If the user has it installed, likely it was installed by homebrew. Previously, on x86, homebrew installed libs into /usr/lib which is in the default search path, but since aarch64, homebrew has moved libs to /opt/homebrew/lib. So now we use pkg-config to find the library. Potential problems: - Not everyone has pkg-config (e.g windows users, a few mac users) - Not everyone actually needs libtiff, only the network geotiff users, but we assume everyone needs it since most system installations include it. Note that proj enables tiff support by defeault, provided libtiff is found (using pkg-config? or something else?) --- proj-sys/build.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/proj-sys/build.rs b/proj-sys/build.rs index 05af87ce..5bca2ffe 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; @@ -105,6 +105,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 +115,32 @@ 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"); + + // 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") { From b0f447446d07cadc2da86d6be3d37eb35c3620d6 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 29 Nov 2021 12:07:53 -0800 Subject: [PATCH 2/2] only require tiff for source builds when network feature is enabled --- Cargo.toml | 2 +- proj-sys/Cargo.toml | 1 + proj-sys/build.rs | 57 ++++++++++++++++++++++++++++++--------------- 3 files changed, 40 insertions(+), 20 deletions(-) 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 5bca2ffe..d8ac4df1 100644 --- a/proj-sys/build.rs +++ b/proj-sys/build.rs @@ -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 @@ -119,27 +136,29 @@ fn build_from_source() -> Result> // The PROJ library needs SQLite and the C++ standard library. println!("cargo:rustc-link-lib=dylib=sqlite3"); - // 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); + 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"); } - println!("cargo:rustc-link-lib=dylib=tiff"); if cfg!(target_os = "linux") { println!("cargo:rustc-link-lib=dylib=stdc++");