From 9c0c4c292cca7f26ae10f54814ef12a70cc80ea5 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 28 Apr 2024 18:54:27 -0400 Subject: [PATCH] document hot_lib for developers a bit Signed-off-by: strawberry --- Cargo.lock | 10 +++++----- Cargo.toml | 8 +++++--- {lib => hot_lib}/Cargo.toml | 2 +- {lib => hot_lib}/src/lib.rs | 3 +++ src/service/admin/test_cmd/mod.rs | 18 ++++++++++++++---- 5 files changed, 28 insertions(+), 13 deletions(-) rename {lib => hot_lib}/Cargo.toml (83%) rename {lib => hot_lib}/src/lib.rs (68%) diff --git a/Cargo.lock b/Cargo.lock index 9bee6c43..446bec49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -567,6 +567,7 @@ dependencies = [ "hickory-resolver", "hmac", "hot-lib-reloader", + "hot_lib", "http 1.1.0", "http-body-util", "hyper 1.3.1", @@ -575,7 +576,6 @@ dependencies = [ "ipaddress", "itertools 0.12.1", "jsonwebtoken", - "lib", "log", "loole", "lru-cache", @@ -1347,6 +1347,10 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "hot_lib" +version = "0.1.0" + [[package]] name = "html5ever" version = "0.26.0" @@ -1797,10 +1801,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" -[[package]] -name = "lib" -version = "0.1.0" - [[package]] name = "libc" version = "0.2.153" diff --git a/Cargo.toml b/Cargo.toml index 4fddac7c..d9d58395 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,14 +18,16 @@ rust-version = "1.76.0" # for hot lib reload [workspace] -members = ["lib"] +members = ["hot_lib"] [dependencies] console-subscriber = { version = "0.1", optional = true } # for hot lib reload +# see https://github.com/rksm/hot-lib-reloader-rs?tab=readme-ov-file#usage for more details if you are a dev hot-lib-reloader = { version = "^0.7", optional = true } -lib = { path = "lib", optional = true } +hot_lib = { path = "hot_lib", optional = true } +# not sure if we need this, will anyone be using hot lib reload on release profile? #no-mangle-if-debug = { version = "*" } # Used for secure identifiers @@ -406,7 +408,7 @@ perf_measurements = [ # incompatible with release_max_log_level tokio_console = ["console-subscriber", "tokio/tracing"] -hot_reload = ["dep:hot-lib-reloader", "lib"] +hot_reload = ["dep:hot-lib-reloader", "hot_lib"] hardened_malloc = ["hardened_malloc-rs"] diff --git a/lib/Cargo.toml b/hot_lib/Cargo.toml similarity index 83% rename from lib/Cargo.toml rename to hot_lib/Cargo.toml index b301b690..0582e57c 100644 --- a/lib/Cargo.toml +++ b/hot_lib/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "lib" +name = "hot_lib" version = "0.1.0" edition = "2021" diff --git a/lib/src/lib.rs b/hot_lib/src/lib.rs similarity index 68% rename from lib/src/lib.rs rename to hot_lib/src/lib.rs index 91e76586..2ffe3278 100644 --- a/lib/src/lib.rs +++ b/hot_lib/src/lib.rs @@ -1,3 +1,6 @@ +//! hot reloadable functions, generally called by the admin room test commands +//! see https://github.com/rksm/hot-lib-reloader-rs?tab=readme-ov-file#usage for more details if you are a dev + #[no_mangle] pub fn test_command() { println!("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); diff --git a/src/service/admin/test_cmd/mod.rs b/src/service/admin/test_cmd/mod.rs index 852afbe7..08cf2c54 100644 --- a/src/service/admin/test_cmd/mod.rs +++ b/src/service/admin/test_cmd/mod.rs @@ -1,21 +1,30 @@ -use clap::Subcommand; +//! test commands generally used for hot lib reloadable functions. +//! see https://github.com/rksm/hot-lib-reloader-rs?tab=readme-ov-file#usage for more details if you are a dev + +//#[cfg(not(feature = "hot_reload"))] +//#[allow(unused_imports)] +//#[allow(clippy::wildcard_imports)] +// non hot reloadable functions (?) +//use hot_lib::*; #[cfg(feature = "hot_reload")] #[allow(unused_imports)] #[allow(clippy::wildcard_imports)] -use hot_lib::*; +use hot_lib_funcs::*; use ruma::events::room::message::RoomMessageEventContent; use crate::{debug_error, Result}; #[cfg(feature = "hot_reload")] #[hot_lib_reloader::hot_module(dylib = "lib")] -mod hot_lib { +mod hot_lib_funcs { + // these will be functions from lib.rs, so `use hot_lib_funcs::test_command;` hot_functions_from_file!("lib/src/lib.rs"); } #[cfg_attr(test, derive(Debug))] -#[derive(Subcommand)] +#[derive(clap::Subcommand)] pub(crate) enum TestCommands { + // !admin test test1 Test1, } @@ -25,6 +34,7 @@ pub(crate) async fn process(command: TestCommands, _body: Vec<&str>) -> Result