-
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
Made pg_config path configurable per-target. #18
Changes from all 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 |
---|---|---|
|
@@ -6,6 +6,8 @@ extern crate vcpkg; | |
|
||
use std::process::Command; | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
|
||
fn main() { | ||
println!("cargo:rerun-if-env-changed=PQ_LIB_DIR"); | ||
|
@@ -21,14 +23,7 @@ fn main() { | |
let path = replace_homebrew_path_on_mac(path); | ||
println!("cargo:rustc-link-search=native={}", path); | ||
} | ||
|
||
if cfg!(all(windows, target_env="msvc")) { | ||
println!("cargo:rustc-link-lib=dylib=libpq"); | ||
} else if env::var_os("PQ_LIB_STATIC").is_some() { | ||
println!("cargo:rustc-link-lib=static=pq"); | ||
} else { | ||
println!("cargo:rustc-link-lib=pq"); | ||
} | ||
static_or_not(); | ||
} | ||
|
||
#[cfg(feature = "pkg-config")] | ||
|
@@ -63,8 +58,56 @@ fn configured_by_vcpkg() -> bool { | |
false | ||
} | ||
|
||
fn static_or_not() { | ||
use std::ascii::AsciiExt; | ||
|
||
// On Windows-MSVC, always link dynamically | ||
if cfg!(all(windows, target_env="msvc")) { | ||
println!("cargo:rustc-link-lib=dylib=libpq"); | ||
return; | ||
} | ||
|
||
// Link unconditionally statically | ||
if env::var_os("PQ_LIB_STATIC").is_some() { | ||
println!("cargo:rustc-link-lib=static=pq"); | ||
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've noticed that I need to include the following when linking [dependencies]
# This is needed to make sure that Cargo statically links against
# `libssl`. This should happen automatically, but it doesn't.
openssl-sys = "0.9" Is there an underlying issue here with |
||
return; | ||
} | ||
|
||
// Examine the per-target env vars | ||
if let Ok(target) = env::var("TARGET") { | ||
let pg_config_for_target = format!("PQ_LIB_STATIC_{}", target.to_ascii_uppercase().replace("-", "_")); | ||
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 requires us adding a new println!("cargo:rerun-if-env-changed={}", pg_config_for_target); ...line somewhere in the script. Also, you probably mean |
||
if env::var_os(&pg_config_for_target).is_some() { | ||
println!("cargo:rustc-link-lib=static=pq"); | ||
return; | ||
} | ||
} | ||
|
||
// Otherwise, don't specify | ||
println!("cargo:rustc-link-lib=pq"); | ||
} | ||
|
||
fn pg_config_path() -> PathBuf { | ||
use std::ascii::AsciiExt; | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. This also requires something like: println!("cargo:rerun-if-env-changed={}", pg_config_for_target); It might be best to wrap |
||
if let Some(pg_config_path) = env::var_os(pg_config_for_target) { | ||
|
||
let path = PathBuf::from(&pg_config_path); | ||
|
||
if !path.exists() { | ||
panic!("pg_config doesn't exist in the configured path: {:?}", path); | ||
} | ||
|
||
return path; | ||
} | ||
} | ||
return PathBuf::from("pg_config"); | ||
} | ||
|
||
fn pg_config_output(command: &str) -> Option<String> { | ||
Command::new("pg_config") | ||
|
||
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. ✂️ 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. 👀 |
||
Command::new(pg_config_path()) | ||
.arg(command) | ||
.output() | ||
.ok() | ||
|
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.
This method name seems odd to me. It has side effects but implies it returns a boolean. Can we have it return a value instead? Perhaps a 3 state enum?