diff --git a/plugin_manager/src/plugin_manager.rs b/plugin_manager/src/plugin_manager.rs index 7bc4ba5b..0d7be013 100644 --- a/plugin_manager/src/plugin_manager.rs +++ b/plugin_manager/src/plugin_manager.rs @@ -3,6 +3,12 @@ use dlopen::wrapper::{Container, WrapperApi}; use plugin_interface::PluginInterface; use std::path::PathBuf; +const BUILD_TYPE: &str = if cfg!(debug_assertions) { + "debug" +} else { + "release" +}; + #[derive(WrapperApi)] struct Wrapper { plugin: fn() -> Box, @@ -13,7 +19,7 @@ pub struct PluginManager {} impl PluginManager { pub fn run(plugin_name: &str) { let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let plugin_path = format!("target/debug/libcoco_{}.dylib", plugin_name); + let plugin_path = Self::get_plugin_path(plugin_name); let path = root.parent().unwrap().join(plugin_path); let cont: Container = @@ -22,6 +28,21 @@ impl PluginManager { let plugin = cont.plugin(); println!("{:?}", plugin.name()); } + + #[cfg(target_os = "linux")] + fn get_plugin_path(plugin_name: &str) -> String { + format!("target/{}/lib{}.so", BUILD_TYPE, plugin_name) + } + + #[cfg(target_os = "macos")] + fn get_plugin_path(plugin_name: &str) -> String { + format!("target/{}/libcoco_{}.dylib", BUILD_TYPE, plugin_name) + } + + #[cfg(target_os = "windows")] + fn get_plugin_path(plugin_name: &str) -> String { + format!("target\\{}\\{}.dll", BUILD_TYPE, plugin_name) + } } #[cfg(test)]