On 01/30/2017 01:29 AM, Fabio Valentini wrote:
1) Is there support for building and distributing rust libraries as
shared libraries (.so files), if the crate supports it?
If not, this could lead to at least one problem ... any software package
using a rust library via a FFI (as described at [0]) would have to build
the crate itself and bundle the library. I don't think this is feasible
in the long run (every package having to build the create itself and
every package having to include the .so file looks like a lot of wasted
work, time and space to me).
Additionally, I generally dislike linking everything statically (like
golang does), and would much prefer if fedora supported building and
distributing rust libraries from the start. ;)
The biggest problem is that Rust has no defined ABI:
https://github.com/rust-lang/rfcs/issues/600
I've written about this before, several times, for instance here:
https://bugzilla.redhat.com/show_bug.cgi?id=915043#c68
The gist is that while static linking is painful, dynamic linking on an
unstable ABI is even worse.
Now, that's only for Rust<->Rust. In the case of FFI, you're actually
using a C ABI, and this should be fine. Dynamic linking should be
preferred for both Rust making FFI calls and for Rust providing FFI for
other languages to call.
For the latter, the crate should either build as a "cdylib", or emit
objects or a staticlib that's later linked into a larger .so, like the
latest librsvg is doing.
https://github.com/GNOME/librsvg/tree/master/rust
Hmm, that's an old version of the book, and FWIW that section appears to
be chopped from the current version. There's still the FFI chapter, but
it only has a brief section on calling into Rust:
https://doc.rust-lang.org/book/ffi.html#calling-rust-code-from-c