3 ms·
The innocent looking CLI thingy linked below turns into 68 MB binary when built with cargo build --release https://github.com/mozilla/application-services
by inshadows 6y ago
The innocent looking CLI thingy linked below turns into 68 MB binary when built with
cargo build --release
https://github.com/mozilla/application-services/blob/master/components/tabs/examples/tabs_sync.rs https://github.com/mozilla/application-services/blob/master/...
I don't think Rust can replace C for CLI tools. It feels more like Java with these uber binaries.
- fgonzag 6y agoIsn't that statically compiled though? I haven't checked too much into Rust but I seem to recall it could be dynamically compiled. I would imagine any OS base tools would be dynamically compiled anyways. Though considering the lengths that package managers go to for dependency management, maybe static linking everything is not a bad idea after all, I don't mind a 10GB OS image on disk as long as it isn't actually wasting memory.
- inshadows 6y ago% ldd tabs_sync linux-vdso.so.1 (0x00007fffb06d0000) libdl.so.2 => /usr/lib/libdl.so.2 (0x00007fd523f96000) librt.so.1 => /usr/lib/librt.so.1 (0x00007fd523f8b000) libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007fd523f69000) libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fd523f4f000) libc.so.6 => /usr/lib/libc.so.6 (0x00007fd523d88000) /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007fd52490a000) libm.so.6 => /usr/lib/libm.so.6 (0x00007fd523c43000) It still links to libc. It seems most of it is loads of Mozilla stuff. Oh, the nss lib is actually linked statically. Rust Evangelism Strike Force has struck me already. That was fast!
- gpm 6y agoldd just prints the things it dynamically links, which is basically just libc and related system interface libraries. You want to list then number of things it statically links. If you run cargo clean; cargo build, and check out target/debug/deps you should be able to get a list of all the statically linked rust libraries, which is a subset of all the statically linked libraries. Also, as other people mentioned, this is including debug information and so on. Strip it if you care about size. Rust is perfectly happy to make very small executables, you just have to ask it to.
- nicoburns 6y ago68MB seems excessive. Is that embedding an entire browser engine? (I see it's a Mozilla repo, and importing "TabsEngine"). 1-5MB is more typical, and while it's certainly larger than C binaries, I don't think it's problematic for CLI tools. Unlike Java you still get instant startup. Ripgrep is one of the most popular Rust CLI tools. It has ~2MB binaries: https://github.com/BurntSushi/ripgrep/releases https://github.com/BurntSushi/ripgrep/releases (except the windows GNU variant which is 8MB for some reason, but a ~2MB windows MSVC variant is available). That's certainly a lot bigger than the ~50kb for my system's copy of grep. But it's also faster than grep for most use cases (see: https://blog.burntsushi.net/ripgrep/ https://blog.burntsushi.net/ripgrep/), and has better support for things like unicode. Seems like a pretty good trade-off to me.
- dathinab 6y agoIt's over 50MB debug info (see other comments). Release just specified the profile and you can override settings if it in Cargo.toml, e.g. to include debug info into release builds it disable lto. (Edit) which is done by the linked tool.
- jamesmunns 6y agohttps://github.com/mozilla/application-services/blob/master/Cargo.toml#L39-L42 https://github.com/mozilla/application-services/blob/master/... They include debug info in release builds in their configuration. If you run `strip` on the resulting binary, it will likely drop to like 5 MB.
- inshadows 6y agoWow, it dropped to 9.1 MB. Thanks for the info!