gate libloading to conduwuit_mods feature and cfg only

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2025-01-10 10:46:32 -05:00
parent 53d03bbb1f
commit 4c2999ccd1
10 changed files with 38 additions and 9 deletions

View file

@ -212,6 +212,8 @@
# be expected on non-debug builds. # be expected on non-debug builds.
"jemalloc_prof" "jemalloc_prof"
"jemalloc_stats" "jemalloc_stats"
# conduwuit_mods is a development-only hot reload feature
"conduwuit_mods"
]; ];
}; };
all-features-debug = scopeHost.main.override { all-features-debug = scopeHost.main.override {
@ -224,6 +226,8 @@
"hardened_malloc" "hardened_malloc"
# dont include experimental features # dont include experimental features
"experimental" "experimental"
# conduwuit_mods is a development-only hot reload feature
"conduwuit_mods"
]; ];
}; };
hmalloc = scopeHost.main.override { features = ["hardened_malloc"]; }; hmalloc = scopeHost.main.override { features = ["hardened_malloc"]; };
@ -241,6 +245,8 @@
# be expected on non-debug builds. # be expected on non-debug builds.
"jemalloc_prof" "jemalloc_prof"
"jemalloc_stats" "jemalloc_stats"
# conduwuit_mods is a development-only hot reload feature
"conduwuit_mods"
]; ];
}; };
}; };
@ -255,6 +261,8 @@
"hardened_malloc" "hardened_malloc"
# dont include experimental features # dont include experimental features
"experimental" "experimental"
# conduwuit_mods is a development-only hot reload feature
"conduwuit_mods"
]; ];
}; };
}; };
@ -330,6 +338,8 @@
# be expected on non-debug builds. # be expected on non-debug builds.
"jemalloc_prof" "jemalloc_prof"
"jemalloc_stats" "jemalloc_stats"
# conduwuit_mods is a development-only hot reload feature
"conduwuit_mods"
]; ];
}; };
} }
@ -349,6 +359,8 @@
# be expected on non-debug builds. # be expected on non-debug builds.
"jemalloc_prof" "jemalloc_prof"
"jemalloc_stats" "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); 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" "hardened_malloc"
# dont include experimental features # dont include experimental features
"experimental" "experimental"
# conduwuit_mods is a development-only hot reload feature
"conduwuit_mods"
]; ];
}; };
} }
@ -423,6 +437,8 @@
# be expected on non-debug builds. # be expected on non-debug builds.
"jemalloc_prof" "jemalloc_prof"
"jemalloc_stats" "jemalloc_stats"
# conduwuit_mods is a development-only hot reload feature
"conduwuit_mods"
]; ];
}; };
}; };
@ -444,6 +460,8 @@
# be expected on non-debug builds. # be expected on non-debug builds.
"jemalloc_prof" "jemalloc_prof"
"jemalloc_stats" "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); 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" "hardened_malloc"
# dont include experimental features # dont include experimental features
"experimental" "experimental"
# conduwuit_mods is a development-only hot reload feature
"conduwuit_mods"
]; ];
}; };
}; };
@ -510,6 +530,8 @@
# be expected on non-debug builds. # be expected on non-debug builds.
"jemalloc_prof" "jemalloc_prof"
"jemalloc_stats" "jemalloc_stats"
# conduwuit_mods is a development-only hot reload feature
"conduwuit_mods"
]; ];
}; };
})); }));

View file

@ -50,6 +50,9 @@ zstd_compression = [
] ]
perf_measurements = [] perf_measurements = []
sentry_telemetry = [] sentry_telemetry = []
conduwuit_mods = [
"dep:libloading"
]
[dependencies] [dependencies]
argon2.workspace = true argon2.workspace = true
@ -75,6 +78,7 @@ ipaddress.workspace = true
itertools.workspace = true itertools.workspace = true
libc.workspace = true libc.workspace = true
libloading.workspace = true libloading.workspace = true
libloading.optional = true
log.workspace = true log.workspace = true
num-traits.workspace = true num-traits.workspace = true
rand.workspace = true rand.workspace = true

View file

