4 ms·
> Like Go, Rust can compile statically linked linux binaries. The GNU C library (needed not only by C programs for C things) doesn't support static linking, so
by kazinator 8y ago
> Like Go, Rust can compile statically linked linux binaries.
The GNU C library (needed not only by C programs for C things) doesn't support static linking, so the only way this is possible is to use another library entirely, or raw inlined syscalls (where applicable).
- steveklabnik 8y agoYes, we have full support for MUSL. It's a $ rustup target add x86_64-unknown-linux-musl $ cargo build --target x86_64-unknown-linux-musl away.
- ekidd 8y agoYeah, Rust's musl support is great. We use it heavily at work for all sorts of CLI tools. Many thanks to everybody who worked on this. (And if you need to link against common C libraries like OpenSSL or PostgreSQL, I maintain a Docker image with the necessary C toolchains, and instructions on how to use it: https://github.com/emk/rust-musl-builder https://github.com/emk/rust-musl-builder. There are a couple of similar images out there, too, I think.)
- throwaway23H 8y agoYou can also download the cross-compilation tarball for musl at https://static.rust-lang.org/dist/rust-std-1.31.0-x86_64-unknown-linux-musl.tar.gz https://static.rust-lang.org/dist/rust-std-1.31.0-x86_64-unk... if you installed rust that way. You'd then build normally: $ cargo build --target x86_64-unknown-linux-musl
- dbaupp 8y agoRust's main toolchain has first class support for musl: https://rust-lang-nursery.github.io/edition-guide/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html https://rust-lang-nursery.github.io/edition-guide/rust-2018/...
- jabl 8y agoBy default rust links dynamically to glibc, while rust stuff is statically linked. Which I think is a reasonably good default. Most Linux systems provide glibc, and you can deploy binaries to them without those systems needing a rust installation. Of course, there's the usual issue with glibc symbol versioning, so you probably want to build your binaries on the oldest supported system (say, a centos 6 container).