Skip to content

Commit

Permalink
Merge #95
Browse files Browse the repository at this point in the history
95: Fix source build on aarch64/homebrew r=urschrei a=michaelkirk

Slightly improves the situation at #57

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?)


This is a draft because some tests are currently failing for me on aarch64. I'm looking into it now...

<details>
<summary>failing test output</summary>
<pre>
geos: Invalid latitude
geos: Invalid latitude
"proj=pipeline step proj=unitconvert xy_in=us-ft xy_out=m step inv proj=lcc lat_0=32.1666666666667 lon_0=-116.25 lat_1=33.8833333333333 lat_2=32.7833333333333 x_0=2000000.0001016 y_0=500000.0001016 ellps=GRS80 step proj=lcc lat_0=32.1666666666667 lon_0=-116.25 lat_1=33.8833333333333 lat_2=32.7833333333333 x_0=2000000 y_0=500000 ellps=GRS80"
proj_create: unrecognized format / unknown name

assert_relative_eq!(t.x(), 0.43633200013698786)

    left  = NaN
    right = 0.43633200013698786


thread 'proj::test::test_inverse_projection' panicked at 'assert_relative_eq!(t.x(), 0.43633200013698786)

    left  = NaN
    right = 0.43633200013698786

', src/proj.rs:1069:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5
   1: std::panicking::begin_panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:460:5
   2: proj::proj::test::test_inverse_projection
             at ./src/proj.rs:1069:9
   3: proj::proj::test::test_inverse_projection::{{closure}}
             at ./src/proj.rs:1059:5
   4: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
   5: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


assert_relative_eq!(t.x(), 0.0023755864830313977)

    left  = NaN
    right = 0.0023755864830313977


thread 'proj::test::test_london_inverse' panicked at 'assert_relative_eq!(t.x(), 0.0023755864830313977)

    left  = NaN
    right = 0.0023755864830313977

', src/proj.rs:1086:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5
   1: std::panicking::begin_panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:460:5
   2: proj::proj::test::test_london_inverse
             at ./src/proj.rs:1086:9
   3: proj::proj::test::test_london_inverse::{{closure}}
             at ./src/proj.rs:1074:5
   4: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
   5: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


assert_relative_eq!(t.x(), 500119.7035366755, epsilon = 1e-5)

    left  = NaN
    right = 500119.7035366755


thread 'proj::test::test_projection' panicked at 'assert_relative_eq!(t.x(), 500119.7035366755, epsilon = 1e-5)

    left  = NaN
    right = 500119.7035366755

', src/proj.rs:1054:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5
   1: std::panicking::begin_panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:460:5
   2: proj::proj::test::test_projection
             at ./src/proj.rs:1054:9
   3: proj::proj::test::test_projection::{{closure}}
             at ./src/proj.rs:1044:5
   4: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
   5: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

thread 'proj::test::test_searchpath' panicked at 'assertion failed: `(left == right)`
  left: `"/Users/mkirk/src/georust/proj/target/debug/build/proj-sys-1e3a03028e94a7d6/out/share/proj"`,
 right: `"/foo"`', src/proj.rs:1016:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/panicking.rs:101:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/panicking.rs:140:5
   4: proj::proj::test::test_searchpath
             at ./src/proj.rs:1016:9
   5: proj::proj::test::test_searchpath::{{closure}}
             at ./src/proj.rs:1010:5
   6: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
</pre>
</details>

Co-authored-by: Michael Kirk <michael.code@endoftheworl.de>
  • Loading branch information
bors[bot] and michaelkirk authored Nov 29, 2021
2 parents b1fa08a + b0f4474 commit 5c1594f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions proj-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 46 additions & 2 deletions proj-sys/build.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -20,6 +20,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.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");
Expand Down Expand Up @@ -91,6 +98,16 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
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
Expand All @@ -105,6 +122,8 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
"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()
Expand All @@ -113,9 +132,34 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
"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") {
Expand Down

0 comments on commit 5c1594f

Please sign in to comment.