use std::path::Path;
use std::{fs, io};
#[cfg(not(feature = "docsrs"))]
fn main() {
let lib_src = std::env::current_dir().unwrap().join("target/vzense-lib");
if !lib_src.exists() {
std::fs::copy("vzense-lib.tar.xz", "target/vzense-lib.tar.xz")
.expect("could not copy vzense-lib");
std::process::Command::new("unxz")
.current_dir("target/")
.arg("vzense-lib.tar.xz")
.output()
.expect("could not unxz vzense-lib");
std::process::Command::new("tar")
.current_dir("target/")
.arg("-xf")
.arg("vzense-lib.tar")
.output()
.expect("could not untar vzense-lib");
std::process::Command::new("rm")
.current_dir("target/")
.arg("vzense-lib.tar")
.output()
.unwrap();
}
let mut deps_path = std::env::current_exe().unwrap();
for _ in 0..3 {
deps_path.pop(); }
deps_path.push("deps");
symlink_dir_all(lib_src, deps_path.clone()).expect("failed to create symlinks to libraries");
println!("cargo:rustc-link-search={}", deps_path.to_str().unwrap());
println!(
"cargo:rustc-link-arg=-Wl,-rpath,{}",
deps_path.to_str().unwrap()
);
println!("cargo:rustc-link-lib=vzense_api");
println!("cargo:rustc-link-lib=Scepter_api");
}
fn symlink_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
fs::create_dir_all(&dst)?;
for entry in fs::read_dir(src)? {
let entry = entry?;
let file = dst.as_ref().join(entry.file_name());
let ty = entry.file_type()?;
if ty.is_dir() {
symlink_dir_all(entry.path(), file)?;
} else {
if !file.exists() {
std::os::unix::fs::symlink(entry.path(), file)?;
}
}
}
Ok(())
}