diff --git a/Cargo.toml b/Cargo.toml index 89ac780..952ec24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/host_tools/Cargo.toml b/host_tools/Cargo.toml new file mode 100644 index 0000000..aacd06a --- /dev/null +++ b/host_tools/Cargo.toml @@ -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" diff --git a/src/lib.rs b/host_tools/src/lib.rs similarity index 86% rename from src/lib.rs rename to host_tools/src/lib.rs index 664869a..a7bd822 100644 --- a/src/lib.rs +++ b/host_tools/src/lib.rs @@ -1,3 +1,7 @@ +pub use tokio; +pub use tracing; +pub use tracing_subscriber; + use std::collections::HashMap; use tokio::runtime::Handle; diff --git a/plugins/testing/Cargo.toml b/plugins/testing/Cargo.toml index 6648dcc..ddda153 100644 --- a/plugins/testing/Cargo.toml +++ b/plugins/testing/Cargo.toml @@ -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" diff --git a/plugins/testing/src/lib.rs b/plugins/testing/src/lib.rs index 719c493..c704715 100644 --- a/plugins/testing/src/lib.rs +++ b/plugins/testing/src/lib.rs @@ -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 { - println!("start of example_function"); +fn example_function(handle: Handle) -> JoinHandle { + info!("start of example_function"); handle.spawn(async { - println!("task running"); + info!("task running"); PluginResult::Ok }) } diff --git a/src/main.rs b/src/main.rs index d77c208..f0c85f8 100644 --- a/src/main.rs +++ b/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>> = Arc::new(RwLock::new(HashMap::new())); let plugin_lib = load_plugin("target/release/libtesting.so", Arc::clone(&function_map)).await?;