From 458c651cd4e0f0d40ca22bfa5cc036e8695ab9e3 Mon Sep 17 00:00:00 2001 From: red binder Date: Tue, 21 Apr 2026 21:41:44 +0200 Subject: [PATCH] Fix conditional compilaton --- rnex-core/src/executables/common.rs | 42 +++++++++++++++++------------ rnex-core/src/nex/mod.rs | 8 +++++- rnex-core/src/nex/user.rs | 36 ++++++++++++++++++------- 3 files changed, 58 insertions(+), 28 deletions(-) diff --git a/rnex-core/src/executables/common.rs b/rnex-core/src/executables/common.rs index ec27f43..280ab7f 100644 --- a/rnex-core/src/executables/common.rs +++ b/rnex-core/src/executables/common.rs @@ -10,33 +10,41 @@ use std::sync::Arc; use tokio::net::TcpListener; use std::sync::LazyLock; use std::sync::OnceLock; -use sqlx::postgres::PgPool; - +cfg_if! { + if #[cfg(feature = "datastore")] { + use sqlx::postgres::PgPool; + } +} use log::error; use std::error::Error; use std::string::ToString; +use cfg_if::cfg_if; use crate::reggie::UnitPacketRead; const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip"; -pub static RNEX_DATASTORE_DATABASE_URL: LazyLock = LazyLock::new(|| { - std::env::var("RNEX_DATASTORE_DATABASE_URL") - .expect("RNEX_DATASTORE_DATABASE_URL must be set") -}); +cfg_if! { + if #[cfg(feature = "datastore")] { + pub static RNEX_DATASTORE_DATABASE_URL: LazyLock = LazyLock::new(|| { + std::env::var("RNEX_DATASTORE_DATABASE_URL") + .expect("RNEX_DATASTORE_DATABASE_URL must be set") + }); -pub static DB_POOL: OnceLock = OnceLock::new(); + pub static DB_POOL: OnceLock = OnceLock::new(); -pub fn get_db() -> &'static PgPool { - DB_POOL.get().expect("db_pool not initialized") + pub fn get_db() -> &'static PgPool { + DB_POOL.get().expect("db_pool not initialized") + } + pub static RNEX_DATASTORE_S3_ENDPOINT: LazyLock = LazyLock::new(|| { + std::env::var("RNEX_DATASTORE_S3_ENDPOINT") + .expect("RNEX_DATASTORE_S3_ENDPOINT must be set") + }); + pub static RNEX_DATASTORE_S3_BUCKET: LazyLock = LazyLock::new(|| { + std::env::var("RNEX_DATASTORE_S3_BUCKET") + .expect("RNEX_DATASTORE_S3_BUCKET must be set") + }); + } } -pub static RNEX_DATASTORE_S3_ENDPOINT: LazyLock = LazyLock::new(|| { - std::env::var("RNEX_DATASTORE_S3_ENDPOINT") - .expect("RNEX_DATASTORE_S3_ENDPOINT must be set") -}); -pub static RNEX_DATASTORE_S3_BUCKET: LazyLock = LazyLock::new(|| { - std::env::var("RNEX_DATASTORE_S3_BUCKET") - .expect("RNEX_DATASTORE_S3_BUCKET must be set") -}); pub fn try_get_ip() -> Result> { let mut req = ureq::get(IP_REQ_SERVICE_URL).call()?; diff --git a/rnex-core/src/nex/mod.rs b/rnex-core/src/nex/mod.rs index 91bb866..f54e939 100644 --- a/rnex-core/src/nex/mod.rs +++ b/rnex-core/src/nex/mod.rs @@ -1,3 +1,5 @@ +use cfg_if::cfg_if; + pub mod account; pub mod auth_handler; pub mod common; @@ -6,4 +8,8 @@ pub mod matchmake; pub mod remote_console; pub mod user; pub mod datastore; -pub mod s3presigner; \ No newline at end of file +cfg_if! { + if #[cfg(feature = "datastore")] { + pub mod s3presigner; + } +} \ No newline at end of file diff --git a/rnex-core/src/nex/user.rs b/rnex-core/src/nex/user.rs index f271355..a812d7c 100644 --- a/rnex-core/src/nex/user.rs +++ b/rnex-core/src/nex/user.rs @@ -41,21 +41,37 @@ use rnex_core::prudp::socket_addr::PRUDPSockAddr; use rnex_core::rmc::response::ErrorCode::{Core_InvalidArgument, RendezVous_AccountExpired}; use rnex_core::rmc::structures::qresult::QResult; use std::sync::{Arc, Weak}; +use cfg_if::cfg_if; use rnex_core::rmc::protocols::ranking::{CompetitionRankingScoreData, CompetitionRankingGetParam, CompetitionRankingScoreInfo}; use rnex_core::rmc::structures::ranking::{UploadCompetitionData}; use tokio::sync::{Mutex, RwLock}; -define_rmc_proto!( - proto UserProtocol{ - Secure, - MatchmakeExtension, - MatchmakeExt, - Matchmake, - NatTraversal, - Ranking, - DataStore +cfg_if! { + if #[cfg(feature = "datastore")] { + define_rmc_proto!( + proto UserProtocol{ + Secure, + MatchmakeExtension, + MatchmakeExt, + Matchmake, + NatTraversal, + Ranking, + DataStore + } + ); + } else { + define_rmc_proto!( + proto UserProtocol{ + Secure, + MatchmakeExtension, + MatchmakeExt, + Matchmake, + NatTraversal, + Ranking + } + ); } -); +} #[rmc_struct(UserProtocol)] pub struct User {