feat: Make 'server' feature optional and add compile-time check

Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-10 10:33:47 -03:00
parent c5eb6d140a
commit d9a36012bc
4 changed files with 25 additions and 9 deletions

View File

@@ -11,7 +11,7 @@ categories = ["command-line-utilities"]
[dependencies]
anyhow = "1.0.72"
axum = "0.8.4"
axum = { version = "0.8.4", optional = true }
derive_more = { version = "2.0", features = ["full"] }
smart-default = "0.7"
thiserror = "1.0"
@@ -56,9 +56,9 @@ term = "1.1.0"
tokio = { version = "1.0", features = ["full"] }
tokio-stream = "0.1"
tokio-util = "0.7.16"
tower = "0.5.2"
tower-http = { version = "0.6.6", features = ["cors", "fs", "trace"] }
utoipa = { version = "5.4.0", features = ["axum_extras"] }
tower = { version = "0.5.2", optional = true }
tower-http = { version = "0.6.6", features = ["cors", "fs", "trace"], optional = true }
utoipa = { version = "5.4.0", features = ["axum_extras"], optional = true }
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"], optional = true }
uzers = "0.12.1"
which = "8.0.0"
@@ -69,7 +69,10 @@ pest_derive = "2.8.1"
[features]
# Default features include core compression engines and swagger UI
default = ["magic", "gzip", "lz4", "swagger"]
default = ["server", "magic", "gzip", "lz4", "swagger"]
# Server feature (includes axum and related dependencies)
server = ["dep:axum", "dep:tower", "dep:tower-http", "dep:utoipa"]
# Compression features
gzip = ["flate2"]

View File

@@ -8,8 +8,8 @@ pub mod compression_engine;
pub mod config;
pub mod services;
pub mod db;
#[cfg(feature = "server")]
pub mod meta_plugin;
pub mod filter_plugin;
pub mod modes;
pub mod plugins;
pub mod args;

View File

@@ -1,4 +1,3 @@
use anyhow::{Context, Error, Result, anyhow};
use clap::*;
use clap::error::ErrorKind;
@@ -203,7 +202,19 @@ fn main() -> Result<(), Error> {
KeepModes::Info => modes::info::mode_info(&mut cmd, &settings, ids, tags, &mut conn, data_path),
KeepModes::Status => modes::status::mode_status(&mut cmd, &settings, data_path, db_path),
KeepModes::StatusPlugins => modes::status_plugins::mode_status_plugins(&mut cmd, &settings, data_path, db_path),
KeepModes::Server => modes::server::mode_server(&mut cmd, &settings, &mut conn, data_path),
KeepModes::Server => {
#[cfg(feature = "server")]
{
modes::server::mode_server(&mut cmd, &settings, &mut conn, data_path)
}
#[cfg(not(feature = "server"))]
{
cmd.error(
ErrorKind::MissingRequiredArgument,
"This binary was not compiled with server support. Recompile with --features server"
).exit();
}
},
KeepModes::GenerateConfig => modes::generate_config::mode_generate_config(&mut cmd, &settings),
KeepModes::Unknown => unreachable!(),
}

View File

@@ -1,3 +1,5 @@
#[cfg(feature = "server")]
pub mod server;
pub mod common;
pub mod delete;
pub mod diff;
@@ -6,7 +8,6 @@ pub mod get;
pub mod info;
pub mod list;
pub mod save;
pub mod server;
pub mod status;
pub mod status_plugins;
@@ -18,6 +19,7 @@ pub use get::mode_get;
pub use info::mode_info;
pub use list::mode_list;
pub use save::mode_save;
#[cfg(feature = "server")]
pub use server::mode_server;
pub use status::mode_status;
pub use status_plugins::mode_status_plugins;