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
Changes from 1 commit
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
27 changes: 26 additions & 1 deletion 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 Down Expand Up @@ -105,6 +105,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 +115,32 @@ 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");

// 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");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having second thoughts about some of my changes in 9aca22c 😬

Assuming that the system proj has tiff was a nice way to avoid building from src in more circumstances, but we're now also requiring libtiff whenever building from source.

With a little work we might be able to accommodate all these cases...

Copy link
Member Author

@michaelkirk michaelkirk Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After typing it out, I was motivated to just address this. With b0f4474 we only require tiff when using the network feature, which I've now forwarded from proj to proj/sys.

It's almost like the old bunled_proj_tiff, except that we'll still allow a system proj to satisfy the requirement, assuming that it has tiff support.

We could add some kind of check to build.rs to make sure the linked libproj supports tiff, but I'm inclined to wait and see if it's actually a problem.

If we wanted to require pkg-config, one (not very impressive) approach would be parsing the output of pkg-config --libs --static proj for libtiff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, kornel's Rust -sys library guide notes that pkg-config can be quite fussy. Homebrew's proj installs pkg-config but of course we can't make that assumption w/r/t/ Linux, so if we can do without it that's great.


if cfg!(target_os = "linux") {
println!("cargo:rustc-link-lib=dylib=stdc++");
} else if cfg!(target_os = "macos") {
Expand Down