From 39248b2ca3e268623084b7940b1c395cb14cc69c Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Thu, 27 Jan 2022 21:50:25 +0100 Subject: [PATCH] First commit --- .gitignore | 2 ++ Cargo.lock | 60 ++++++++++++++++++++++++++++++++ Cargo.toml | 12 +++++++ plugins/hotload_toto1/Cargo.lock | 7 ++++ plugins/hotload_toto1/Cargo.toml | 12 +++++++ plugins/hotload_toto1/src/lib.rs | 4 +++ src/main.rs | 5 +++ src/plugin_manager.rs | 38 ++++++++++++++++++++ 8 files changed, 140 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 plugins/hotload_toto1/Cargo.lock create mode 100644 plugins/hotload_toto1/Cargo.toml create mode 100644 plugins/hotload_toto1/src/lib.rs create mode 100644 src/main.rs create mode 100644 src/plugin_manager.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..74f7873 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +**/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..3ee3144 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,60 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "hotload" +version = "0.1.0" +dependencies = [ + "glob", + "hotload_toto1", + "libloading", +] + +[[package]] +name = "hotload_toto1" +version = "0.1.0" + +[[package]] +name = "libloading" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..26a58a1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "hotload" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +libloading = "0.7" +glob = "0.3" +# hotload_plugin = { path = "./crates/hotload_plugin" } +hotload_toto1 = { path = "./plugins/hotload_toto1" } diff --git a/plugins/hotload_toto1/Cargo.lock b/plugins/hotload_toto1/Cargo.lock new file mode 100644 index 0000000..f333e14 --- /dev/null +++ b/plugins/hotload_toto1/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "hotload_toto1" +version = "0.1.0" diff --git a/plugins/hotload_toto1/Cargo.toml b/plugins/hotload_toto1/Cargo.toml new file mode 100644 index 0000000..5159015 --- /dev/null +++ b/plugins/hotload_toto1/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "hotload_toto1" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +# hotload_plugin = { path = "../../crates/hotload_plugin" } + +[lib] +crate-type = ["dylib"] diff --git a/plugins/hotload_toto1/src/lib.rs b/plugins/hotload_toto1/src/lib.rs new file mode 100644 index 0000000..080c089 --- /dev/null +++ b/plugins/hotload_toto1/src/lib.rs @@ -0,0 +1,4 @@ +#[no_mangle] +pub extern fn version() -> String { + "0.2.0".to_string() +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e529e38 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,5 @@ +mod plugin_manager; + +fn main() { + plugin_manager::PluginManager::new(); +} diff --git a/src/plugin_manager.rs b/src/plugin_manager.rs new file mode 100644 index 0000000..2f7b821 --- /dev/null +++ b/src/plugin_manager.rs @@ -0,0 +1,38 @@ +use std::env::current_exe; +use std::path::PathBuf; +use glob::glob; + +#[derive(Debug, Clone)] +pub struct Plugin { + pub version: String +} + +pub struct PluginManager { + pub plugins: Vec, +} + +impl PluginManager { + pub fn new() { + println!("Loading librairies..."); + let mut plugins = Vec::new(); + let current_path = current_exe().unwrap(); + let parent_path = current_path.parent().unwrap(); + let lib_folder = parent_path.join("*.so"); + for lib_file in glob(lib_folder.to_str().unwrap()).unwrap() { + let plugin = Self::load_library(lib_file.unwrap()); + println!("Loaded plugin {:?}", plugin); + plugins.push(plugin); + } + } + + fn load_library(lib_file: PathBuf) -> Plugin { + println!("Loading library {:?}", lib_file); + unsafe { + let lib = libloading::Library::new(lib_file).unwrap(); + let version_func : libloading::Symbol String> = lib.get(b"version").unwrap(); + Plugin { + version: version_func() + } + } + } +}