News for hackers. Stuff that matters.
Re:GitUI: Terminal UI for Git by efficax on Saturday September 17, 2022 @08:32PM (#32883117)
rust binaries are statically linked, that's the big difference. If you included all the libc code statically in most c programs they'd probably also be pretty big
Re:GitUI: Terminal UI for Git by elcritch on Saturday September 17, 2022 @10:16PM (#32883742)
Go programs are also statically linked and Go based CLI tools generally only come in at 3-4 MB IIRC. I've used static linking in binaries in Nim and C programs too with similar (or smaller) sizes.

Rust binaries are just impressively large. I'd guess part of it must be how Rust monomorphizes generics: https://rustc-dev-guide.rust-lang.org/backend/monomorph.html

Re:GitUI: Terminal UI for Git by stjohnswarts on Sunday September 18, 2022 @02:29AM (#32884976)
if you strip them you tend to lose a lot of the fat.
Re:GitUI: Terminal UI for Git by elcritch on Sunday September 18, 2022 @05:02AM (#32885763)
Nice, any tips on how to do that? Is there a Cargo thing or just run regular ole strip?
Re:GitUI: Terminal UI for Git by styluss on Sunday September 18, 2022 @03:44PM (#32890797)
Re:GitUI: Terminal UI for Git by synergy20 on Sunday September 18, 2022 @12:34PM (#32888923)
strip will help to some extent, like 20% downsize, just not enough
Re:GitUI: Terminal UI for Git by synergy20 on Saturday September 17, 2022 @11:49PM (#32884250)
when i have an embedded board with say 64mb storage,a few rust executable will fill them up fast. problem is that rust does not give me option to do dynamic link to its stdlib.
Re:GitUI: Terminal UI for Git by MarkSweep on Sunday September 18, 2022 @12:58AM (#32884548)
Not that this is based on some Googleing and experimentation; I could not find official docs.

It actually is possible to dynamically link to the standard library. Add this to your project's .cargo/config.toml file:

    [build]
    rustflags = ["-C", "prefer-dynamic"]
And add a reference to this crate, which copies the stdlib's shared library to your output directory:

https://github.com/WilliamVenner/prefer-dynamic

After you do `cargo build --release`, you will notice you hello world EXE is much smaller than a typical rust binary. Like 10~20KB small. On Windows it runs just fine. On Linux, I has to change the exe's RPATH to look for the standard library in the current directory:

    patchelf --set-rpath '$ORIGIN' ./exe_name
Anyways, it is possible. The rustc compiler itself is shipped in this way.
Re:GitUI: Terminal UI for Git by synergy20 on Sunday September 18, 2022 @08:31AM (#32886998)
as far as i know,this is not officially supported.rust links to its stdlib statically by design. when you have to share this stdlib with a few dynamically linked rust crates it's hard to do in practice.

tried all size reduction tricks,still the size is much large,like 15x large than c,c++. even the stdlib is a 3x larger than to libstdc++

Re:GitUI: Terminal UI for Git by thayne on Sunday September 18, 2022 @12:21AM (#32884395)
by default rust doesn't statically link to libc.