1
0
Fork 0

First commit

This commit is contained in:
Florian RICHER 2022-01-27 21:50:25 +01:00
commit 39248b2ca3
8 changed files with 140 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
**/target

60
Cargo.lock generated Normal file
View file

@ -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"

12
Cargo.toml Normal file
View file

@ -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" }

7
plugins/hotload_toto1/Cargo.lock generated Normal file
View file

@ -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"

View file

@ -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"]

View file

@ -0,0 +1,4 @@
#[no_mangle]
pub extern fn version() -> String {
"0.2.0".to_string()
}

5
src/main.rs Normal file
View file

@ -0,0 +1,5 @@
mod plugin_manager;
fn main() {
plugin_manager::PluginManager::new();
}

38
src/plugin_manager.rs Normal file
View file

@ -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<Plugin>,
}
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<extern fn() -> String> = lib.get(b"version").unwrap();
Plugin {
version: version_func()
}
}
}
}