Making Rust binaries smaller by default (kobzol.github.io)
from morrowind@lemmy.ml to rust@programming.dev on 24 Jan 2024 04:21
https://lemmy.ml/post/10963134

Upto 90% for hellworld

#rust

threaded - newest

seth@lemmy.world on 24 Jan 2024 09:08 next collapse

Quite an interesting writeup, going to go check out Rust now (I tell myself for the umpteenth time).

sugar_in_your_tea@sh.itjust.works on 24 Jan 2024 12:17 collapse

Join us, the water is great. :)

bitcrafter@programming.dev on 24 Jan 2024 15:45 collapse

Is that because of the iron supplement?

Lmaydev@programming.dev on 24 Jan 2024 10:43 next collapse

So debug builds now strip it by default as well?

robinm@programming.dev on 24 Jan 2024 11:04 collapse

It’s also what I understood from what I read but I assume it was just a poor choice of word. Debug symbols are way too important for debugging to be stripped by default.

Lmaydev@programming.dev on 24 Jan 2024 11:21 next collapse

I guess it may use external debug symbols and strip them from the binary by default.

Otherwise seems like a massive change haha

OmnipotentEntity@beehaw.org on 24 Jan 2024 12:12 next collapse

As mentioned in the article, this concerns release mode, which already does not have symbols by default for user code. It does have symbols for the standard library code, however, due to how the binaries for the standard library are shipped (i.e. with symbols only). This change simply also removes standard library symbols.

If you need symbols, you can use default debugging build, or if you need both compiler optimizations and debugging symbols you can create a custom profile that inherets from release with debug = true. The second you already need to do to get full debugging symbols right now, so this isn’t really much of a change from a workflow standpoint.

Lmaydev@programming.dev on 24 Jan 2024 13:13 collapse

In fact, this new default will be used for any profile which does not enable debuginfo anywhere in its dependency chain, not just for the release profile.

This is the sentence that tripped me up. But on rereading I’m assuming the debug profile does enable this.

OmnipotentEntity@beehaw.org on 24 Jan 2024 15:06 collapse

Yeah, definitely :)

The default dev profile is defined as:

[profile.dev]
opt-level = 0
debug = true
split-debuginfo = '...'  # Platform-specific.
strip = "none"
debug-assertions = true
overflow-checks = true
lto = false
panic = 'unwind'
incremental = true
codegen-units = 256
rpath = false

You can find more information in the cargo book page on profiles

Lmaydev@programming.dev on 24 Jan 2024 16:01 collapse

I knew I had to be missing something. Thanks for the insight mate.

Lmaydev@programming.dev on 24 Jan 2024 13:14 collapse

In fact, this new default will be used for any profile which does not enable debuginfo anywhere in its dependency chain, not just for the release profile.

On reflection I imagine the debug profile does enable this

robinm@programming.dev on 24 Jan 2024 15:38 collapse

Yeah, this make sence

ExLisper@linux.community on 24 Jan 2024 12:38 collapse

So this is around 4MB less, right? The small app I’m currently working on is 15MB so with this change it will be 11MB. Nice but nothing revolutionary. It will have bigger impact on a really tiny apps. I guess that’s why it wasn’t resolved for so long.