-
Notifications
You must be signed in to change notification settings - Fork 32
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -77,11 +77,30 @@ 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 | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is not performed for the "normal" There was a problem hiding this comment. Choose a reason for hiding this commentThe 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{ | ||||||||||||||||||||||||||||
use_general_lib_dir() | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the generalized version of
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still have to get used to more functional programming and not be as imperativ as I used to. Thanks for showing me that 👍 |
||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
else{ | ||||||||||||||||||||||||||||
use_general_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 | ||||||||||||||||||||||||||||
|
@@ -127,6 +146,19 @@ fn configured_by_vcpkg() -> bool { | |||||||||||||||||||||||||||
false | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
fn use_general_lib_dir() -> Result<String, VarError>{ | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would change this function in such a way that it accepts the name of a environment variable as input. This would enable reusing the same function for target specific variables as well and unify even more code there. |
||||||||||||||||||||||||||||
println!("cargo:rerun-if-env-changed=PQ_LIB_DIR"); | ||||||||||||||||||||||||||||
println!("PQ_LIB_DIR = {:?}", env::var("PQ_LIB_DIR")); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
let pq_lib_dir = env::var("PQ_LIB_DIR"); | ||||||||||||||||||||||||||||
if let Ok(pg_lib_path) = pq_lib_dir { | ||||||||||||||||||||||||||||
let path = PathBuf::from(&pg_lib_path); | ||||||||||||||||||||||||||||
if !path.exists() { | ||||||||||||||||||||||||||||
panic!("Folder {:?} doesn't exist in the configured path: {:?}", "PQ_LIB_DIR", path); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
fn pg_config_path() -> PathBuf { | ||||||||||||||||||||||||||||
if let Ok(target) = env::var("TARGET") { | ||||||||||||||||||||||||||||
let pg_config_for_target = &format!("PG_CONFIG_{}", target.to_ascii_uppercase().replace("-", "_")); | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be switched, as the current implementation prefers
PQ_LIB_DIR_{TARGET}
overPQ_LIB_DIR
(which is fine).