The infamous question of bin file size ;)

Hi all,
I would like to compile my bin for linux with just the minimal bin size at each time and organise
a shared bin file where the standard lib or even other binary could be reused without having to waste too much space for that?... Rust is well crafted in protocols but no need to recompile them at each programs no ? so is it possible to do that ? is there some documentations somewhere ?
if not that would be great to have such feature no ?

hi Alice, I know this famous page of vi, specially the -C prefer-dynamic flag but how to store and link other crate that's not explained ?...

of course there are a lot of things that I miss... but how could I link several bin in order to make them work together from source file ? that would be a huge help for me

You mean like what busybox does? You can't directly link multiple executables together. What you can do is turn each bin into a library exporting a main function and then have a single executable dispatch to the main function of the correct library.

less or more, mostly a way to share the rust runtime and compile only the code of the program itself overall just don't waste memory place by sharing what could be shared ?

In practice I think you'll find there's not as much as you think that can be shared; most of the non-trivial code in Rust's standard library is generic, and you typically cannot easily share generic code in a library.


As a corollary, another thing is that highly optimized, inlined Rust can sometimes delete lots of unused code; this is the main reason opt-level = 3 can sometimes produce smaller binaries than opt-level = 's'. The act of sharing (e.g. via dynamic linking) nearly by definition disables inlining, meaning you might end up with a giant shared library file, without significantly reducing the size of your binaries.

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.