@ -25,7 +25,7 @@ pub use crate as conduwuit_core;
rustc_flags_capture! {} rustc_flags_capture! {}
#[cfg(not(conduwuit_mods))] #[cfg(any(not(conduwuit_mods), not(feature = "conduwuit_mods")))]
pub mod mods { pub mod mods {
#[macro_export] #[macro_export]
macro_rules! mod_ctor { macro_rules! mod_ctor {

View file

@ -1,4 +1,4 @@
#![cfg(conduwuit_mods)] #![cfg(all(conduwuit_mods, feature = "conduwuit_mods"))]
pub(crate) use libloading::os::unix::{Library, Symbol}; pub(crate) use libloading::os::unix::{Library, Symbol};

View file

@ -59,7 +59,7 @@ impl Server {
} }
pub fn reload(&self) -> Result<()> { 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"); return Err!("Reloading not enabled");
} }

View file

@ -135,6 +135,9 @@ zstd_compression = [
"conduwuit-database/zstd_compression", "conduwuit-database/zstd_compression",
"conduwuit-router/zstd_compression", "conduwuit-router/zstd_compression",
] ]
conduwuit_mods = [
"conduwuit-core/conduwuit_mods",
]
[dependencies] [dependencies]
conduwuit-admin.workspace = true conduwuit-admin.workspace = true

View file

@ -37,7 +37,7 @@ fn main() -> Result<(), Error> {
/// Operate the server normally in release-mode static builds. This will start, /// Operate the server normally in release-mode static builds. This will start,
/// run and stop the server within the asynchronous runtime. /// run and stop the server within the asynchronous runtime.
#[cfg(not(conduwuit_mods))] #[cfg(any(not(conduwuit_mods), not(feature = "conduwuit_mods")))]
#[tracing::instrument( #[tracing::instrument(
name = "main", name = "main",
parent = None, parent = None,
@ -89,7 +89,7 @@ async fn async_main(server: &Arc<Server>) -> Result<(), Error> {
/// Operate the server in developer-mode dynamic builds. This will start, run, /// 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 /// 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. /// 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<Server>) -> Result<(), Error> { async fn async_main(server: &Arc<Server>) -> Result<(), Error> {
let mut starts = true; let mut starts = true;
let mut reloads = true; let mut reloads = true;

View file

@ -1,4 +1,4 @@
#![cfg(conduwuit_mods)] #![cfg(all(conduwuit_mods, feature = "conduwuit_mods"))]
#[unsafe(no_link)] #[unsafe(no_link)]
extern crate conduwuit_service; extern crate conduwuit_service;

View file

@ -23,7 +23,7 @@ pub(crate) struct Server {
#[cfg(feature = "sentry_telemetry")] #[cfg(feature = "sentry_telemetry")]
_sentry_guard: Option<::sentry::ClientInitGuard>, _sentry_guard: Option<::sentry::ClientInitGuard>,
#[cfg(conduwuit_mods)] #[cfg(all(conduwuit_mods, feature = "conduwuit_mods"))]
// Module instances; TODO: move to mods::loaded mgmt vector // Module instances; TODO: move to mods::loaded mgmt vector
pub(crate) mods: tokio::sync::RwLock<Vec<conduwuit::mods::Module>>, pub(crate) mods: tokio::sync::RwLock<Vec<conduwuit::mods::Module>>,
} }
@ -75,7 +75,7 @@ impl Server {
#[cfg(feature = "sentry_telemetry")] #[cfg(feature = "sentry_telemetry")]
_sentry_guard: sentry_guard, _sentry_guard: sentry_guard,
#[cfg(conduwuit_mods)] #[cfg(all(conduwuit_mods, feature = "conduwuit_mods"))]
mods: tokio::sync::RwLock::new(Vec::new()), mods: tokio::sync::RwLock::new(Vec::new()),
})) }))
} }

View file

@ -12,7 +12,7 @@ pub(super) async fn signal(server: Arc<Server>) {
use unix::SignalKind; use unix::SignalKind;
const CONSOLE: bool = cfg!(feature = "console"); 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 quit = unix::signal(SignalKind::quit()).expect("SIGQUIT handler");
let mut term = unix::signal(SignalKind::terminate()).expect("SIGTERM handler"); let mut term = unix::signal(SignalKind::terminate()).expect("SIGTERM handler");