Make unshell-lib, and module system with components.

This commit is contained in:
Michael Mikovsky
2025-11-08 14:56:03 -07:00
parent 8f33945633
commit 3dba32264c
27 changed files with 461 additions and 311 deletions
@@ -28,21 +28,6 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]] [[package]]
name = "libloading" name = "libloading"
version = "0.8.9" version = "0.8.9"
@@ -124,21 +109,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]] [[package]]
name = "unshell-modules" name = "unshell-breakout-module"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"libloading", "unshell-lib",
"log",
] ]
[[package]] [[package]]
name = "unshell-test-module" name = "unshell-lib"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bincode", "bincode",
"crossbeam-channel", "libloading",
"log", "log",
"unshell-modules",
] ]
[[package]] [[package]]
@@ -1,19 +1,21 @@
cargo-features = ["trim-paths"] cargo-features = ["trim-paths"]
[package] [package]
name = "unshell-test-module" name = "unshell-breakout-module"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies]
# unshell-modules = {path = "../unshell-modules"}
unshell-lib = {path = "../unshell-lib"}
[lib] [lib]
crate-type = ["cdylib"] crate-type = ["cdylib"]
[features] [features]
default = ["client-component", "server-component"] default = ["client", "server"]
client-component = [] client = []
server-component = [] server = []
# server = []
[profile.release] [profile.release]
strip = true # Strip symbols from the binary strip = true # Strip symbols from the binary
@@ -26,10 +28,3 @@ debug = false
trim-paths = "all" trim-paths = "all"
# crate-type = ["cdylib"] # crate-type = ["cdylib"]
[dependencies]
bincode = "2.0.1"
crossbeam-channel = "0.5.15"
log = "0.4.28"
unshell-modules = {path = "../unshell-modules"}
+28
View File
@@ -0,0 +1,28 @@
#![no_main]
use std::collections::HashMap;
use unshell_lib::Component;
#[unsafe(no_mangle)]
pub fn get_components() -> HashMap<&'static str, Box<dyn Component>> {
let mut components: HashMap<&'static str, Box<dyn Component>> = HashMap::new();
#[cfg(feature = "client")]
components.insert(
unshell_lib::client::MODULE_NAME,
Box::new(unshell_lib::client::ClientComponent::new()),
);
components
// vec![
// Feature::Client,
// #[cfg(feature = "server")]
// Feature::Server,
// ]
}
#[cfg(feature = "client")]
pub use unshell_lib::client::*;
#[cfg(feature = "server")]
pub use unshell_lib::server::*;
+3 -27
View File
@@ -28,21 +28,6 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]] [[package]]
name = "libloading" name = "libloading"
version = "0.8.9" version = "0.8.9"
@@ -127,25 +112,16 @@ checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
name = "unshell-cli" name = "unshell-cli"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"unshell-test-module", "unshell-lib",
] ]
[[package]] [[package]]
name = "unshell-modules" name = "unshell-lib"
version = "0.1.0"
dependencies = [
"libloading",
"log",
]
[[package]]
name = "unshell-test-module"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bincode", "bincode",
"crossbeam-channel", "libloading",
"log", "log",
"unshell-modules",
] ]
[[package]] [[package]]
+1 -1
View File
@@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
unshell-test-module = {path = "../unshell-test-module"}#, default-features = false, features = ["server-component"]} unshell-lib = {path = "../unshell-lib"}#, default-features = false, features = ["server-component"]}
+2 -2
View File
@@ -1,6 +1,6 @@
use std::io::{Write, stdin, stdout}; use std::io::{Write, stdin, stdout};
use unshell_test_module::Announcement; use unshell_lib::Announcement;
// use unshell_test_module::ListenerRuntime; // use unshell_test_module::ListenerRuntime;
@@ -9,7 +9,7 @@ use unshell_test_module::Announcement;
// } // }
fn main() { fn main() {
let mut serverruntime = unshell_test_module::ListenerRuntime::new(); let mut serverruntime = unshell_lib::server::ListenerRuntime::new();
loop { loop {
print!("> "); print!("> ");
+136
View File
@@ -0,0 +1,136 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "bincode"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740"
dependencies = [
"bincode_derive",
"serde",
"unty",
]
[[package]]
name = "bincode_derive"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09"
dependencies = [
"virtue",
]
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "libloading"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
dependencies = [
"cfg-if",
"windows-link",
]
[[package]]
name = "log"
version = "0.4.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
[[package]]
name = "proc-macro2"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
dependencies = [
"proc-macro2",
]
[[package]]
name = "serde"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [
"serde_core",
]
[[package]]
name = "serde_core"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "2.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f17c7e013e88258aa9543dcbe81aca68a667a9ac37cd69c9fbc07858bfe0e2f"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
name = "unshell-lib"
version = "0.1.0"
dependencies = [
"bincode",
"libloading",
"log",
]
[[package]]
name = "unty"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae"
[[package]]
name = "virtue"
version = "0.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1"
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
+10
View File
@@ -0,0 +1,10 @@
[package]
name = "unshell-lib"
version = "0.1.0"
edition = "2024"
[dependencies]
libloading = {version = "0.8.9"}
bincode = "2.0.1"
log = "0.4.28"
# unshell-modules = {path = "../unshell-modules"}
@@ -1,19 +1,5 @@
#![no_main]
#[macro_use]
extern crate log;
use bincode::{Decode, Encode}; use bincode::{Decode, Encode};
#[cfg(feature = "client-component")]
mod client;
#[cfg(feature = "client-component")]
pub use client::*;
#[cfg(feature = "server-component")]
mod server;
#[cfg(feature = "server-component")]
pub use server::ListenerRuntime;
#[derive(Debug, Encode, Decode)] #[derive(Debug, Encode, Decode)]
pub enum Announcement { pub enum Announcement {
TestAnnouncement(String), TestAnnouncement(String),
@@ -8,9 +8,9 @@ use std::{
thread::{self, JoinHandle}, thread::{self, JoinHandle},
}; };
use unshell_modules::{Manager, ModuleRuntime}; // use unshell_modules::{Manager, ModuleRuntime};
use crate::Announcement; use crate::{Announcement, ModuleRuntime, module::Manager};
pub struct RuntimeTest { pub struct RuntimeTest {
thread_handle: JoinHandle<()>, thread_handle: JoinHandle<()>,
+74
View File
@@ -0,0 +1,74 @@
mod client_runtime;
// use crate::module::Interface;
use std::sync::{Arc, Mutex};
pub const MODULE_NAME: &'static str = "client";
// pub use unshell_modules::setup_logger;
// use unshell_modules::{Manager, ModuleRuntime, module_interface};
use crate::{
Component,
ModuleRuntime,
client::client_runtime::RuntimeTest,
module::{Interface, Manager},
module_interface,
// module_interface,
};
pub extern "C" fn test1() {
warn!("Test1 called xxxxxxxxxxx");
}
pub extern "C" fn test2() {
warn!("Test2 called");
}
pub extern "C" fn test3() {
warn!("Test3 called");
}
module_interface! {
ClientInterface {
fn test1();
fn test2();
fn test3();
}
}
// #[unsafe(no_mangle)]
// pub fn interface() -> Interface {
// Interface::from_raw(test1, test2, test3)
// }
// #[unsafe(no_mangle)]
// pub fn init(manager: Arc<Mutex<Manager>>) -> Box<dyn ModuleRuntime> {
// info!("Initializing client module");
// }
#[derive(Clone)]
pub struct ClientComponent;
impl ClientComponent {
pub fn new() -> Self {
ClientComponent
}
}
impl Component for ClientComponent {
fn name(&self) -> &'static str {
MODULE_NAME
}
fn start_runtime(&self, manager: Arc<Mutex<Manager>>) -> Option<Box<dyn ModuleRuntime>> {
Some(Box::new(RuntimeTest::new(manager)))
}
fn clone_box(&self) -> Box<dyn Component> {
Box::new(self.clone())
}
fn get_interface(&self) -> Box<dyn Interface> {
Box::new(ClientInterface::from_raw(test1, test2, test3))
}
}
+45
View File
@@ -0,0 +1,45 @@
#![no_main]
#[macro_use]
extern crate log;
pub mod client;
pub mod module;
pub mod server;
mod announcement;
use std::sync::{Arc, Mutex};
pub use announcement::Announcement;
use crate::module::{Interface, Manager};
///Generic error type for module-related operations.
#[derive(Debug)]
pub enum ModuleError {
LibLoadingError(libloading::Error),
LogError(log::SetLoggerError),
LinkError(String),
Error(String),
}
/// Trait for defining modules that have a runtime.
pub trait ModuleRuntime: Send {
/// Returns true if the module is running.
/// After returning false, the module will be dropped.
fn is_running(&self) -> bool;
/// Consumes the module, implementation should kill whatever is running.
fn kill(self: Box<Self>);
}
pub trait Component {
fn name(&self) -> &'static str;
fn start_runtime(&self, manager: Arc<Mutex<Manager>>) -> Option<Box<dyn ModuleRuntime>>;
fn get_interface(&self) -> Box<dyn Interface>;
fn clone_box(&self) -> Box<dyn Component>;
}
impl Clone for Box<dyn Component> {
fn clone(&self) -> Box<dyn Component> {
self.clone_box()
}
}
+88
View File
@@ -0,0 +1,88 @@
use std::{
collections::HashMap,
sync::{Arc, Mutex},
thread,
time::Duration,
};
use crate::{Component, ModuleRuntime, module::Module};
pub struct Manager {
modules: Vec<Module>,
components: HashMap<&'static str, Box<dyn Component>>,
}
// static mut MANAGER_RUNTIME: Option<Arc<Mutex<Manager>>> = None;
impl Manager {
/// Create Manager, and run initilization for each Module
#[allow(static_mut_refs)]
pub fn run<'a>(modules: Vec<Module>) {
let this: Self = Self::load_modules(modules);
let components = this.components.clone();
let this = Arc::new(Mutex::new(this));
let mut runtimes: Vec<Box<dyn ModuleRuntime>> = Vec::new();
for (name, component) in components {
let module_runtime = component.start_runtime(this.clone());
if let Some(module_runtime) = module_runtime {
info!("Initialized {}", name);
runtimes.push(module_runtime);
}
}
Self::join(&mut runtimes);
}
pub fn load_modules<'a>(modules: Vec<Module>) -> Self {
let module_count = modules.len();
let mut this = Self {
modules,
components: HashMap::new(),
};
// let mut runtimes = Vec::new();
for i in 0..module_count {
info!("Importing module {}", i);
// let this_lock = .unwrap();
let component_func = if let Ok(component_func) = this.modules[i]
.get_symbol::<fn() -> HashMap<&'static str, Box<dyn Component>>>(b"get_components")
{
component_func
} else {
warn!("get_components function not found");
continue;
};
let components = component_func();
info!("[{i}] Loaded {} components", components.len());
this.components.extend(components);
}
this
}
/// Iterateratively loop through all runtimes, until all are finished executing
pub fn join(runtimes: &mut Vec<Box<dyn ModuleRuntime>>) {
// let mut len = runtimes.len().clone();
while runtimes.len() > 0 {
runtimes.retain(|runtime| runtime.is_running());
thread::sleep(Duration::from_micros(100));
}
}
// pub extern "C" fn test1234(&self, float: f32) {
// info!("Manager Test Sucsessfull! {}", float.powf(2.));
// }
// #[allow(static_mut_refs, improper_ctypes_definitions)]
// pub extern "C" fn get_manager() -> Arc<Mutex<Manager>> {
// unsafe { MANAGER_RUNTIME.clone().unwrap() }
// }
}
@@ -1,30 +1,15 @@
#[macro_use]
extern crate log;
mod logger; mod logger;
mod manager; mod manager;
mod module; mod module;
// use std::any::Any;
pub use logger::setup_logger; pub use logger::setup_logger;
pub use manager::Manager; pub use manager::Manager;
pub use module::Module; pub use module::Module;
///Generic error type for module-related operations. pub trait Interface {
#[derive(Debug)] fn as_any(self: Box<Self>) -> Box<dyn std::any::Any>;
pub enum ModuleError {
LibLoadingError(libloading::Error),
LogError(log::SetLoggerError),
LinkError(String),
Error(String),
}
/// Trait for defining modules that have a runtime.
pub trait ModuleRuntime: Send {
/// Returns true if the module is running.
/// After returning false, the module will be dropped.
fn is_running(&self) -> bool;
/// Consumes the module, implementation should kill whatever is running.
fn kill(self: Box<Self>);
} }
/// "Module Interface" helper macro that creates a struct with function pointers /// "Module Interface" helper macro that creates a struct with function pointers
@@ -73,5 +58,11 @@ macro_rules! module_interface {
} }
} }
} }
impl crate::module::Interface for $interface_name {
fn as_any(self: Box<Self>) -> Box<dyn std::any::Any> {
self
}
}
}; };
} }
@@ -1,8 +1,7 @@
use libloading::{Library, Symbol}; use libloading::{Library, Symbol};
use crate::{ModuleError, logger::SetupLogger}; use crate::{ModuleError, module::logger::SetupLogger};
// #[derive(Clone, Copy)]
pub struct Module { pub struct Module {
// name: String, // name: String,
lib: Library, lib: Library,
@@ -31,15 +30,15 @@ impl Module {
Ok(symbol) Ok(symbol)
} }
pub fn get_interface<T>(&self) -> Result<T, ModuleError> { // pub fn get_interface<T>(&self) -> Result<T, ModuleError> {
if let Ok(interface_function) = self.get_symbol::<fn() -> T>(b"interface") { // if let Ok(interface_function) = self.get_symbol::<fn() -> T>(b"interface") {
Ok(interface_function()) // Ok(interface_function())
} else { // } else {
Err(ModuleError::LinkError(format!( // Err(ModuleError::LinkError(format!(
"Interface function not found!" // "Interface function not found!"
))) // )))
} // }
} // }
} }
// extern "C" fn test1234() { // extern "C" fn test1234() {
@@ -5,7 +5,7 @@ use std::{
thread::{self, JoinHandle}, thread::{self, JoinHandle},
}; };
use unshell_modules::ModuleRuntime; use crate::ModuleRuntime;
use crate::Announcement; use crate::Announcement;
@@ -31,39 +31,11 @@ impl ListenerRuntime {
let stream = stream.unwrap(); let stream = stream.unwrap();
println!("New connection from {}", stream.peer_addr().unwrap()); println!("New connection from {}", stream.peer_addr().unwrap());
streams.lock().unwrap().push(stream); streams.lock().unwrap().push(stream);
// thread::spawn(move || {
// let _ = handle_connection(&mut stream);
// info!("Connection from {} closed", stream.peer_addr().unwrap());
// });
} }
}); });
// let reader = BufReader::new(stream.try_clone().unwrap());
// let writer = BufWriter::new(stream.try_clone().unwrap());
Self { Self {
thread_handle, thread_handle,
streams, streams,
// stream,
// reader,
// writer,
// thread_handle: thread::spawn(move || {
// for stream in listener.incoming() {
// let mut stream = stream.unwrap();
// thread::spawn(move || {
// let _ = handle_connection(&mut stream);
// info!("Connection from {} closed", stream.peer_addr().unwrap());
// });
// }
// // thread::sleep(Duration::from_secs(2));
// // let manager_lock = manager.lock().unwrap();
// // manager_lock.test1234(111.1111);
// // drop(manager_lock);
// }),
} }
} }
-39
View File
@@ -1,39 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "libloading"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
dependencies = [
"cfg-if",
"windows-link",
]
[[package]]
name = "log"
version = "0.4.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
[[package]]
name = "unshell-modules"
version = "0.1.0"
dependencies = [
"libloading",
"log",
]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
-12
View File
@@ -1,12 +0,0 @@
[package]
name = "unshell-modules"
version = "0.1.0"
edition = "2024"
[features]
default = ["exec"]
"exec" = ["libloading"]
[dependencies]
libloading = {version = "0.8.9", optional = true}
log = "0.4.28"
-71
View File
@@ -1,71 +0,0 @@
use std::{
sync::{Arc, Mutex},
thread,
time::Duration,
};
use crate::{Module, ModuleRuntime};
pub struct Manager {
modules: Vec<Module>,
}
static mut MANAGER_RUNTIME: Option<Arc<Mutex<Manager>>> = None;
impl Manager {
/// Create Manager, and run initilization for each Module
#[allow(static_mut_refs)]
pub fn run<'a>(modules: Vec<Module>) {
let module_count = modules.len();
let this = Self { modules };
let this = Arc::new(Mutex::new(this));
let mut runtimes = Vec::new();
for i in 0..module_count {
info!("Initializing {}", i);
let this_lock = this.lock().unwrap();
let init = if let Ok(init) =
this_lock.modules[i]
.get_symbol::<fn(Arc<Mutex<Manager>>) -> Box<dyn ModuleRuntime>>(b"init")
{
init.to_owned()
} else {
warn!("init not found");
continue;
};
let runtime = init(this.clone());
info!("Initialized {}", i);
runtimes.push(runtime);
}
Self::join(&mut runtimes);
}
/// Iterateratively loop through all runtimes, until all are finished executing
pub fn join(runtimes: &mut Vec<Box<dyn ModuleRuntime>>) {
// let mut len = runtimes.len().clone();
while runtimes.len() > 0 {
runtimes.retain(|runtime| runtime.is_running());
thread::sleep(Duration::from_micros(100));
}
}
// pub extern "C" fn test123() {
// info!("Manager Test Sucsessfull!");
// }
pub extern "C" fn test1234(&self, float: f32) {
info!("Manager Test Sucsessfull! {}", float.powf(2.));
}
#[allow(static_mut_refs, improper_ctypes_definitions)]
pub extern "C" fn get_manager() -> Arc<Mutex<Manager>> {
unsafe { MANAGER_RUNTIME.clone().unwrap() }
}
}
+35 -2
View File
@@ -61,6 +61,26 @@ dependencies = [
"windows-sys 0.60.2", "windows-sys 0.60.2",
] ]
[[package]]
name = "bincode"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740"
dependencies = [
"bincode_derive",
"serde",
"unty",
]
[[package]]
name = "bincode_derive"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09"
dependencies = [
"virtue",
]
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.4" version = "1.0.4"
@@ -324,9 +344,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]] [[package]]
name = "unshell-modules" name = "unshell-lib"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bincode",
"libloading", "libloading",
"log", "log",
] ]
@@ -339,15 +360,27 @@ dependencies = [
"libloading", "libloading",
"log", "log",
"pretty_env_logger", "pretty_env_logger",
"unshell-modules", "unshell-lib",
] ]
[[package]]
name = "unty"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae"
[[package]] [[package]]
name = "utf8parse" name = "utf8parse"
version = "0.2.2" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "virtue"
version = "0.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1"
[[package]] [[package]]
name = "winapi-util" name = "winapi-util"
version = "0.1.11" version = "0.1.11"
+1 -1
View File
@@ -11,7 +11,7 @@ libloading = "0.8.9"
log = "0.4.28" log = "0.4.28"
pretty_env_logger = "0.5.0" pretty_env_logger = "0.5.0"
# unshell-logger = {path = "../unshell-logger"} # unshell-logger = {path = "../unshell-logger"}
unshell-modules = {path = "../unshell-modules"} unshell-lib = {path = "../unshell-lib"}
[profile.release] [profile.release]
strip = true # Strip symbols from the binary strip = true # Strip symbols from the binary
+4 -10
View File
@@ -1,16 +1,11 @@
use unshell_modules::{Manager, Module, ModuleError, module_interface}; use unshell_lib::{
ModuleError,
module::{Manager, Module},
};
#[macro_use] #[macro_use]
extern crate log; extern crate log;
module_interface! {
Interface {
fn test1();
fn test2();
fn test3();
}
}
fn main() { fn main() {
// Init the logger (This uses like 600MB of storage) // Init the logger (This uses like 600MB of storage)
pretty_env_logger::init(); pretty_env_logger::init();
@@ -26,7 +21,6 @@ fn main() {
modules.push(Module::new(&arg)?) modules.push(Module::new(&arg)?)
} }
Manager::run(modules); Manager::run(modules);
// manager.join();
Ok(()) Ok(())
}() { }() {
-38
View File
@@ -1,38 +0,0 @@
mod client_runtime;
use std::sync::{Arc, Mutex};
pub use unshell_modules::setup_logger;
use unshell_modules::{Manager, ModuleRuntime, module_interface};
use crate::client::client_runtime::RuntimeTest;
pub extern "C" fn test1() {
warn!("Test1 called");
}
pub extern "C" fn test2() {
warn!("Test2 called");
}
pub extern "C" fn test3() {
warn!("Test3 called");
}
module_interface! {
Interface {
fn test1();
fn test2();
fn test3();
}
}
#[unsafe(no_mangle)]
pub fn interface() -> Interface {
Interface::from_raw(test1, test2, test3)
}
#[unsafe(no_mangle)]
pub fn init(manager: Arc<Mutex<Manager>>) -> Box<dyn ModuleRuntime> {
info!("Initializing client module");
Box::new(RuntimeTest::new(manager))
}