use std::env;
use std::ffi::OsString;
use std::path::Path;
use std::process::Command;
#[cfg(target_os = "macos")]
pub const DYLIB_PATH_VAR: &str = "DYLD_FALLBACK_LIBRARY_PATH";
#[cfg(target_os = "windows")]
pub const DYLIB_PATH_VAR: &str = "PATH";
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
pub const DYLIB_PATH_VAR: &str = "LD_LIBRARY_PATH";
pub fn prepend_dylib_path(command: &mut Command, dir: &Path) {
let mut entries = vec![OsString::from(dir)];
if let Some(existing) = env::var_os(DYLIB_PATH_VAR) {
entries.extend(env::split_paths(&existing).map(OsString::from));
}
let joined = env::join_paths(entries).expect("sysroot lib path contains an invalid character");
command.env(DYLIB_PATH_VAR, joined);
}