fix unnecessary preprocessing cfgs

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-14 10:55:39 +00:00
parent cce270d938
commit 95006f7e46

View file

@ -1,23 +1,29 @@
use figment::Figment; use figment::Figment;
use super::DEPRECATED_KEYS; use super::DEPRECATED_KEYS;
use crate::{debug, error, info, warn, Config, Err, Result}; use crate::{debug, debug_info, error, info, warn, Config, Err, Result};
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
pub fn check(config: &Config) -> Result<()> { pub fn check(config: &Config) -> Result<()> {
#[cfg(debug_assertions)] if cfg!(debug_assertions) {
info!("Note: conduwuit was built without optimisations (i.e. debug build)"); info!("Note: conduwuit was built without optimisations (i.e. debug build)");
}
#[cfg(all(feature = "rocksdb", not(feature = "sha256_media")))] // prevents catching this in `--all-features` // prevents catching this in `--all-features`
if cfg!(all(feature = "rocksdb", not(feature = "sha256_media"))) {
warn!( warn!(
"Note the rocksdb feature was deleted from conduwuit. SQLite support was removed and RocksDB is the only \ "Note the rocksdb feature was deleted from conduwuit. SQLite support was removed and RocksDB is the only \
supported backend now. Please update your build script to remove this feature." supported backend now. Please update your build script to remove this feature."
); );
#[cfg(all(feature = "sha256_media", not(feature = "rocksdb")))] // prevents catching this in `--all-features` }
// prevents catching this in `--all-features`
if cfg!(all(feature = "sha256_media", not(feature = "rocksdb"))) {
warn!( warn!(
"Note the sha256_media feature was deleted from conduwuit, it is now fully integrated in a \ "Note the sha256_media feature was deleted from conduwuit, it is now fully integrated in a \
forwards-compatible way. Please update your build script to remove this feature." forwards-compatible way. Please update your build script to remove this feature."
); );
}
warn_deprecated(config); warn_deprecated(config);
warn_unknown_key(config); warn_unknown_key(config);
@ -26,28 +32,27 @@ pub fn check(config: &Config) -> Result<()> {
return Err!(Config("sentry_endpoint", "Sentry cannot be enabled without an endpoint set")); return Err!(Config("sentry_endpoint", "Sentry cannot be enabled without an endpoint set"));
} }
#[cfg(all(feature = "hardened_malloc", feature = "jemalloc"))] if cfg!(all(feature = "hardened_malloc", feature = "jemalloc")) {
warn!( warn!(
"hardened_malloc and jemalloc are both enabled, this causes jemalloc to be used. If using --all-features, \ "hardened_malloc and jemalloc are both enabled, this causes jemalloc to be used. If using --all-features, \
this is harmless." this is harmless."
); );
}
#[cfg(not(unix))] if cfg!(not(unix)) && config.unix_socket_path.is_some() {
if config.unix_socket_path.is_some() {
return Err!(Config( return Err!(Config(
"unix_socket_path", "unix_socket_path",
"UNIX socket support is only available on *nix platforms. Please remove \"unix_socket_path\" from your \ "UNIX socket support is only available on *nix platforms. Please remove 'unix_socket_path' from your \
config.", config."
)); ));
} }
#[cfg(unix)] if cfg!(unix) && config.unix_socket_path.is_none() {
if config.unix_socket_path.is_none() {
config.get_bind_addrs().iter().for_each(|addr| { config.get_bind_addrs().iter().for_each(|addr| {
use std::path::Path; use std::path::Path;
if addr.ip().is_loopback() { if addr.ip().is_loopback() {
crate::debug_info!("Found loopback listening address {addr}, running checks if we're in a container.",); debug_info!("Found loopback listening address {addr}, running checks if we're in a container.");
if Path::new("/proc/vz").exists() /* Guest */ && !Path::new("/proc/bz").exists() if Path::new("/proc/vz").exists() /* Guest */ && !Path::new("/proc/bz").exists()
/* Host */ /* Host */
@ -90,8 +95,7 @@ pub fn check(config: &Config) -> Result<()> {
} }
// yeah, unless the user built a debug build hopefully for local testing only // yeah, unless the user built a debug build hopefully for local testing only
#[cfg(not(debug_assertions))] if cfg!(not(debug_assertions)) && config.server_name == "your.server.name" {
if config.server_name == "your.server.name" {
return Err!(Config( return Err!(Config(
"server_name", "server_name",
"You must specify a valid server name for production usage of conduwuit." "You must specify a valid server name for production usage of conduwuit."