Avatar ·

Why are Rust executables so huge and how to fix it?

Hi everyone! I'm new to Rust and noticed a strange thing: even the simplest program takes up megabytes on disk. I wrote "Hello, World!" — and got 3 MB! In C/C++, the same code weighs kilobytes. What am I doing wrong?\n\nHere's my code:\n\n```rust\nfn main() {\n println!("Hello, world!");\n}\n```\n\nI build it via `cargo build`. The file target/debug/hello.exe is 3.2 MB. Even after `cargo build --release`, the size only decreased to 2.8 MB. Is this normal? I've heard that Rust compiles statically and includes a runtime, but is it really that much?\n\nMaybe I missed some optimization flag? Or is this a Rust feature? The documentation says Rust is a systems language, but such a size for "Hello, World!" looks strange. Please advise how to reduce the binary size? Thanks in advance!\n\nP.S. I'm using Windows.