Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How do you get self-contained binaries with Rust? There's a lot of talk but I've not found a definitive "produces a static library" build guide.


As my sibling commentor says, they're the default. There are some details though:

Rust uses glibc by default, which must be dynamically linked. It's usually the only thing that's dynamic about Rust binaries, but it does mean that compiling on on old CentOS box is a decent idea if you want a wide range of compatibility.

Alternatively, you can use MUSL, which works like this:

    $ rustup target add x86_64-unknown-linux-musl
    $ cargo build --target=x86_64-unknown-linux-musl
Boom, now libc is statically linked too.

The default is that all Rust code is statically linked, but since you may link C code as well, that may or may not be statically linked. It's done by packages, so there's no real default. Many of them default to static and provide the option of dynamic.

That's why there's not really a guide, that's really all there is to it.


They're the default, even when you include 100+ packages via Cargo. The only issue I've faced is standard Linux cross-distro issues due to libc versions. Even most of the crates that handle bindings to C libraries link them statically by default.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: