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

Make cross-compilation possible #40

Merged
merged 4 commits into from
Jun 17, 2022
Merged
Changes from 2 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
27 changes: 25 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,34 @@ impl Display for LinkingOptions {
}

fn main() {
println!("cargo:rerun-if-env-changed=PQ_LIB_DIR");
println!("cargo:rerun-if-env-changed=PQ_LIB_STATIC");
println!("cargo:rerun-if-env-changed=TARGET");

if let Ok(lib_dir) = env::var("PQ_LIB_DIR") {
// if target is specified the more concrete pq_lib_dir overwrites a more general one
let lib_dir = if let Ok(target) = env::var("TARGET") {
let pq_lib_dir_for_target = format!("PQ_LIB_DIR_{}", target.to_ascii_uppercase().replace("-", "_"));
println!("cargo:rerun-if-env-changed={}", pq_lib_dir_for_target);
if let Ok(pg_lib_path) = env::var(pq_lib_dir_for_target.clone()) {
let path = PathBuf::from(&pg_lib_path);
if !path.exists() {
panic!("Folder {:?} doesn't exist in the configured path: {:?}", pq_lib_dir_for_target, path);
}
println!("{:?} = {:?}", pq_lib_dir_for_target, pg_lib_path); // list in output for small debuggability
Copy link
Collaborator

Choose a reason for hiding this comment

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

This check is not performed for the "normal" PQ_LIB_DIR variable at all. Either we need to change that there or remove it from here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to the "normal" variable as well. As I find it to be good practice to give as many hints as possible as to why something fails.

Ok(pg_lib_path)
}
else{
println!("cargo:rerun-if-env-changed=PQ_LIB_DIR");
println!("PQ_LIB_DIR = {:?}", env::var("PQ_LIB_DIR"));
env::var("PQ_LIB_DIR")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to unify this block with that one below as they are identical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored it into a function

}
}
else{
println!("cargo:rerun-if-env-changed=PQ_LIB_DIR");
println!("PQ_LIB_DIR = {:?}", env::var("PQ_LIB_DIR"));
env::var("PQ_LIB_DIR")
};

if let Ok(lib_dir) = lib_dir {
println!("cargo:rustc-link-search=native={}", lib_dir);
} else if configured_by_pkg_config() {
return // pkg_config does everything for us, including output for cargo
Expand Down