HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
johnthagen
min-sized-rust
Rust2019–2026
johnthagen / min-sized-rust

min-sized-rust

🦀 How to minimize Rust binary size 📦 https://github.com/johnthagen/min-sized-rust

48Distinct people
55Mentions
0Explicit recommenders
9.9KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

🦀 How to minimize Rust binary size 📦 https://github.com/johnthagen/min-sized-rust

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:56:07 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year55 dated mentions

Observed mentions: 2019-04-26 20:28:23 UTC to 2026-10-21 10:24:37 UTC.

0369122019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments20192020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 8 mentions; 1 submissions, 7 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 6 mentions; 0 submissions, 6 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 8 mentions; 0 submissions, 8 comments20222023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 10 mentions; 2 submissions, 8 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 11 mentions; 0 submissions, 11 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 7 mentions; 0 submissions, 7 comments2026-01-01 00:00:00 UTC to 2027-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments. Incomplete calendar period.2026*

* An incomplete calendar period is marked with an outlined bar. Its count is not directly comparable with a full period.

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC202
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC817
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC606
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC808
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC1028
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC11011
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC707
2026 (partial)2026-01-01 00:00:00 UTC2027-01-01 00:00:00 UTC303

From the project README

An excerpt from the repository, fetched Nov 13, 2026.

Read the project’s introduction
Minimizing Rust Binary Size 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: $ cargo build --release 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: [profile.release] strip = true # Automatically strip symbols from the binary. Prior to Rust 1.59, run strip directly on the .elf file instead: $ strip target/release/min-sized-rust Optimize For Size Cargo defaults its optimization level to 3 for release builds, which optimizes the binary for speed. To instruct Cargo to optimize for minimal binary size, use the z optimization level in Cargo.toml: [profile.release] opt-level = "z" # Optimize for size. NoteIn some cases the "s" level may result in a smaller binary than "z", as explained in the opt-level documentation: It is recommended to experiment with different levels to find the right balance for your project. There may be surprising results, such as ... the "s" and "z" levels not being necessarily smaller. Enable Link Time Optimization (LTO) By default, Cargo instructs compilation units to be compiled and optimized in isolation. LTO instructs the linker to optimize at the link stage. This can, for example, remove dead code and often times reduces binary size. Enable LTO in Cargo.toml: [profile.release] lto = true Dynamic Linking: Why It Doesn't Work Some might suggest using prefer-dynamic for smaller binaries, but this approach has critical limitations: No stable ABI - binaries break between Rust versions Deployment complexity - requires exact library matches Community consensus - static linking preferred for reliability Reduce Parallel Code Generation Units to Increase Optimization By default, Cargo specifies 16 parallel codegen units for release builds. This improves compile times, but prevents some optimizations. Set this to 1 in Cargo.toml to allow for maximum size reduction optimizations: [profile.release] codegen-units = 1 Abort on Panic ImportantUp to this point, the features discussed to reduce binary size did not have an impact on the behaviour of the program (only its execution speed). This feature does have an impact on behavior. By default, when Rust code encounters a situation when it must call panic!(), it unwinds the stack and produces a helpful backtrace. The unwinding code, however, does require extra binary size. rustc can be instructed to abort immediately rather than unwind, which removes the need for this extra unwinding code. Enable this in Cargo.toml: [profile.release] panic = "abort" Remove Location Details By default, Rust includes file, line, and column information for panic!() and [track_caller] to provide more useful traceback information. This information requires space in the binary and thus increases the size of the compiled binaries. To remove this file, line, and column information, use the unstable rustc -Zlocation-detail flag: $ RUSTFLAGS="-Zlocation-detail=none" cargo +nightly build --release Remove fmt::Debug With the -Zfmt-debug flag you can turn #[derive(Debug)]and {:?} formatting into no-ops. This will ruin output of dbg!(), assert!(), unwrap(), etc., and may break code that unwisely relies on the debug formatting, but it will remove derived fmt functions and their strings. $ RUSTFLAGS="-Zfmt-debug=none" cargo +nightly build --release Optimize libstd with build-std NoteSee also Xargo, the predecessor to build-std. Xargo is currently in maintenance status. NoteExample project is located in the build_std folder. Rust ships pre-built copies of the standard library (libstd) with its toolchains. This means that developers don't need to build libstd every time they build their applications. libstd is statically linked into the binary instead. While this is very convenient there are several drawbacks if a developer is trying to aggressively optimize for size. The prebuilt libstd is optimized for speed, not size. It's not possible to remove portions of libstd that are not used in a particular application (e.g. LTO and panic behaviour). This is where build-std comes in. The build-std feature is able to compile libstd with your application from the source. It does this with the rust-src component that rustup conveniently provides. Install the appropriate toolchain and the rust-src component: $ rustup toolchain install nightly $ rustup component add rust-src --toolchain nightly Build using build-std: # Find your host's target triple. $ rustc -vV ... host: x86_64-apple-darwin # Use that target triple when building with build-std. # Add the =std,panic_abort to the option to make panic = "abort" Cargo.toml option work. # See: https://github.com/rust-lang/wg-cargo-std-aware/issues/56 $ RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none" cargo +nightly build \ -Z build-std=std,panic_abort \ -Z build-std-features="optimize_for_size" \ --target x86_64-apple-darwin --release The optimize_for_size flag provides a hint to libstd that it should try to use algorithms optimized for binary size. More information about it can be found in the tracking issue. On macOS, the final stripped binary size is reduced to 51KB. Remove panic String Formatting with panic=immediate-abort Even if panic = "abort" i
Read the full README on GitHub

