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"]
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};

View File

@@ -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)]

View File

@@ -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();
}

View File

@@ -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<Server>, runtime: Runtime) -> Result {
run(server, &runtime)?;
shutdown(&server.server, runtime)
shutdown(server, runtime)
}
pub fn run(server: &Arc<Server>, runtime: &Runtime) -> Result {

View File

@@ -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();

View File

@@ -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<Server>, 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<Server>, 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();
}

View File

@@ -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 {

View File

@@ -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() {}

View File

@@ -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
})

View File

@@ -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
})