Hacker News new | ask | show | jobs
by mischief6 876 days ago
not a rust programmer. can someone explain why this is in the final binary and not in a shared library?
1 comments

The Rust compiler statically links everything into a single binary. This can be changed, but is generally discouraged as there are no ABI stability guarantees at this point.
You can use the C ABI if you want something stable, and there are custom crates that will help with translating from the Rust to the C ABI. (This also helps because the resulting shared objects can potentially be FFI'd with from any language, not just Rust. They might as well be plain C libraries as far as anyone is concerned, only with the usual Rust safety requirements.)
Also, even in "the" C ABI provided by Rust out of the box there's a certain amount of "Well, this is probably what your C compiler does here, but there's no requirement" rather than an actual hard ABI document. A lot of the "We're ABI stable" claims in C and C++ are "We daren't change anything or stuff breaks" which isn't so much an ABI as it is paralysis and Rust is confident it doesn't want to do that.
> A lot of the "We're ABI stable" claims in C and C++ are "We daren't change anything or stuff breaks" which isn't so much an ABI as it is paralysis

For the C++ standary library maybe, but for pretty much all others which provide ABI compatibility it's a concious and properly followed decision.

> "We're ABI stable" claims in C and C++ are "We daren't change anything or stuff breaks" which isn't so much an ABI as it is paralysis and Rust is confident it doesn't want to do that.

For C++, yes sure, but I thought C usually has a pretty well specified ABI on most platforms, no?

I think it's true for common enough platforms, but C is available in too many platforms so I'm not sure it's generally true.