What Hacker News says

55 sources
TFA did [0] the most important stuff for minimizing Rust binaries: release mode, LTO, strip, and abort on panic. But there is a lot more you can do if you really care about Rust binary size [1]: remove location details, purge the debug formatters, rebuild the standard library for size, abort with no error message at all, and nuttier stuff. [0]: https://github.com/zion-sati/NetWasm/blob/main/docs/size-and... [1]: https://github.com/johnthagen/min-sized-rust
In C# now beats Rust on WASM size
You can get Rust binaries pretty small: https://github.com/johnthagen/min-sized-rust But in practice it's more like there's an overhead for "hello world" but it's a fixed overhead. So it's really only a problem where you have lots of binaries, e.g. for coreutils. The solution there is a multi-call binary like Busybox that switches on argv[0]. C programs often seem small because you don't see the size of their dependencies directly, but they obviously still take up disk space. In some cases they can be shared but actually the amount of disk space this saves is not very big except for things like libc (which Rust dynamically links) and maybe big libraries like Qt, GTK, X11.
In Garbage collection for Rust: The finalizer frontier
Working with / compiling from source code (portable/non-portable): cosmopolitan libc[0] Each language kinda has own tricks,java[3], rust[4] From [1] : " A comparison of dietlibc, uclibc, musl, and glibc, by the author of musl: http://www.etalabs.net/compare_libcs.html " How to make smaller C and C++ binaries[7] Removing unused code[5] / Exploiting function similarity for code size reduction[6] ------- [0] : a) https://justine.lol/cosmopolitan/ b) size tricks : https://justine.lol/sizetricks/ [1] : Dietlibc - a libc optimized for small size : https://news.ycombinator.com/item?id=21291893 [2] : https://interrupt.memfault.com/blog/dealing-with-large-symbo... [3] : java : https://www.graalvm.org/latest/reference-manual/native-image... [4] minimizing rust : https://github.com/johnthagen/min-sized-rust [5] : https://tetzank.github.io/po
Read the rest
In Ask HN: What are some non-standard ways to reduce the size of executable files?
> a debug build of "hello world!" in Rust clocks in at 3.7mb. (No shade on Rust) This isn't true. It took me two seconds to create a new project, run `cargo build` followed by `ls -hl ./target/debug/helloworld`. That tells me it's 438K, not 3.7MB. Also, this is a debug build, one that contains debug symbols to help with debugging. Release builds would be configured to strip them, and a release binary of hello world clocks in at 343K. And for people who want even smaller binaries, they can follow the instructions at https://github.com/johnthagen/min-sized-rust. Older Rust versions used to include more debug symbols in the build, but they're now stripped out by default.
In Users don't care about your tech stack
This is a good guide on building small Rust binaries: https://github.com/johnthagen/min-sized-rust This talks about going to extreme lengths on making the smallest Rust binary possible, 400 bytes when it was written, https://darkcoding.net/software/a-very-small-rust-binary-ind... The thing is, you lose a lot of nice features when you do this, like panic unwinding, debug symbols, stdlib… for kernel and some embedded development it’s definitely important, but for most use cases, does it matter?
In The Linux Kernel Prepares for Rust 1.77 Upgrade

Showing the 15 most recent of 55 sources. Enable JavaScript to search and browse every indexed mention.

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.