Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source build on aarch64/homebrew #95

Merged
merged 2 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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