Exploring how small a Rust binary can get, one technique at a time.
Each example builds on the previous one, progressively stripping away overhead until we reach a sub-kilobyte ELF binary.
| # | Example | Technique | Size |
|---|---|---|---|
| 01 | release-opts | Release profile: strip, LTO, opt-level=z | ~297 KB |
| 02 | panic-abort | Add panic=abort via workspace profile | ~297 KB |
| 03 | no-std | Drop std, use libc for write/exit, custom _start |
~13 KB |
| 04 | raw-syscall | Drop libc, inline asm syscalls, custom linker script | 560 B |
| 05 | tiny-wasm | WebAssembly target, no_std cdylib | 554 B |
| 06 | build-std | Rebuild core with -Z build-std, panic_immediate_abort |
~400 B* |
| 07 | global-asm | Assembly entry stub via global_asm! |
~400 B* |
| 08 | upx-compressed | Post-build UPX compression on example 04 | varies |
| 09 | tiny-yes | Endless "y" output, like coreutils yes |
~14 KB |
| 10 | tiny-base64 | Base64 encode/decode stdin filter | ~14 KB |
| 11 | tiny-hash | FNV-1a 64-bit hash of stdin | ~14 KB |
| 12 | tiny-random | Xorshift64 random number generator | ~14 KB |
| 13 | xor-packer | Runtime XOR-decrypt and exec of shellcode | ~14 KB |
| 14 | tiny-cat | Concatenate files/stdin, file descriptor I/O | ~14 KB |
| 15 | tiny-wc | Count lines/words/bytes from stdin | ~14 KB |
| 16 | tiny-multicall | BusyBox-style argv[0] dispatch | ~14 KB |
| 17 | tiny-alloc | Bump allocator, heap without std | ~14 KB |
| 18 | tiny-signal | Signal handling with sigaction | ~14 KB |
| 19 | tiny-mmap | Memory-mapped file I/O, zero-copy | ~14 KB |
| 20 | tiny-server | HTTP server with raw sockets | ~14 KB |
| 21 | tiny-sha256 | SHA-256 hash of stdin (NIST crypto primitive) | ~14 KB |
| 22 | tiny-pipe | Fork + pipe IPC, child/parent messaging | ~14 KB |
| 23 | tiny-portscan | TCP connect scanner, non-blocking I/O | ~14 KB |
| 24 | tiny-sandbox | Chroot + privilege drop + execve | ~14 KB |
| 25 | tiny-udp-echo | UDP echo server with epoll multiplexing | ~14 KB |
| 26 | tiny-x11 | Raw X11 protocol, GUI window via AF_UNIX | ~14 KB |
| 27 | tiny-proxy | TCP port forwarder with poll() | ~14 KB |
| 28 | tiny-revproxy | HTTP reverse proxy with header injection | ~14 KB |
| 29 | tiny-lb | Round-robin HTTP load balancer | ~14 KB |
| 30 | tiny-lb-sticky | IP-hash sticky session load balancer | ~14 KB |
| 31 | tiny-smtp | SMTP mail server, text protocol state machine | ~14 KB |
| 32 | tiny-blockchain | In-memory blockchain with HTTP API, hash chains | ~14 KB |
| 33 | tiny-kv | Hash table key-value store with REST CRUD | ~14 KB |
| 34 | tiny-objstore | Content-addressable object store with dedup | ~14 KB |
| 35 | tiny-transformer | GPT-style transformer with attention, FFN, layer norm | ~14 KB |
| 36 | tiny-gpt2 | GPT-2 Small (124M) inference with real pre-trained weights | ~14 KB |
| 37 | tiny-sql-db | SQL database engine with HTTP API, tokenizer, direct execution | ~14 KB |
| 38 | tiny-kafka-broker | Kafka-like broker: partitioned topics, consumer groups, ring buffers | ~14 KB |
| 39 | tiny-kafka-pubsub | Kafka-style pub/sub broker with topic filters | ~14 KB |
| 40 | tiny-kafka-cluster | Multi-broker Kafka cluster with partitions and consumer groups | ~14 KB |
*Requires nightly toolchain. Exact size depends on toolchain version.
Examples 09-40 are practical utilities proving tiny binaries can do real work, all using the no_std + libc pattern from example 03.
Examples 02-04 and 09-40 are workspace members and build together:
cargo build --releaseExample 01 has its own release profile and builds independently:
cd 01-release-opts && cargo build --releaseExample 05 targets WebAssembly:
cd 05-tiny-wasm && cargo build --release --target wasm32-unknown-unknownExamples 06-07 require nightly:
cd 06-build-std && cargo +nightly build --release
cd 07-global-asm && cargo +nightly build --releaseExample 08 requires UPX:
cd 08-upx-compressed && bash build.sh- Rust stable (for examples 01-05)
- Rust nightly (for examples 06-07):
rustup toolchain install nightly - wasm32 target (for example 05):
rustup target add wasm32-unknown-unknown - UPX (for example 08, optional)
- Linux x86_64 (examples 03-04, 06-07, 13 use Linux syscalls and x86_64 assembly)
The next 100+ examples are mapped out. See docs/ideas/:
- Roadmap -- what to build first, plus 8 themed learning series (Unix toolbox, build a tiny OS, AI from scratch, emulators, compression, and more)
- Idea Catalog -- the full backlog of 248 candidate programs, tiered and grouped by category
- Organizing 100+ Examples -- numbering, status tracking, and navigation scheme for scaling the repo
- Project Classes -- how examples are categorized by class (navigation) and build contract (toolchain), and the
[package.metadata.tiny]scheme - Size Optimization Guide -- techniques ranked by impact with motivations, counterpoints, and measured sizes
- Troubleshooting -- stack alignment SIGSEGV case study, debugging tools reference, and common pitfalls