|
|
Subscribe / Log in / New account

Packaging Rust for Fedora

Packaging Rust for Fedora

Posted Oct 28, 2022 17:51 UTC (Fri) by khim (subscriber, #9252)
In reply to: Packaging Rust for Fedora by tchernobog
Parent article: Packaging Rust for Fedora

> Just use shared libraries? You seem to be under the impression Rust doesn't support them.

Rust doesn't really support shared libraries. swift does, though and Rust-the-language forces traits model which makes that support not impossible in the future.

That's hard task, though, not something you may demand while Rust developers are doing that development on shoestring budget.


to post comments

Packaging Rust for Fedora

Posted Oct 28, 2022 19:33 UTC (Fri) by tchernobog (guest, #73595) [Link] (7 responses)

You can use #[repr(C)] if you want a stable ABI now.

Else, you can opt to stick with the same rustc version for a few years, and the unstable ABI producing dylibs (".rlib") will be enough.

I mean, it's not like Perl gets upgraded on my Debian system without hundreds of modules going through a mass rebuild. And C++ ABI got calmer only with libstdc++ versioning.

I am just saying: it's not a particularly new film we are seeing. Nor one which has an unsolvable scenario, given enough willingness to fix it.

Packaging Rust for Fedora

Posted Oct 28, 2022 21:08 UTC (Fri) by khim (subscriber, #9252) [Link] (6 responses)

> You can use #[repr(C)] if you want a stable ABI now.

You can't. Ideomatic Rust is built on top Option<T> and Result<T, E> (some language construct don't even accept anything else!) — and these are not #[repr(C)].

Actually you can't even use other generic types without language support similar to what Swift did.

That, basically, means that instead of using shared libraries as, well, libraries, you are creating modules, boundaries of which are almost as hard to cross as boundaries between processes.

At this point making shared libraries makes no sense. Too much pain for too little gain. Better to link in network library and go with multiple processes.

> And C++ ABI got calmer only with libstdc++ versioning.

No. It got calmer when C++ developers have decided: yes, we do want to support shared libraries. Rust developers have never done that.

> Else, you can opt to stick with the same rustc version for a few years, and the unstable ABI producing dylibs (".rlib") will be enough.

This would have worked if Rust releases, like GNAT releases, happened once a year. And even that would have been problematic (I don't think any distribution releases too many shared Ada libraries). But they are released 8 times a year. That's too much churn to realistically support.

You can't go against upstream, basically. If upstream doesn't want to support shared libraries and actively makes that support problematic then they wouldn't be supported.

Packaging Rust for Fedora

Posted Oct 30, 2022 13:31 UTC (Sun) by ssokolow (guest, #94568) [Link] (4 responses)

No. It got calmer when C++ developers have decided: yes, we do want to support shared libraries. Rust developers have never done that.

Whether or not to build a cdylib from a Rust project is certainly a choice upstream makes, but also bear in mind in mind that, unless things have changed since 2012 on the ABI compatibility front, many of the core issues are just as unsolved in C++... it's just less idiomatic to rely on things like templates in C++ than on things like generics in Rust. (See The impact of C++ templates on library ABI by Michał Górny from 2012 for more on that.)

...not to mention, Rust's dependency counts are misleading when you're trying to make comparisons, because C and C++ are rife with bespoke reimplementations and single-header libraries that maintainers just take in stride, rather than trying to split out into their own packages. (See the Gotta go deeper section of Alopex's Let's Be Real About Dependencies for details on that.)

Packaging Rust for Fedora

Posted Oct 30, 2022 14:50 UTC (Sun) by khim (subscriber, #9252) [Link] (3 responses)

> it's just less idiomatic to rely on things like templates in C++ than on things like generics in Rust.

No. The important thing is standard library. It's ideomatic to use it in both C++ and Rust.

And while it's called Standard Template Library libstdc++ developers have decided that they would find a way to make it work as shared library. And they did. Yes, templates are injected in your code, not in the shared library, but certain discipline on the side of libstdc++ developers made it possible.

Swift as we all know picked different road, compiler-based. But, again: standard types and standard templates are usable when you build shared library.

In Rust land… Rust developers have never done that and not even core is offered in a way suitable for use in shared libraries.

That means that shared-library-Rust doesn't even remotely resemble normal std-based Rust. While in C++ the part which can be used as shared library is very much a subset of what you would do in normal C++.

That's pretty big difference: while in C++ it's possible to write code which would be acceptable both in normal C++ project and in shared library, too… in Rust it's just impossible. Without ability to just return Result or accept Option your code is not Rust, it's different language.

In C++, on the other hand, it's perfectly fine to accept std::option or pass std::unique_ptr even in function which is part of shared library.

Packaging Rust for Fedora

Posted Oct 30, 2022 15:02 UTC (Sun) by ssokolow (guest, #94568) [Link] (2 responses)

Fair point... though an argument has also been made that C++'s focus on ABI stability is killing the standard library.

Packaging Rust for Fedora

Posted Oct 30, 2022 16:51 UTC (Sun) by khim (subscriber, #9252) [Link] (1 responses)

There is no free lunch. Either you have ABI-stable standard library or shared libraries are, basically, impossible.

And it's not as if Rust standard library can do sudden, radical, changes. It just wasn't in use for as long as C++ one.

Packaging Rust for Fedora

Posted Oct 30, 2022 17:09 UTC (Sun) by ssokolow (guest, #94568) [Link]

There is no free lunch. Either you have ABI-stable standard library or shared libraries are, basically, impossible.
Or you marshal your data in some way, like the abi_stable crate does for enabling dlopen-able libraries using higher-level Rust constructs via Rust-Rust FFI through the C ABI.
And it's not as if Rust standard library can do sudden, radical, changes. It just wasn't in use for as long as C++ one.
The Rust standard library has two advantages over C++ on that front:
  1. Static linking and no stable ABI (eg. Rust 1.0 didn't do automatic structure packing. That was added later.)
  2. Stronger API encapsulation (Rust has already done things C++ balked at, such as Rust 1.36 swapping out its original, slower HashMap implementation for a vendored copy of a port of Google's SwissTable. There's currently a PR being refined to replace the internals of std::sync::mpsc with a vendored copy of crossbeam-channel.)

Packaging Rust for Fedora

Posted Oct 31, 2022 11:44 UTC (Mon) by DianaNites (subscriber, #160945) [Link]


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds