Make all modules feature-gated to improve compile time
This commit is contained in:
20
src/lib.rs
20
src/lib.rs
@@ -1,14 +1,20 @@
|
||||
#[cfg(feature = "task")]
|
||||
pub use lb::chan;
|
||||
#[cfg(feature = "fs")]
|
||||
pub use lb::fs;
|
||||
#[cfg(feature = "net")]
|
||||
pub use lb::net;
|
||||
#[cfg(feature = "task")]
|
||||
pub use lb::task;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn load_modules(runtime: &mut lb::runtime::Builder) {
|
||||
// core modules
|
||||
runtime
|
||||
.module::<task::lb_tasklib>("lb:task")
|
||||
.module::<chan::lb_chanlib>("lb:channel")
|
||||
.module::<fs::lb_fslib>("lb:fs")
|
||||
.module::<net::lb_netlib>("lb:net");
|
||||
pub fn open(#[allow(unused)] rt: &mut lb::runtime::Builder) {
|
||||
#[cfg(feature = "task")]
|
||||
rt.module::<task::lb_tasklib>("lb:task");
|
||||
#[cfg(feature = "task")]
|
||||
rt.module::<chan::lb_chanlib>("lb:channel");
|
||||
#[cfg(feature = "fs")]
|
||||
rt.module::<fs::lb_fslib>("lb:fs");
|
||||
#[cfg(feature = "net")]
|
||||
rt.module::<net::lb_netlib>("lb:net");
|
||||
}
|
||||
|
||||
23
src/main.rs
23
src/main.rs
@@ -1,9 +1,7 @@
|
||||
use clap::Parser;
|
||||
use mimalloc::MiMalloc;
|
||||
use owo_colors::OwoColorize;
|
||||
use std::{
|
||||
backtrace::Backtrace, fmt::Display, net::SocketAddr, num::NonZero, panic, process, thread,
|
||||
};
|
||||
use std::{backtrace::Backtrace, fmt::Display, num::NonZero, panic, process, thread};
|
||||
use sysexits::ExitCode;
|
||||
|
||||
#[global_allocator]
|
||||
@@ -84,10 +82,12 @@ struct Args {
|
||||
blocking_threads: NonZero<usize>,
|
||||
|
||||
/// Enable tokio-console integration.
|
||||
#[cfg(feature = "tokio-console")]
|
||||
#[clap(long, help_heading = "Debugging")]
|
||||
enable_console: bool,
|
||||
|
||||
/// tokio-console publish address.
|
||||
#[cfg(feature = "tokio-console")]
|
||||
#[clap(
|
||||
long,
|
||||
help_heading = "Debugging",
|
||||
@@ -95,7 +95,7 @@ struct Args {
|
||||
default_value = "127.0.0.1:6669",
|
||||
requires = "enable_console"
|
||||
)]
|
||||
console_addr: SocketAddr,
|
||||
console_addr: std::net::SocketAddr,
|
||||
|
||||
/// Dump internal data.
|
||||
#[clap(
|
||||
@@ -162,7 +162,7 @@ fn unwrap_exit<T, E: Display>(code: ExitCode) -> impl FnOnce(E) -> T {
|
||||
|
||||
fn init_logger(args: &Args) {
|
||||
use tracing::level_filters::LevelFilter;
|
||||
use tracing_subscriber::{Layer, util::*};
|
||||
use tracing_subscriber::util::*;
|
||||
|
||||
let log = tracing_subscriber::fmt()
|
||||
.compact()
|
||||
@@ -176,16 +176,19 @@ fn init_logger(args: &Args) {
|
||||
.with_target(false)
|
||||
.finish();
|
||||
|
||||
if args.enable_console {
|
||||
#[cfg(feature = "tokio-console")]
|
||||
{
|
||||
use tracing_subscriber::Layer;
|
||||
console_subscriber::ConsoleLayer::builder()
|
||||
.with_default_env()
|
||||
.server_addr(args.console_addr)
|
||||
.spawn()
|
||||
.with_subscriber(log)
|
||||
.init()
|
||||
} else {
|
||||
log.init()
|
||||
.init();
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "tokio-console"))]
|
||||
log.init();
|
||||
}
|
||||
|
||||
fn init_tokio(args: &Args) -> tokio::runtime::Runtime {
|
||||
@@ -207,7 +210,7 @@ fn init_tokio(args: &Args) -> tokio::runtime::Runtime {
|
||||
|
||||
fn init_lua(args: &Args) -> lb::runtime::Runtime {
|
||||
let mut rt = lb::runtime::Builder::new();
|
||||
luby::load_modules(&mut rt);
|
||||
luby::open(&mut rt);
|
||||
|
||||
if args.dump.iter().find(|s| *s == "cdef").is_some() {
|
||||
print!("{}", rt.registry());
|
||||
|
||||
Reference in New Issue
Block a user