use std::path::PathBuf;
pub fn buildflags() {
if cfg!(target_os = "macos") {
println!("cargo:rustc-cdylib-link-arg=-undefined");
println!("cargo:rustc-cdylib-link-arg=dynamic_lookup");
} else if cfg!(target_os = "windows") {
println!("cargo:rustc-cdylib-link-arg=/FORCE");
}
}
pub fn cdylib_path() -> PathBuf {
let mut path = std::env::current_dir().unwrap();
path.push("target");
if cfg!(debug_assertions) {
path.push("debug");
} else {
path.push("release");
};
let pkgname = std::env::var("CARGO_PKG_NAME").unwrap();
path.push(pkgname_to_libname(&pkgname));
return path;
}
fn pkgname_to_libname(name: &str) -> String {
let libname = name.to_string().replace("-", "_");
if cfg!(target_os = "windows") {
format!("{}.dll", libname)
} else if cfg!(target_os = "macos") {
format!("lib{}.dylib", libname)
} else {
format!("lib{}.so", libname)
}
}
#[test]
fn cdylib_dir_exists() {
let mut path = cdylib_path();
path.pop();
assert!(std::fs::metadata(path).unwrap().is_dir());
}