Restructured project for separate plugins
This commit is contained in:
40
helpers/src/lib.rs
Normal file
40
helpers/src/lib.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
#[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";
|
||||
|
||||
pub fn built_lib_path(lib_name: &str) -> PathBuf {
|
||||
Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap_or("".to_owned()))
|
||||
.join(format!("target/{CONFIG}/lib{lib_name}.{OS_LIB_EXT}"))
|
||||
}
|
||||
|
||||
pub fn copy_artifact_to_out_dir(lib_name: &str, pretty_name: &str) {
|
||||
let src_path = built_lib_path(lib_name);
|
||||
|
||||
let dst_path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap_or("".to_owned())).join(
|
||||
format!("target/build/{CONFIG}/{pretty_name}_{OS_NAME}.clap"),
|
||||
);
|
||||
|
||||
fs::create_dir_all(dst_path.parent().unwrap())
|
||||
.expect("Failed to create artifact output directory");
|
||||
fs::copy(src_path, dst_path).expect("Failed to move artifact");
|
||||
}
|
||||
Reference in New Issue
Block a user