Skip to content
Closed
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
15 changes: 15 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ fn main() {

if let Ok(lib_dir) = env::var("PQ_LIB_DIR") {
println!("cargo:rustc-link-search=native={}", lib_dir);
emit_rpath(&lib_dir);
} else if configured_by_pkg_config() {
return // pkg_config does everything for us, including output for cargo
} else if configured_by_vcpkg() {
return // vcpkg does everything for us, including output for cargo
} else if let Some(path) = pg_config_output("--libdir") {
let path = replace_homebrew_path_on_mac(path);
println!("cargo:rustc-link-search=native={}", path);
emit_rpath(&path);
}
println!("cargo:rustc-link-lib={}", LinkingOptions::from_env());
}
Expand Down Expand Up @@ -127,6 +129,19 @@ fn configured_by_vcpkg() -> bool {
false
}

//
// When libpq comes from a location that's not on the runtime linker's default
// search path, setting RPATH on the built binary is required in order for libpq
// to be found at runtime. Many linkers support this with `-R/path/to/library`.
//
#[cfg(any(target_os = "illumos", target_os = "linux"))]
fn emit_rpath(lib_dir: &str) {
println!("cargo:rustc-link-arg=-Wl,-R{}", lib_dir);
}

#[cfg(not(any(target_os = "illumos", target_os = "linux")))]
fn emit_rpath(_: &str) {}

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("-", "_"));
Expand Down