working proof of concept
This commit is contained in:
parent
9a86073066
commit
9efcf6b526
6 changed files with 39 additions and 18 deletions
|
@ -4,11 +4,9 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.39.2", features = ["full"] }
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = "0.3.18"
|
||||
libloading = "0.8.5"
|
||||
once_cell = "1.19.0"
|
||||
host_tools = { path = "host_tools" }
|
||||
|
||||
[workspace]
|
||||
members = ["plugins/testing"]
|
||||
members = [ "host_tools","plugins/testing"]
|
||||
|
|
13
host_tools/Cargo.toml
Normal file
13
host_tools/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "host_tools"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["dylib"]
|
||||
|
||||
[dependencies]
|
||||
async-trait = "0.1.81"
|
||||
tokio = { version = "1.39.3", features = ["full"] }
|
||||
tracing-subscriber = "0.3.18"
|
||||
tracing = "0.1.40"
|
|
@ -1,3 +1,7 @@
|
|||
pub use tokio;
|
||||
pub use tracing;
|
||||
pub use tracing_subscriber;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use tokio::runtime::Handle;
|
|
@ -7,8 +7,9 @@ edition = "2021"
|
|||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
tokio = "1.39.3"
|
||||
tracing = "0.1.40"
|
||||
gpt-sandbox = { path = "../../" }
|
||||
#tokio = "1.39.3"
|
||||
#tracing = "0.1.40"
|
||||
host_tools = {path="../../host_tools"}
|
||||
#gpt-sandbox = { path = "../../" }
|
||||
async-trait = "0.1.81"
|
||||
once_cell = "1.19.0"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use async_trait::async_trait;
|
||||
use gpt_sandbox::{AsyncFn, Plugin, PluginResult, RegisterFn};
|
||||
use host_tools::{tokio::task::JoinHandle, tracing::info, AsyncFn, Plugin, PluginResult, RegisterFn};
|
||||
use std::collections::HashMap;
|
||||
use tokio::runtime::Handle;
|
||||
use host_tools::tokio::runtime::Handle;
|
||||
|
||||
#[allow(improper_ctypes_definitions)] // will never be used by c programs, would use rust dylib if it existed
|
||||
#[no_mangle]
|
||||
|
@ -24,11 +24,11 @@ impl Plugin for ExamplePlugin {
|
|||
}
|
||||
}
|
||||
|
||||
fn example_function(handle: Handle) -> tokio::task::JoinHandle<PluginResult> {
|
||||
println!("start of example_function");
|
||||
fn example_function(handle: Handle) -> JoinHandle<PluginResult> {
|
||||
info!("start of example_function");
|
||||
|
||||
handle.spawn(async {
|
||||
println!("task running");
|
||||
info!("task running");
|
||||
PluginResult::Ok
|
||||
})
|
||||
}
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -1,10 +1,10 @@
|
|||
use gpt_sandbox::{AsyncFn, PluginResult, RegisterFn};
|
||||
use host_tools::tokio::runtime::Handle;
|
||||
use host_tools::tokio::sync::RwLock;
|
||||
use host_tools::tracing::{error, info};
|
||||
use host_tools::{AsyncFn, PluginResult, RegisterFn};
|
||||
use libloading::{Library, Symbol};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use tokio::runtime::Handle;
|
||||
use tokio::sync::RwLock;
|
||||
use tracing::{error, info};
|
||||
|
||||
fn get_name() -> String {
|
||||
"example_function".to_string()
|
||||
|
@ -100,9 +100,14 @@ async fn unload_plugin(
|
|||
// Ok(())
|
||||
//}
|
||||
|
||||
#[tokio::main(flavor = "multi_thread", worker_threads = 6)]
|
||||
#[host_tools::tokio::main(
|
||||
crate = "host_tools::tokio",
|
||||
flavor = "multi_thread",
|
||||
worker_threads = 6
|
||||
)]
|
||||
async fn main() -> Result<(), PluginResult> {
|
||||
tracing::subscriber::set_global_default(tracing_subscriber::fmt().finish()).unwrap();
|
||||
host_tools::tracing::subscriber::set_global_default(host_tools::tracing_subscriber::fmt().finish())
|
||||
.unwrap();
|
||||
let function_map: Arc<RwLock<HashMap<String, AsyncFn>>> = Arc::new(RwLock::new(HashMap::new()));
|
||||
|
||||
let plugin_lib = load_plugin("target/release/libtesting.so", Arc::clone(&function_map)).await?;
|
||||
|
|
Loading…
Add table
Reference in a new issue