Skip to content

Commit

Permalink
Reduce release binary size (#72)
Browse files Browse the repository at this point in the history
* Switch from clap to argh

* Add code size release optimizations
  • Loading branch information
twizmwazin authored Jan 24, 2024
1 parent 611c4d9 commit 94f9a13
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[workspace]
members = ["crates/*"]
resolver = "2"


[profile.release]
codegen-units = 1
lto = true
panic = "abort"
strip = true
opt-level = "s"
5 changes: 2 additions & 3 deletions crates/bh_agent_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 11 additions & 8 deletions crates/bh_agent_server/src/main.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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::<Args>();

// Setup runtime
let rt = runtime::Builder::new_multi_thread()
Expand Down

0 comments on commit 94f9a13

Please sign in to comment.