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

I'm now imagining a distro using relibc (rust implementation of POSIX libc from RedoxOS) and uutils.


I currently build my nixOS packages with musl, clang, and uutils, and the difference from gcc/coreutils/glibc is unnoticeable. The uutils project is great


How does Rust work with dynamic linking? I thought it didn't?


Rust can dynamically link to/like a library written in C if you really want it to.

https://doc.rust-lang.org/nomicon/ffi.html


That's the inverse of my question. If Rust is going to replace things written in C, other stuff is going to want to dynamically link to it.

A statically compiled Rust based replacement for an entire distribution isn't a realistic proposition, unless you fancy downloading a gig or two every time there's a security update and everything has to be rebuilt.


It is possible to use Rust shared objects in C (and other languages) with the "cdylib" or "staticlib" crate types and when the Rust functions are marked with 'extern "C"'. See https://docs.rust-embedded.org/book/interoperability/rust-wi... and https://doc.rust-lang.org/reference/linkage.html. The YouTube video https://www.youtube.com/watch?v=5zmaLhSAkNE has an example/demo and Jon Gjengset has the "Reverse FFI" section in his "Crust of Rust: Build Scripts and Foreign-Function Interfaces (FFI)" video at 2:02:57 https://www.youtube.com/watch?v=pePqWoTnSmQ&t=7378s. Finally, https://prog.world/building-and-using-dynamic-link-libraries... is yes another article on "Building and using dynamic link libraries in Rust".


Theoretically, you could dynamically link with other Rust code that exposes the standard C ABI. This used to be common for C++ code, when name mangling was different between different compilers and versions - so a C++ library that wanted to be portable had to expose a C ABI, and C++ apps would dynamically link to it by calling that C ABI. Of course, this meant no exceptions, no destructors, no std:: data structures, but such was the price.




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

Search: