Move args and runtime back to main from core (1313eb0b64).

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-10-04 03:29:19 +00:00
parent 53ab6742c8
commit 4743a8d968
10 changed files with 38 additions and 36 deletions

View File

@@ -1,7 +1,6 @@
#![type_length_limit = "12288"] #![type_length_limit = "12288"]
pub mod alloc; pub mod alloc;
pub mod args;
pub mod config; pub mod config;
pub mod debug; pub mod debug;
pub mod error; pub mod error;
@@ -10,7 +9,6 @@ pub mod log;
pub mod matrix; pub mod matrix;
pub mod metrics; pub mod metrics;
pub mod mods; pub mod mods;
pub mod runtime;
pub mod server; pub mod server;
pub mod utils; pub mod utils;
@@ -22,14 +20,12 @@ pub use ::smallstr;
pub use ::smallvec; pub use ::smallvec;
pub use ::toml; pub use ::toml;
pub use ::tracing; pub use ::tracing;
pub use args::Args;
pub use config::Config; pub use config::Config;
pub use error::Error; pub use error::Error;
pub use info::{rustc_flags_capture, version, version::version}; pub use info::{rustc_flags_capture, version, version::version};
pub use matrix::{ pub use matrix::{
Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, RoomVersion, pdu, state_res, Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, RoomVersion, pdu, state_res,
}; };
pub use runtime::Runtime;
pub use server::Server; pub use server::Server;
pub use utils::{ctor, dtor, implement, result, result::Result}; pub use utils::{ctor, dtor, implement, result, result::Result};

View File

@@ -3,8 +3,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use clap::{ArgAction, Parser}; use clap::{ArgAction, Parser};
use tuwunel_core::{
use crate::{
Err, Result, Err, Result,
config::{Figment, FigmentValue}, config::{Figment, FigmentValue},
err, toml, err, toml,
@@ -17,7 +16,7 @@ use crate::{
about, about,
long_about = None, long_about = None,
name = "tuwunel", name = "tuwunel",
version = crate::version(), version = tuwunel_core::version(),
)] )]
pub struct Args { pub struct Args {
#[arg(short, long)] #[arg(short, long)]

View File

@@ -1,7 +1,7 @@
use criterion::{Criterion, criterion_group, criterion_main}; use criterion::{Criterion, criterion_group, criterion_main};
use tracing::Level; use tracing::Level;
use tuwunel::Server; use tuwunel::{Args, Server, runtime};
use tuwunel_core::{Args, result::ErrLog, runtime}; use tuwunel_core::result::ErrLog;
criterion_group!( criterion_group!(
name = benches; name = benches;
@@ -31,5 +31,5 @@ fn smoke(c: &mut Criterion) {
}) })
.unwrap(); .unwrap();
tuwunel::shutdown(&server.server, runtime).unwrap(); tuwunel::shutdown(&server, runtime).unwrap();
} }

View File

