Skip to content

Commit

Permalink
feat(plugin): use conditional build for different os and build type
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliot00 committed Feb 20, 2021
1 parent 62de090 commit 11bea29
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion plugin_manager/src/plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn PluginInterface>,
Expand All @@ -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<Wrapper> =
Expand All @@ -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)]
Expand Down

0 comments on commit 11bea29

Please sign in to comment.