57 lines
1.9 KiB
Rust
57 lines
1.9 KiB
Rust
use std::{env, fs, path::Path};
|
|
|
|
#[cfg(debug_assertions)]
|
|
const CONFIG: &str = "debug";
|
|
#[cfg(not(debug_assertions))]
|
|
const CONFIG: &str = "release";
|
|
|
|
#[cfg(target_os = "macos")]
|
|
const OS_LIB_EXT: &str = "dylib";
|
|
#[cfg(target_os = "windows")]
|
|
const OS_LIB_EXT: &str = "dll";
|
|
#[cfg(target_os = "linux")]
|
|
const OS_LIB_EXT: &str = "so";
|
|
|
|
#[cfg(target_os = "macos")]
|
|
const OS_NAME: &str = "macOS";
|
|
#[cfg(target_os = "windows")]
|
|
const OS_NAME: &str = "Windows";
|
|
#[cfg(target_os = "linux")]
|
|
const OS_NAME: &str = "Linux";
|
|
|
|
fn get_output_lib_name(lib_name: &str) -> &'static str {
|
|
match lib_name {
|
|
"airfreshener" => "AirFreshener",
|
|
_ => "Unknown",
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let target_dir = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap_or("".to_owned()))
|
|
.join(format!("target/{CONFIG}"));
|
|
let artifact_dir = target_dir.join("deps/artifact");
|
|
|
|
let artifact_dirs =
|
|
fs::read_dir(artifact_dir).expect("Failed to read build artifact directory");
|
|
for dir_result in artifact_dirs {
|
|
if let Ok(dir) = dir_result {
|
|
if let Some(lib_name) = dir.file_name().to_string_lossy().split('-').next() {
|
|
let lib_path = dir
|
|
.path()
|
|
.join(format!("cdylib/lib{lib_name}.{OS_LIB_EXT}"));
|
|
if fs::exists(&lib_path).unwrap_or_default() {
|
|
let out_lib_name = get_output_lib_name(lib_name);
|
|
let out_lib_path = target_dir.join(format!("{out_lib_name}_{OS_NAME}.clap"));
|
|
if let Err(err) = fs::copy(&lib_path, &out_lib_path) {
|
|
println!(
|
|
"cargo::error=Output library lib{lib_name:?}.{OS_LIB_EXT} could not be copied to target: {err}"
|
|
);
|
|
}
|
|
} else {
|
|
println!("cargo::error=Output library lib{lib_name:?}.{OS_LIB_EXT} not found");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|