{"repo":"johnthagen/min-sized-rust","free":true,"listed":false,"github":"https://github.com/johnthagen/min-sized-rust","clone":"git clone https://github.com/johnthagen/min-sized-rust.git","description":"🦀 How to minimize Rust binary size 📦 https://github.com/johnthagen/min-sized-rust","language":"Rust","stars":9835,"topics":["rust","binary-size","cargo","containers","upx","lto","strip","wasm","no-std"],"license":"MIT","category":"deployment-docker-iac","readme_excerpt":"Minimizing Rust Binary Size [![GitHub Actions][github-actions-badge]](https://github.com/johnthagen/min-sized-rust/actions) [github-actions-badge]: https://github.com/johnthagen/min-sized-rust/workflows/build/badge.svg This repository demonstrates how to minimize the size of a Rust binary. By default, Rust optimizes for execution speed, compilation speed, and ease of debugging rather than binary size, since for the vast majority of applications this is ideal. But for situations where a developer wants to optimize for binary size instead, Rust provides mechanisms to accomplish this. Build in Release Mode By default, cargo build builds the Rust binary in debug mode. Debug mode disables many optimizations, which helps debuggers (and IDEs that run them) provide a better debugging experience. Debug binaries can be 30% or more larger than release binaries. To minimize binary size, build in release mode: strip Symbols from Binary By default on Linux and macOS, symbol information is included in the compiled .elf file. This information is not needed to properly execute the binary. Cargo can be configured to automatically strip binaries. Modify Cargo.toml in this way: Prior to Rust 1.59 , run strip directly on the .elf file instead: Optimize For Size [Cargo defaults its optimization level to 3 for release builds][cargo-profile], which optimizes the binary for speed . To instruct Cargo to optimize for minimal binary size , use the z optimization level in Cargo.toml : [cargo-profile]: ht","default_branch":null,"files":null,"tree":[],"storefront":"/r/johnthagen","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/johnthagen/min-sized-rust/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}