Binary size in Linux and Freebsd

Hi there. It is my first participation in the forum. I'm starting with Rust, I still did not do anything beyond reading, watching videos and transcribing some examples.

Use FreeBSD and Linux, although I prefer FreeBSD. I noticed something that caught my attention is that the simple example of the book [1] compiled with cargo run --release
The binary in Linux has 3.3MB and the FreeBSD 0.45MB

Why so much difference?

[1] Programming a Guessing Game - The Rust Programming Language
Listing 2-6: Complete guessing game code

Did you try stripping the binary on Linux?

I'm not sure about this - I know very little about FreeBSD - but Rust currently still includes debug symbols even in release mode, and that's typically a good chunk of binary size in my experience (on Linux, vs on Windows where they are stored in separate .pdb files - maybe there is something similar happening on FreeBSD?).

Hello @geeklint

You say that in Linux is leaving debug symbols and in FreeBSD no, and hence the difference in sizes?

Thanks

Rust has a long-standing Linux-specific bug that causes it to add debug symbols of standard library, even if you disabled debug symbols.

On Linux you have to manually strip executables, always.

If executable size is a concern for you, see other recommendations: GitHub - johnthagen/min-sized-rust: 🦀 How to minimize Rust binary size 📦

Hello @kornel

More than a concern is a curiosity. As I said I prefer to use FreeBSD over Linux, only that this caught me this difference.

My doubt is already answered.

Thank you very much

Jose

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.