I wrote a small program in Rust called cba_blooper. Its purpose is to download files from this funky looper pedal called the Blooper.
It’s the first time I finished a program in Rust. I find Rust programming a nice experience, after a couple of years of intermittent struggle to adapt my existing mental programming models to Rust’s conventions.
When I finished the tool I was surprised by the output size – initially a 5.6MB binary for a tool that basically just calls into libasound
to read and write MIDI. I followed the excellent min-sized-rust guide and got that down to 1.4MB by fixing some obvious mistakes such as actually stripping the binary and building in release mode. But 1.4MB still seems quite big.
Next I ran cargo bloat
and found there were two big dependencies:
- the ‘clap‘ argument parser library
- the ‘regex’ library, pulled in by ‘env_logger‘
I got ‘env_logger’ to shrink by disabling its optional features in Cargo.toml
:
env_logger = { version ="0.10.0", default_features = false, features = [] }
As for ‘clap’, it seems unavoidable that it adds a few hundred KB to the binary. There’s an open issue here to improve that. I haven’t found a more minimal argument parser that looks anywhere near as nice as ‘clap’, so I guess the final binary will stay at 842KB for the time being. As my bin/
directories fill up with Rust programs over the next decade, this overhead will start to add up but it’s fine for now.
It’s thanks to Rust being fun that this tool exists at all. It definitely easier to make a small C program but the story around distribution and dependency management for self-contained C programs is so not-fun that I probably wouldn’t even have bothered writing the tool in the first place.