@@ -1,19 +1,24 @@
#![type_length_limit = "4096"] //TODO: reduce me #![type_length_limit = "4096"] //TODO: reduce me
pub mod args;
pub mod logging; pub mod logging;
pub mod mods; pub mod mods;
pub mod restart; pub mod restart;
pub mod runtime;
pub mod sentry; pub mod sentry;
pub mod server; pub mod server;
pub mod signals; pub mod signals;
use std::sync::Arc; use std::sync::Arc;
pub use tuwunel_core::runtime::shutdown; use tuwunel_core::{Result, debug_info, error, mod_ctor, mod_dtor, rustc_flags_capture};
use tuwunel_core::{Result, Runtime, debug_info, error, mod_ctor, mod_dtor, rustc_flags_capture};
use tuwunel_service::Services; use tuwunel_service::Services;
pub use self::server::Server; pub use self::{
args::Args,
runtime::{Runtime, shutdown},
server::Server,
};
mod_ctor! {} mod_ctor! {}
mod_dtor! {} mod_dtor! {}
@@ -21,7 +26,7 @@ rustc_flags_capture! {}
pub fn exec(server: &Arc<Server>, runtime: Runtime) -> Result { pub fn exec(server: &Arc<Server>, runtime: Runtime) -> Result {
run(server, &runtime)?; run(server, &runtime)?;
shutdown(&server.server, runtime) shutdown(server, runtime)
} }
pub fn run(server: &Arc<Server>, runtime: &Runtime) -> Result { pub fn run(server: &Arc<Server>, runtime: &Runtime) -> Result {

View File

@@ -1,7 +1,7 @@
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use tuwunel::{Server, restart}; use tuwunel::{Server, args, restart, runtime};
use tuwunel_core::{Result, args, debug_info, runtime}; use tuwunel_core::{Result, debug_info};
fn main() -> Result { fn main() -> Result {
let args = args::parse(); let args = args::parse();

View File

@@ -10,14 +10,15 @@ use std::{
use tokio::runtime::Builder; use tokio::runtime::Builder;
pub use tokio::runtime::{Handle, Runtime}; pub use tokio::runtime::{Handle, Runtime};
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
use crate::result::LogDebugErr; use tuwunel_core::result::LogDebugErr;
use crate::{ use tuwunel_core::{
Args, Result, Server, debug, is_true, Result, debug, is_true,
utils::sys::compute::{nth_core_available, set_affinity}, utils::sys::compute::{nth_core_available, set_affinity},
}; };
use crate::{Args, Server};
const WORKER_NAME: &str = "tuwunel:worker"; const WORKER_NAME: &str = "tuwunel:worker";
const WORKER_MIN: usize = 2; const WORKER_MIN: usize = 2;
const WORKER_KEEPALIVE: u64 = 36; const WORKER_KEEPALIVE: u64 = 36;
@@ -102,11 +103,12 @@ pub fn shutdown(server: &Arc<Server>, runtime: Runtime) -> Result {
wait_shutdown(server, runtime); wait_shutdown(server, runtime);
let runtime_metrics = server let runtime_metrics = server
.server
.metrics .metrics
.runtime_interval() .runtime_interval()
.unwrap_or_default(); .unwrap_or_default();
crate::event!(LEVEL, ?runtime_metrics, "Final runtime metrics"); tuwunel_core::event!(LEVEL, ?runtime_metrics, "Final runtime metrics");
Ok(()) Ok(())
} }
@@ -127,7 +129,7 @@ fn wait_shutdown(_server: &Arc<Server>, runtime: Runtime) {
// Join any jemalloc threads so they don't appear in use at exit. // Join any jemalloc threads so they don't appear in use at exit.
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] #[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() .log_debug_err()
.ok(); .ok();
} }
@@ -173,7 +175,7 @@ fn set_worker_affinity() {
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
fn set_worker_mallctl(id: usize) { fn set_worker_mallctl(id: usize) {
use crate::alloc::je::{ use tuwunel_core::alloc::je::{
is_affine_arena, is_affine_arena,
this_thread::{set_arena, set_muzzy_decay}, this_thread::{set_arena, set_muzzy_decay},
}; };
@@ -186,7 +188,8 @@ fn set_worker_mallctl(id: usize) {
.get() .get()
.expect("GC_MUZZY initialized by runtime::new()"); .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) { if matches!(muzzy_option, Some(false) | None if muzzy_auto_disable) {
set_muzzy_decay(-1).log_debug_err().ok(); set_muzzy_decay(-1).log_debug_err().ok();
@@ -240,7 +243,7 @@ fn thread_park() {
fn gc_on_park() { fn gc_on_park() {
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
crate::alloc::je::this_thread::decay() tuwunel_core::alloc::je::this_thread::decay()
.log_debug_err() .log_debug_err()
.ok(); .ok();
} }

View File

@@ -2,15 +2,14 @@ use std::{path::PathBuf, sync::Arc};
use tokio::sync::Mutex; use tokio::sync::Mutex;
use tuwunel_core::{ use tuwunel_core::{
Args, Error, Result, args, Error, Result,
config::Config, config::Config,
implement, info, implement, info,
log::Log, log::Log,
runtime,
utils::{stream, sys}, utils::{stream, sys},
}; };
use crate::logging::TracingFlameGuard; use crate::{Args, args, logging::TracingFlameGuard, runtime};
/// Server runtime state; complete /// Server runtime state; complete
pub struct Server { pub struct Server {

View File

@@ -1,8 +1,8 @@
#![cfg(test)] #![cfg(test)]
use insta::{assert_debug_snapshot, with_settings}; use insta::{assert_debug_snapshot, with_settings};
use tuwunel::Server; use tuwunel::{Args, Server, runtime};
use tuwunel_core::{Args, Result, runtime}; use tuwunel_core::Result;
#[test] #[test]
fn dummy() {} fn dummy() {}

View File

@@ -1,8 +1,8 @@
#![cfg(test)] #![cfg(test)]
use insta::{assert_debug_snapshot, with_settings}; use insta::{assert_debug_snapshot, with_settings};
use tuwunel::Server; use tuwunel::{Args, Server, runtime};
use tuwunel_core::{Args, Result, runtime}; use tuwunel_core::Result;
#[test] #[test]
fn smoke_async() -> Result { fn smoke_async() -> Result {
@@ -17,7 +17,7 @@ fn smoke_async() -> Result {
tuwunel::async_exec(&server).await tuwunel::async_exec(&server).await
}); });
runtime::shutdown(&server.server, runtime)?; runtime::shutdown(&server, runtime)?;
assert_debug_snapshot!(result); assert_debug_snapshot!(result);
result result
}) })

View File

@@ -2,8 +2,8 @@
use insta::{assert_debug_snapshot, with_settings}; use insta::{assert_debug_snapshot, with_settings};
use tracing::Level; use tracing::Level;
use tuwunel::Server; use tuwunel::{Args, Server, runtime};
use tuwunel_core::{Args, Result, runtime, utils::result::ErrLog}; use tuwunel_core::{Result, utils::result::ErrLog};
#[test] #[test]
fn smoke_shutdown() -> Result { fn smoke_shutdown() -> Result {
@@ -22,7 +22,7 @@ fn smoke_shutdown() -> Result {
tuwunel::async_stop(&server).await tuwunel::async_stop(&server).await
}); });
runtime::shutdown(&server.server, runtime)?; runtime::shutdown(&server, runtime)?;
assert_debug_snapshot!(result); assert_debug_snapshot!(result);
result result
}) })