From 94f9a1391a595a2e8a9bbc6315c45f3fa8ef9c0d Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Tue, 23 Jan 2024 18:05:33 -0700 Subject: [PATCH] Reduce release binary size (#72) * Switch from clap to argh * Add code size release optimizations --- Cargo.toml | 8 ++++++++ crates/bh_agent_server/Cargo.toml | 5 ++--- crates/bh_agent_server/src/main.rs | 19 +++++++++++-------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d767148..391ef62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,11 @@ [workspace] members = ["crates/*"] resolver = "2" + + +[profile.release] +codegen-units = 1 +lto = true +panic = "abort" +strip = true +opt-level = "s" diff --git a/crates/bh_agent_server/Cargo.toml b/crates/bh_agent_server/Cargo.toml index 4fe1199..5c9f61f 100644 --- a/crates/bh_agent_server/Cargo.toml +++ b/crates/bh_agent_server/Cargo.toml @@ -10,13 +10,12 @@ anyhow = "1.0.75" bh_agent_common = { path = "../bh_agent_common" } subprocess = "0.2.9" tarpc = { version = "0.33.0", features = ["full"] } -tokio = { version = "1.32.0", features = ["full"] } -futures-util = "0.3.28" +tokio = { version = "1.32.0", features = ["rt-multi-thread"] } futures = "0.3.28" log = "0.4.20" env_logger = { version = "0.10.0", default-features = false, features = ["auto-color", "humantime"] } bimap = "0.6.3" -clap = { version = "4.4.11", features = ["derive"] } +argh = "0.1.12" [target.'cfg(not(target_os = "windows"))'.dependencies] daemonize = "0.5.0" diff --git a/crates/bh_agent_server/src/main.rs b/crates/bh_agent_server/src/main.rs index a195864..5e5f6d9 100644 --- a/crates/bh_agent_server/src/main.rs +++ b/crates/bh_agent_server/src/main.rs @@ -1,6 +1,6 @@ -use std::net::IpAddr; +use std::{net::IpAddr, process::exit}; -use clap::Parser; +use argh::FromArgs; use futures::{future, prelude::*}; use tarpc::{ server::{self, Channel}, @@ -11,21 +11,24 @@ use tokio::runtime; use bh_agent_common::BhAgentService; use bh_agent_server::BhAgentServer; -#[derive(Parser)] -#[command(author, version, about, long_about = None)] +#[derive(FromArgs)] +/// bh_agent_server struct Args { - /// The address to listen on + /// address to listen on + #[argh(positional)] address: IpAddr, - /// The port to listen on + /// port to listen on + #[argh(positional)] port: u16, #[cfg(not(target_os = "windows"))] - #[arg(short, long, default_value = "false", help = "Daemonize the process")] + /// daemonize the process + #[argh(option, default = "false")] daemonize: bool, } fn main() -> anyhow::Result<()> { env_logger::init(); - let args = Args::parse(); + let args = argh::from_env::(); // Setup runtime let rt = runtime::Builder::new_multi_thread()