diff --git a/flake.nix b/flake.nix index d8ad47a8..e3497d85 100644 --- a/flake.nix +++ b/flake.nix @@ -212,6 +212,8 @@ # be expected on non-debug builds. "jemalloc_prof" "jemalloc_stats" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" ]; }; all-features-debug = scopeHost.main.override { @@ -224,6 +226,8 @@ "hardened_malloc" # dont include experimental features "experimental" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" ]; }; hmalloc = scopeHost.main.override { features = ["hardened_malloc"]; }; @@ -241,6 +245,8 @@ # be expected on non-debug builds. "jemalloc_prof" "jemalloc_stats" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" ]; }; }; @@ -255,6 +261,8 @@ "hardened_malloc" # dont include experimental features "experimental" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" ]; }; }; @@ -330,6 +338,8 @@ # be expected on non-debug builds. "jemalloc_prof" "jemalloc_stats" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" ]; }; } @@ -349,6 +359,8 @@ # be expected on non-debug builds. "jemalloc_prof" "jemalloc_stats" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" ]; x86_64_haswell_target_optimised = (if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false); }; @@ -367,6 +379,8 @@ "hardened_malloc" # dont include experimental features "experimental" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" ]; }; } @@ -423,6 +437,8 @@ # be expected on non-debug builds. "jemalloc_prof" "jemalloc_stats" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" ]; }; }; @@ -444,6 +460,8 @@ # be expected on non-debug builds. "jemalloc_prof" "jemalloc_stats" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" ]; x86_64_haswell_target_optimised = (if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false); }; @@ -464,6 +482,8 @@ "hardened_malloc" # dont include experimental features "experimental" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" ]; }; }; @@ -510,6 +530,8 @@ # be expected on non-debug builds. "jemalloc_prof" "jemalloc_stats" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" ]; }; })); diff --git a/src/core/Cargo.toml b/src/core/Cargo.toml index 4a9cc462..c716e9c2 100644 --- a/src/core/Cargo.toml +++ b/src/core/Cargo.toml @@ -50,6 +50,9 @@ zstd_compression = [ ] perf_measurements = [] sentry_telemetry = [] +conduwuit_mods = [ + "dep:libloading" +] [dependencies] argon2.workspace = true @@ -75,6 +78,7 @@ ipaddress.workspace = true itertools.workspace = true libc.workspace = true libloading.workspace = true +libloading.optional = true log.workspace = true num-traits.workspace = true rand.workspace = true diff --git a/src/core/mod.rs b/src/core/mod.rs index 87cb58ae..1416ed9e 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -25,7 +25,7 @@ pub use crate as conduwuit_core; rustc_flags_capture! {} -#[cfg(not(conduwuit_mods))] +#[cfg(any(not(conduwuit_mods), not(feature = "conduwuit_mods")))] pub mod mods { #[macro_export] macro_rules! mod_ctor { diff --git a/src/core/mods/mod.rs b/src/core/mods/mod.rs index ac0c333b..b8f06f29 100644 --- a/src/core/mods/mod.rs +++ b/src/core/mods/mod.rs @@ -1,4 +1,4 @@ -#![cfg(conduwuit_mods)] +#![cfg(all(conduwuit_mods, feature = "conduwuit_mods"))] pub(crate) use libloading::os::unix::{Library, Symbol}; diff --git a/src/core/server.rs b/src/core/server.rs index 8a4d9f66..948eea36 100644 --- a/src/core/server.rs +++ b/src/core/server.rs @@ -59,7 +59,7 @@ impl Server { } pub fn reload(&self) -> Result<()> { - if cfg!(not(conduwuit_mods)) { + if cfg!(any(not(conduwuit_mods), not(feature = "conduwuit_mods"))) { return Err!("Reloading not enabled"); } diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 38eb7188..baf5336f 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -135,6 +135,9 @@ zstd_compression = [ "conduwuit-database/zstd_compression", "conduwuit-router/zstd_compression", ] +conduwuit_mods = [ + "conduwuit-core/conduwuit_mods", +] [dependencies] conduwuit-admin.workspace = true diff --git a/src/main/main.rs b/src/main/main.rs index e7aaf3fc..dacc2a2e 100644 --- a/src/main/main.rs +++ b/src/main/main.rs @@ -37,7 +37,7 @@ fn main() -> Result<(), Error> { /// Operate the server normally in release-mode static builds. This will start, /// run and stop the server within the asynchronous runtime. -#[cfg(not(conduwuit_mods))] +#[cfg(any(not(conduwuit_mods), not(feature = "conduwuit_mods")))] #[tracing::instrument( name = "main", parent = None, @@ -89,7 +89,7 @@ async fn async_main(server: &Arc) -> Result<(), Error> { /// Operate the server in developer-mode dynamic builds. This will start, run, /// and hot-reload portions of the server as-needed before returning for an /// actual shutdown. This is not available in release-mode or static builds. -#[cfg(conduwuit_mods)] +#[cfg(all(conduwuit_mods, feature = "conduwuit_mods"))] async fn async_main(server: &Arc) -> Result<(), Error> { let mut starts = true; let mut reloads = true; diff --git a/src/main/mods.rs b/src/main/mods.rs index ca799b90..9ab36e6c 100644 --- a/src/main/mods.rs +++ b/src/main/mods.rs @@ -1,4 +1,4 @@ -#![cfg(conduwuit_mods)] +#![cfg(all(conduwuit_mods, feature = "conduwuit_mods"))] #[unsafe(no_link)] extern crate conduwuit_service; diff --git a/src/main/server.rs b/src/main/server.rs index a81b708d..359a029c 100644 --- a/src/main/server.rs +++ b/src/main/server.rs @@ -23,7 +23,7 @@ pub(crate) struct Server { #[cfg(feature = "sentry_telemetry")] _sentry_guard: Option<::sentry::ClientInitGuard>, - #[cfg(conduwuit_mods)] + #[cfg(all(conduwuit_mods, feature = "conduwuit_mods"))] // Module instances; TODO: move to mods::loaded mgmt vector pub(crate) mods: tokio::sync::RwLock>, } @@ -75,7 +75,7 @@ impl Server { #[cfg(feature = "sentry_telemetry")] _sentry_guard: sentry_guard, - #[cfg(conduwuit_mods)] + #[cfg(all(conduwuit_mods, feature = "conduwuit_mods"))] mods: tokio::sync::RwLock::new(Vec::new()), })) } diff --git a/src/main/signal.rs b/src/main/signal.rs index 0f541099..cecb718b 100644 --- a/src/main/signal.rs +++ b/src/main/signal.rs @@ -12,7 +12,7 @@ pub(super) async fn signal(server: Arc) { use unix::SignalKind; const CONSOLE: bool = cfg!(feature = "console"); - const RELOADING: bool = cfg!(all(conduwuit_mods, not(CONSOLE))); + const RELOADING: bool = cfg!(all(conduwuit_mods, feature = "conduwuit_mods", not(CONSOLE))); let mut quit = unix::signal(SignalKind::quit()).expect("SIGQUIT handler"); let mut term = unix::signal(SignalKind::terminate()).expect("SIGTERM handler");