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 8–Nov 15 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/15/2026, 9:28:18 AM 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

8 sources
> total size of the binary Have you researched this space already[1]? By default Rust doesn't optimize for the resulting binary size, but there are lots of things that can be done to bring size down where you'd expect. > number of dependencies used When this comes up it becomes as much a technical discussion as a philosophical one :) > and compilation time. No arguments there. There are some things that can be done in your project to avoid spending too much time (simplify bounds to minimize recalculation in the type system, avoid proc macros, leverage cfg conditional compilation), but they are work arounds. [1]: https://github.com/johnthagen/min-sized-rust
In Assorted Thoughts on Zig and Rust
Rust is statically linked by default, not sure how D works. Rust still includes some debug features that can give you a stack trace. Size will also depend on the compile options, if LTO was enabled, how much generics were used, how much string printing was used (print is a macro in Rust that generates code at the callsite), etc. Most, if not all, of these can be resolved. See https://github.com/johnthagen/min-sized-rust for aiming for small binary size. This article shows a 93% size reduction, 2.7m -> 200kb, with some relatively simple modifications https://www.collabora.com/news-and-blog/blog/2020/04/28/redu.... Here is someone using Rust for a 3kb demoscene program https://www.codeslow.com/2019/12/tiny-windows-executable-in-....
In Porting a Golang and Rust CLI tool to D
No way are you fitting a normal operating system on there. You can certainly compile rust to fit on there without any trouble though, you just have to try... the same way you have to try to compile any language in that sort of environment really. You can get to about 30kb while still keeping the standard library [1], you can get something with a fully featured web server in a few hundred kb [2]. [1] https://github.com/johnthagen/min-sized-rust [2] https://jamesmunns.com/blog/tinyrocket/
In Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe Systems Programming

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.