reactive_graph_utils_deployment/
lib.rs1use serde::Deserialize;
2use std::env::VarError;
3use std::env::var;
4use std::fs;
5use std::path::PathBuf;
6use thiserror::Error;
7
8#[derive(Deserialize)]
9struct Deployment {
10 pub target_dirs: Vec<String>,
11}
12
13#[derive(Debug, Error)]
14pub enum DeploymentError {
15 #[error("Could not read .deployment.toml: {0}")]
16 ReadError(#[from] std::io::Error),
17 #[error("Could not parse .deployment.toml: {0}")]
18 TomlError(#[from] toml::de::Error),
19 #[error("Could not read env var: {0}")]
20 EnvVarError(#[from] VarError),
21}
22
23pub fn deploy_plugin(filename: &str) -> Result<(), DeploymentError> {
24 let toml_string = fs::read_to_string("./.deployment.toml")?;
25 let deployment: Deployment = toml::from_str(&toml_string)?;
26 let mut crate_out_dir = var("CRATE_OUT_DIR")?;
27 crate_out_dir.push('/');
28 crate_out_dir.push_str(filename);
29 for target_dir in deployment.target_dirs {
30 for source_path in glob::glob(crate_out_dir.as_str()).unwrap().flatten() {
31 let file_name = source_path.file_name().unwrap().to_str().unwrap();
32 if file_name.ends_with(".so") || file_name.ends_with(".dll") {
33 let mut target_path = PathBuf::from(&target_dir);
34 target_path.push(file_name);
35 println!("Copy plugin from {} to {}", source_path.display(), target_path.display());
36 match fs::copy(source_path, target_path) {
37 Ok(_) => println!("Success"),
38 Err(e) => eprintln!("Error: {e}"),
39 }
40 }
41 }
42 }
43 Ok(())
44}