I've been playing around with getting my final binaries smaller and after finding #46 I'm somewhat confused about why structopts is the biggest contributor to my binary size after the standard library. What's a little funny is turning default features off grows the final binary so there's nowhere to go but up? This is all on Linux with 1.56.0-nightly but I see the same results in stable.
Here's some experiments:
-rwxrwxr-x 2 me me 3.5M Aug 21 01:27 target/release/test_opts (without structopt code)
-rwxrwxr-x 2 me me 4.1M Aug 21 01:29 target/release/test_opts
-rwxrwxr-x 2 me me 4.2M Aug 21 01:26 target/release/test_opts (after default-features = false)
The code for this:
use structopt::StructOpt;
use std::path::PathBuf;
#[derive(StructOpt, Debug)]
enum ProgramOptions {
New {
#[structopt(parse(from_os_str), help = "File path for new level")]
filename: PathBuf,
#[structopt(short, long, help = "Level name")]
name: String,
#[structopt(short, long, help = "Width for new level")]
width: usize,
#[structopt(short, long, help = "Height for new level")]
height: usize,
},
Load {
#[structopt(parse(from_os_str), help = "File path for new level")]
filename: PathBuf,
}
}
pub fn main() {
// Comment this line out to compare and contrast sizes
parse_args().unwrap();
}
pub fn parse_args() -> Result<(), &'static str> {
let opts = ProgramOptions::from_args();
match opts {
ProgramOptions::New { ref filename, ref name, width, height } => {
let filename = match filename.to_str() {
Some(y) => y,
None => return Err("Unable to parse filename into OS string".into()),
};
println!("Use some vars: {:?}, {}, {}, {}", filename, name, width, height);
},
ProgramOptions::Load { ref filename } => {
let filename = match filename.to_str() {
Some(y) => y,
None => return Err("Unable to parse filename into OS string".into()),
};
println!("Use some vars: {:?}", filename);
}
}
Ok(())
}
I've been playing around with getting my final binaries smaller and after finding #46 I'm somewhat confused about why structopts is the biggest contributor to my binary size after the standard library. What's a little funny is turning default features off grows the final binary so there's nowhere to go but up? This is all on Linux with 1.56.0-nightly but I see the same results in stable.
Here's some experiments:
The code for this: