Skip to content

Commit 5c1594f

Browse files
Merge #95
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 <[email protected]>
2 parents b1fa08a + b0f4474 commit 5c1594f

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ members = ["proj-sys"]
2727
default = ["geo-types"]
2828
bundled_proj = [ "proj-sys/bundled_proj" ]
2929
pkg_config = [ "proj-sys/pkg_config" ]
30-
network = ["reqwest"]
30+
network = ["reqwest", "proj-sys/network"]
3131

3232
[dev-dependencies]
3333
approx = "0.3"

proj-sys/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ nobuild = []
2424
bundled_proj = []
2525
# `pkg_config` feature is deprecated and does nothing
2626
pkg_config = []
27+
network = []
2728

2829
[package.metadata.docs.rs]
2930
features = [ "nobuild" ] # This feature will be enabled during the docs.rs build

proj-sys/build.rs

+46-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use flate2::read::GzDecoder;
2-
use std::fs::File;
32
use std::env;
3+
use std::fs::File;
44
use std::path::PathBuf;
55
use tar::Archive;
66

@@ -20,6 +20,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2020
.probe("proj")
2121
.map(|pk| {
2222
eprintln!("found acceptable libproj already installed at: {:?}", pk.link_paths[0]);
23+
if cfg!(feature = "network") {
24+
// Generally, system proj installations have been built with tiff support
25+
// allowing for network grid interaction. If this proves to be untrue
26+
// could we try to determine some kind of runtime check and fall back
27+
// to building from source?
28+
eprintln!("assuming existing system libproj installation has network (tiff) support");
29+
}
2330
if let Ok(val) = &env::var("_PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC") {
2431
if val != "0" {
2532
panic!("for testing purposes: existing package was found, but should not have been");
@@ -91,6 +98,16 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
9198
config.define("BUILD_PROJINFO", "OFF");
9299
config.define("BUILD_PROJSYNC", "OFF");
93100
config.define("ENABLE_CURL", "OFF");
101+
102+
let enable_tiff = cfg!(feature="network");
103+
if enable_tiff {
104+
eprintln!("enabling tiff support");
105+
config.define("ENABLE_TIFF", "ON");
106+
} else {
107+
eprintln!("disabling tiff support");
108+
config.define("ENABLE_TIFF", "OFF");
109+
}
110+
94111
let proj = config.build();
95112
// Tell cargo to tell rustc to link libproj, and where to find it
96113
// libproj will be built in $OUT_DIR/lib
@@ -105,6 +122,8 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
105122
"cargo:rustc-link-search=native={}",
106123
proj.join("lib").display()
107124
);
125+
126+
// This is producing a warning - this directory doesn't exist (on aarch64 anyway)
108127
println!(
109128
"cargo:rustc-link-search={}",
110129
&out_path.join("lib64").display()
@@ -113,9 +132,34 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
113132
"cargo:rustc-link-search={}",
114133
&out_path.join("build/lib").display()
115134
);
135+
116136
// The PROJ library needs SQLite and the C++ standard library.
117137
println!("cargo:rustc-link-lib=dylib=sqlite3");
118-
println!("cargo:rustc-link-lib=dylib=tiff");
138+
139+
if enable_tiff {
140+
// On platforms like apples aarch64, users are likely to have installed libtiff with homebrew,
141+
// which isn't in the default search path, so try to determine path from pkg-config
142+
match pkg_config::Config::new()
143+
.atleast_version("4.0")
144+
.probe("libtiff-4")
145+
{
146+
Ok(pk) => {
147+
eprintln!(
148+
"found acceptable libtiff installed at: {:?}",
149+
pk.link_paths[0]
150+
);
151+
println!("cargo:rustc-link-search=native={:?}", pk.link_paths[0]);
152+
}
153+
Err(err) => {
154+
// pkg-config might not even be installed. Let's try to stumble forward
155+
// to see if the build succeeds regardless, e.g. if libtiff is installed
156+
// in some default search path.
157+
eprintln!("Failed to find libtiff with pkg-config: {}", err);
158+
}
159+
}
160+
println!("cargo:rustc-link-lib=dylib=tiff");
161+
}
162+
119163
if cfg!(target_os = "linux") {
120164
println!("cargo:rustc-link-lib=dylib=stdc++");
121165
} else if cfg!(target_os = "macos") {

0 commit comments

Comments
 (0)