From 4743a8d9688e836e7e3e7f27449b8b4683f17a97 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 4 Oct 2025 03:29:19 +0000 Subject: [PATCH] Move args and runtime back to main from core (1313eb0b64). Signed-off-by: Jason Volk --- src/core/mod.rs | 4 ---- src/{core => main}/args.rs | 5 ++--- src/main/benches/main.rs | 6 +++--- src/main/lib.rs | 13 +++++++++---- src/main/main.rs | 4 ++-- src/{core => main}/runtime.rs | 21 ++++++++++++--------- src/main/server.rs | 5 ++--- src/main/tests/smoke.rs | 4 ++-- src/main/tests/smoke_async.rs | 6 +++--- src/main/tests/smoke_shutdown.rs | 6 +++--- 10 files changed, 38 insertions(+), 36 deletions(-) rename src/{core => main}/args.rs (99%) rename src/{core => main}/runtime.rs (93%) diff --git a/src/core/mod.rs b/src/core/mod.rs index 43d21083..fcda4f8c 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -1,7 +1,6 @@ #![type_length_limit = "12288"] pub mod alloc; -pub mod args; pub mod config; pub mod debug; pub mod error; @@ -10,7 +9,6 @@ pub mod log; pub mod matrix; pub mod metrics; pub mod mods; -pub mod runtime; pub mod server; pub mod utils; @@ -22,14 +20,12 @@ pub use ::smallstr; pub use ::smallvec; pub use ::toml; pub use ::tracing; -pub use args::Args; pub use config::Config; pub use error::Error; pub use info::{rustc_flags_capture, version, version::version}; pub use matrix::{ Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, RoomVersion, pdu, state_res, }; -pub use runtime::Runtime; pub use server::Server; pub use utils::{ctor, dtor, implement, result, result::Result}; diff --git a/src/core/args.rs b/src/main/args.rs similarity index 99% rename from src/core/args.rs rename to src/main/args.rs index 61a72a64..7808005c 100644 --- a/src/core/args.rs +++ b/src/main/args.rs @@ -3,8 +3,7 @@ use std::path::PathBuf; use clap::{ArgAction, Parser}; - -use crate::{ +use tuwunel_core::{ Err, Result, config::{Figment, FigmentValue}, err, toml, @@ -17,7 +16,7 @@ use crate::{ about, long_about = None, name = "tuwunel", - version = crate::version(), + version = tuwunel_core::version(), )] pub struct Args { #[arg(short, long)] diff --git a/src/main/benches/main.rs b/src/main/benches/main.rs index e05052fa..d7211caa 100644 --- a/src/main/benches/main.rs +++ b/src/main/benches/main.rs @@ -1,7 +1,7 @@ use criterion::{Criterion, criterion_group, criterion_main}; use tracing::Level; -use tuwunel::Server; -use tuwunel_core::{Args, result::ErrLog, runtime}; +use tuwunel::{Args, Server, runtime}; +use tuwunel_core::result::ErrLog; criterion_group!( name = benches; @@ -31,5 +31,5 @@ fn smoke(c: &mut Criterion) { }) .unwrap(); - tuwunel::shutdown(&server.server, runtime).unwrap(); + tuwunel::shutdown(&server, runtime).unwrap(); } diff --git a/src/main/lib.rs b/src/main/lib.rs index 2ccd1d29..cefb9a53 100644 --- a/src/main/lib.rs +++ b/src/main/lib.rs @@ -1,19 +1,24 @@ #![type_length_limit = "4096"] //TODO: reduce me +pub mod args; pub mod logging; pub mod mods; pub mod restart; +pub mod runtime; pub mod sentry; pub mod server; pub mod signals; use std::sync::Arc; -pub use tuwunel_core::runtime::shutdown; -use tuwunel_core::{Result, Runtime, debug_info, error, mod_ctor, mod_dtor, rustc_flags_capture}; +use tuwunel_core::{Result, debug_info, error, mod_ctor, mod_dtor, rustc_flags_capture}; use tuwunel_service::Services; -pub use self::server::Server; +pub use self::{ + args::Args, + runtime::{Runtime, shutdown}, + server::Server, +}; mod_ctor! {} mod_dtor! {} @@ -21,7 +26,7 @@ rustc_flags_capture! {} pub fn exec(server: &Arc, runtime: Runtime) -> Result { run(server, &runtime)?; - shutdown(&server.server, runtime) + shutdown(server, runtime) } pub fn run(server: &Arc, runtime: &Runtime) -> Result { diff --git a/src/main/main.rs b/src/main/main.rs index 2aa89b4c..9d95e2db 100644 --- a/src/main/main.rs +++ b/src/main/main.rs @@ -1,7 +1,7 @@ use std::sync::atomic::Ordering; -use tuwunel::{Server, restart}; -use tuwunel_core::{Result, args, debug_info, runtime}; +use tuwunel::{Server, args, restart, runtime}; +use tuwunel_core::{Result, debug_info}; fn main() -> Result { let args = args::parse(); diff --git a/src/core/runtime.rs b/src/main/runtime.rs similarity index 93% rename from src/core/runtime.rs rename to src/main/runtime.rs index 1592959e..34a03f60 100644 --- a/src/core/runtime.rs +++ b/src/main/runtime.rs @@ -10,14 +10,15 @@ use std::{ use tokio::runtime::Builder; pub use tokio::runtime::{Handle, Runtime}; - #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] -use crate::result::LogDebugErr; -use crate::{ - Args, Result, Server, debug, is_true, +use tuwunel_core::result::LogDebugErr; +use tuwunel_core::{ + Result, debug, is_true, utils::sys::compute::{nth_core_available, set_affinity}, }; +use crate::{Args, Server}; + const WORKER_NAME: &str = "tuwunel:worker"; const WORKER_MIN: usize = 2; const WORKER_KEEPALIVE: u64 = 36; @@ -102,11 +103,12 @@ pub fn shutdown(server: &Arc, runtime: Runtime) -> Result { wait_shutdown(server, runtime); let runtime_metrics = server + .server .metrics .runtime_interval() .unwrap_or_default(); - crate::event!(LEVEL, ?runtime_metrics, "Final runtime metrics"); + tuwunel_core::event!(LEVEL, ?runtime_metrics, "Final runtime metrics"); Ok(()) } @@ -127,7 +129,7 @@ fn wait_shutdown(_server: &Arc, runtime: Runtime) { // Join any jemalloc threads so they don't appear in use at exit. #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] - crate::alloc::je::background_thread_enable(false) + tuwunel_core::alloc::je::background_thread_enable(false) .log_debug_err() .ok(); } @@ -173,7 +175,7 @@ fn set_worker_affinity() { #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] fn set_worker_mallctl(id: usize) { - use crate::alloc::je::{ + use tuwunel_core::alloc::je::{ is_affine_arena, this_thread::{set_arena, set_muzzy_decay}, }; @@ -186,7 +188,8 @@ fn set_worker_mallctl(id: usize) { .get() .expect("GC_MUZZY initialized by runtime::new()"); - let muzzy_auto_disable = crate::utils::available_parallelism() >= DISABLE_MUZZY_THRESHOLD; + let muzzy_auto_disable = + tuwunel_core::utils::available_parallelism() >= DISABLE_MUZZY_THRESHOLD; if matches!(muzzy_option, Some(false) | None if muzzy_auto_disable) { set_muzzy_decay(-1).log_debug_err().ok(); @@ -240,7 +243,7 @@ fn thread_park() { fn gc_on_park() { #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] - crate::alloc::je::this_thread::decay() + tuwunel_core::alloc::je::this_thread::decay() .log_debug_err() .ok(); } diff --git a/src/main/server.rs b/src/main/server.rs index 74f4bd7e..de68b7f0 100644 --- a/src/main/server.rs +++ b/src/main/server.rs @@ -2,15 +2,14 @@ use std::{path::PathBuf, sync::Arc}; use tokio::sync::Mutex; use tuwunel_core::{ - Args, Error, Result, args, + Error, Result, config::Config, implement, info, log::Log, - runtime, utils::{stream, sys}, }; -use crate::logging::TracingFlameGuard; +use crate::{Args, args, logging::TracingFlameGuard, runtime}; /// Server runtime state; complete pub struct Server { diff --git a/src/main/tests/smoke.rs b/src/main/tests/smoke.rs index cc1d2a1f..13f507f8 100644 --- a/src/main/tests/smoke.rs +++ b/src/main/tests/smoke.rs @@ -1,8 +1,8 @@ #![cfg(test)] use insta::{assert_debug_snapshot, with_settings}; -use tuwunel::Server; -use tuwunel_core::{Args, Result, runtime}; +use tuwunel::{Args, Server, runtime}; +use tuwunel_core::Result; #[test] fn dummy() {} diff --git a/src/main/tests/smoke_async.rs b/src/main/tests/smoke_async.rs index e50955d3..9e228005 100644 --- a/src/main/tests/smoke_async.rs +++ b/src/main/tests/smoke_async.rs @@ -1,8 +1,8 @@ #![cfg(test)] use insta::{assert_debug_snapshot, with_settings}; -use tuwunel::Server; -use tuwunel_core::{Args, Result, runtime}; +use tuwunel::{Args, Server, runtime}; +use tuwunel_core::Result; #[test] fn smoke_async() -> Result { @@ -17,7 +17,7 @@ fn smoke_async() -> Result { tuwunel::async_exec(&server).await }); - runtime::shutdown(&server.server, runtime)?; + runtime::shutdown(&server, runtime)?; assert_debug_snapshot!(result); result }) diff --git a/src/main/tests/smoke_shutdown.rs b/src/main/tests/smoke_shutdown.rs index 9008a84d..bdb94c41 100644 --- a/src/main/tests/smoke_shutdown.rs +++ b/src/main/tests/smoke_shutdown.rs @@ -2,8 +2,8 @@ use insta::{assert_debug_snapshot, with_settings}; use tracing::Level; -use tuwunel::Server; -use tuwunel_core::{Args, Result, runtime, utils::result::ErrLog}; +use tuwunel::{Args, Server, runtime}; +use tuwunel_core::{Result, utils::result::ErrLog}; #[test] fn smoke_shutdown() -> Result { @@ -22,7 +22,7 @@ fn smoke_shutdown() -> Result { tuwunel::async_stop(&server).await }); - runtime::shutdown(&server.server, runtime)?; + runtime::shutdown(&server, runtime)?; assert_debug_snapshot!(result); result })