Make all modules feature-gated to improve compile time
This commit is contained in:
parent
2078dd0d8e
commit
31b5ff5ab9
61
Cargo.lock
generated
61
Cargo.lock
generated
@ -1031,14 +1031,12 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
|||||||
name = "lb"
|
name = "lb"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"camino",
|
|
||||||
"derive_more",
|
"derive_more",
|
||||||
"luaffi",
|
"luaffi",
|
||||||
"luajit",
|
"luajit",
|
||||||
"sysexits",
|
"sysexits",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1103,16 +1101,6 @@ version = "0.8.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956"
|
checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lock_api"
|
|
||||||
version = "0.4.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"scopeguard",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.27"
|
version = "0.4.27"
|
||||||
@ -1326,29 +1314,6 @@ version = "4.2.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e"
|
checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "parking_lot"
|
|
||||||
version = "0.12.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13"
|
|
||||||
dependencies = [
|
|
||||||
"lock_api",
|
|
||||||
"parking_lot_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "parking_lot_core"
|
|
||||||
version = "0.9.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"libc",
|
|
||||||
"redox_syscall",
|
|
||||||
"smallvec",
|
|
||||||
"windows-targets 0.52.6",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.1"
|
version = "2.3.1"
|
||||||
@ -1523,15 +1488,6 @@ dependencies = [
|
|||||||
"getrandom 0.2.16",
|
"getrandom 0.2.16",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "redox_syscall"
|
|
||||||
version = "0.5.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.11.1"
|
version = "1.11.1"
|
||||||
@ -1622,12 +1578,6 @@ version = "1.0.20"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "scopeguard"
|
|
||||||
version = "1.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver"
|
name = "semver"
|
||||||
version = "1.0.26"
|
version = "1.0.26"
|
||||||
@ -1684,15 +1634,6 @@ version = "1.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "signal-hook-registry"
|
|
||||||
version = "1.4.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "simdutf8"
|
name = "simdutf8"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
@ -1849,9 +1790,7 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio",
|
||||||
"parking_lot",
|
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"signal-hook-registry",
|
|
||||||
"socket2",
|
"socket2",
|
||||||
"tokio-macros",
|
"tokio-macros",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
13
Cargo.toml
13
Cargo.toml
@ -30,17 +30,24 @@ repository.workspace = true
|
|||||||
dev.panic = "abort"
|
dev.panic = "abort"
|
||||||
release.panic = "abort"
|
release.panic = "abort"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["task", "fs", "net"]
|
||||||
|
task = ["lb/task"]
|
||||||
|
fs = ["lb/fs"]
|
||||||
|
net = ["lb/net"]
|
||||||
|
tokio-console = ["dep:console-subscriber"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.40", features = ["derive", "env"] }
|
clap = { version = "4.5.40", features = ["derive", "env"] }
|
||||||
console-subscriber = "0.4.1"
|
console-subscriber = { version = "0.4.1", optional = true }
|
||||||
lb = { path = "crates/lb" }
|
lb = { path = "crates/lb" }
|
||||||
luajit = { path = "crates/luajit", features = ["runtime"] }
|
luajit = { path = "crates/luajit", features = ["runtime"] }
|
||||||
mimalloc = "0.1.47"
|
mimalloc = "0.1.47"
|
||||||
owo-colors = "4.2.1"
|
owo-colors = "4.2.1"
|
||||||
sysexits = "0.9.0"
|
sysexits = "0.9.0"
|
||||||
tokio = { version = "1.45.1", features = ["full", "tracing"] }
|
tokio = { version = "1.45.1", features = ["rt", "rt-multi-thread"] }
|
||||||
tracing = "0.1.41"
|
tracing = "0.1.41"
|
||||||
tracing-subscriber = "0.3.19"
|
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
vergen-git2 = { version = "1.0.7", features = ["cargo", "rustc"] }
|
vergen-git2 = { version = "1.0.7", features = ["cargo", "rustc"] }
|
||||||
|
@ -7,12 +7,15 @@ authors.workspace = true
|
|||||||
homepage.workspace = true
|
homepage.workspace = true
|
||||||
repository.workspace = true
|
repository.workspace = true
|
||||||
|
|
||||||
|
[features]
|
||||||
|
task = []
|
||||||
|
fs = ["tokio/fs"]
|
||||||
|
net = ["tokio/net"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
camino = "1.1.10"
|
|
||||||
derive_more = { version = "2.0.1", features = ["full"] }
|
derive_more = { version = "2.0.1", features = ["full"] }
|
||||||
luaffi = { path = "../luaffi" }
|
luaffi = { path = "../luaffi" }
|
||||||
luajit = { path = "../luajit" }
|
luajit = { path = "../luajit" }
|
||||||
sysexits = "0.9.0"
|
sysexits = "0.9.0"
|
||||||
thiserror = "2.0.12"
|
thiserror = "2.0.12"
|
||||||
tokio = { version = "1.45.1", features = ["rt", "time", "fs", "net", "process", "signal", "tracing"] }
|
tokio = { version = "1.45.1", features = ["rt"] }
|
||||||
tracing = "0.1.41"
|
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
pub mod chan;
|
|
||||||
pub mod fs;
|
|
||||||
pub mod net;
|
|
||||||
pub mod runtime;
|
pub mod runtime;
|
||||||
|
|
||||||
|
#[cfg(feature = "task")]
|
||||||
|
pub mod chan;
|
||||||
|
#[cfg(feature = "fs")]
|
||||||
|
pub mod fs;
|
||||||
|
#[cfg(feature = "net")]
|
||||||
|
pub mod net;
|
||||||
|
#[cfg(feature = "task")]
|
||||||
pub mod task;
|
pub mod task;
|
||||||
|
20
src/lib.rs
20
src/lib.rs
@ -1,14 +1,20 @@
|
|||||||
|
#[cfg(feature = "task")]
|
||||||
pub use lb::chan;
|
pub use lb::chan;
|
||||||
|
#[cfg(feature = "fs")]
|
||||||
pub use lb::fs;
|
pub use lb::fs;
|
||||||
|
#[cfg(feature = "net")]
|
||||||
pub use lb::net;
|
pub use lb::net;
|
||||||
|
#[cfg(feature = "task")]
|
||||||
pub use lb::task;
|
pub use lb::task;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn load_modules(runtime: &mut lb::runtime::Builder) {
|
pub fn open(#[allow(unused)] rt: &mut lb::runtime::Builder) {
|
||||||
// core modules
|
#[cfg(feature = "task")]
|
||||||
runtime
|
rt.module::<task::lb_tasklib>("lb:task");
|
||||||
.module::<task::lb_tasklib>("lb:task")
|
#[cfg(feature = "task")]
|
||||||
.module::<chan::lb_chanlib>("lb:channel")
|
rt.module::<chan::lb_chanlib>("lb:channel");
|
||||||
.module::<fs::lb_fslib>("lb:fs")
|
#[cfg(feature = "fs")]
|
||||||
.module::<net::lb_netlib>("lb:net");
|
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 clap::Parser;
|
||||||
use mimalloc::MiMalloc;
|
use mimalloc::MiMalloc;
|
||||||
use owo_colors::OwoColorize;
|
use owo_colors::OwoColorize;
|
||||||
use std::{
|
use std::{backtrace::Backtrace, fmt::Display, num::NonZero, panic, process, thread};
|
||||||
backtrace::Backtrace, fmt::Display, net::SocketAddr, num::NonZero, panic, process, thread,
|
|
||||||
};
|
|
||||||
use sysexits::ExitCode;
|
use sysexits::ExitCode;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
@ -84,10 +82,12 @@ struct Args {
|
|||||||
blocking_threads: NonZero<usize>,
|
blocking_threads: NonZero<usize>,
|
||||||
|
|
||||||
/// Enable tokio-console integration.
|
/// Enable tokio-console integration.
|
||||||
|
#[cfg(feature = "tokio-console")]
|
||||||
#[clap(long, help_heading = "Debugging")]
|
#[clap(long, help_heading = "Debugging")]
|
||||||
enable_console: bool,
|
enable_console: bool,
|
||||||
|
|
||||||
/// tokio-console publish address.
|
/// tokio-console publish address.
|
||||||
|
#[cfg(feature = "tokio-console")]
|
||||||
#[clap(
|
#[clap(
|
||||||
long,
|
long,
|
||||||
help_heading = "Debugging",
|
help_heading = "Debugging",
|
||||||
@ -95,7 +95,7 @@ struct Args {
|
|||||||
default_value = "127.0.0.1:6669",
|
default_value = "127.0.0.1:6669",
|
||||||
requires = "enable_console"
|
requires = "enable_console"
|
||||||
)]
|
)]
|
||||||
console_addr: SocketAddr,
|
console_addr: std::net::SocketAddr,
|
||||||
|
|
||||||
/// Dump internal data.
|
/// Dump internal data.
|
||||||
#[clap(
|
#[clap(
|
||||||
@ -162,7 +162,7 @@ fn unwrap_exit<T, E: Display>(code: ExitCode) -> impl FnOnce(E) -> T {
|
|||||||
|
|
||||||
fn init_logger(args: &Args) {
|
fn init_logger(args: &Args) {
|
||||||
use tracing::level_filters::LevelFilter;
|
use tracing::level_filters::LevelFilter;
|
||||||
use tracing_subscriber::{Layer, util::*};
|
use tracing_subscriber::util::*;
|
||||||
|
|
||||||
let log = tracing_subscriber::fmt()
|
let log = tracing_subscriber::fmt()
|
||||||
.compact()
|
.compact()
|
||||||
@ -176,16 +176,19 @@ fn init_logger(args: &Args) {
|
|||||||
.with_target(false)
|
.with_target(false)
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
if args.enable_console {
|
#[cfg(feature = "tokio-console")]
|
||||||
|
{
|
||||||
|
use tracing_subscriber::Layer;
|
||||||
console_subscriber::ConsoleLayer::builder()
|
console_subscriber::ConsoleLayer::builder()
|
||||||
.with_default_env()
|
.with_default_env()
|
||||||
.server_addr(args.console_addr)
|
.server_addr(args.console_addr)
|
||||||
.spawn()
|
.spawn()
|
||||||
.with_subscriber(log)
|
.with_subscriber(log)
|
||||||
.init()
|
.init();
|
||||||
} else {
|
|
||||||
log.init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "tokio-console"))]
|
||||||
|
log.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_tokio(args: &Args) -> tokio::runtime::Runtime {
|
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 {
|
fn init_lua(args: &Args) -> lb::runtime::Runtime {
|
||||||
let mut rt = lb::runtime::Builder::new();
|
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() {
|
if args.dump.iter().find(|s| *s == "cdef").is_some() {
|
||||||
print!("{}", rt.registry());
|
print!("{}", rt.registry());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user