Hacker News new | ask | show | jobs
by orlp 22 days ago
We have it: unsafe extern "C" { }.

An actual stable native Rust ABI sounds like a forward compatibility nightmare.

1 comments

An actual stable native Rust ABI is a prerequisite for distributing libraries as anything other than source code.
Another year or three of insane memory and disk prices and people will come around.

A stable Rust ABI would be nice for not just Rust, especially if they refine or extend (formally or de facto) the SysV ABI to optimize passing and returning of discriminants. That could then smooth the way for developing these features in C and C++, such as a primitive error-result type that saw some brief attention in both C and C++ WGs a couple of years ago. Doing it properly--absolute minimum cost, ABI stable, and cross-language--seemed to require too much orchestration across the ecosystem so enthusiasm and ambition seemed to peter out. The work required for a stable Rust ABI could provide the inertia to get that done.

What is the advantage of doing so? Is it for cases where your source code is confidential but you want to sell access to your library?
Operating systems.

If there's a CVE in tokio, the OS could theoretically publish a patched version of tokio and all apps that depend on that end up using the fixed code.

As it stands now, the OS needs to publish updated versions of all rust apps that depend on tokio.

That's not how it works basically anywhere except in C/C++ apps on Linux.
Yes and no.

Yes, in that it's primarily a linux thing as MS has gone the route of saving off basically all dlls for all their OSes for backwards compatibility (though they still backpatch).

No, in that other than Rust and Go (and maybe a few others that emit single binaries, zig?) this is how it works with OS distributed programming language packages. Python, ruby, java, perl, C#, the OS will for all of them control distribute and update the libs independent of the apps that use them.

Also, C/C++ still make up a huge percentage of all apps in pretty much any OS.

> prerequisite for distributing libraries as anything other than source code.

> Python, ruby, java, perl, C#, the OS will for all of them control distribute and update the libs independent of the apps that use them.

Those are all JIT'ed languages, so they're distributed in source or intermediate form, not as fixed-ABI-shared-libraries.

It's really just C where shared libs really work. Even C++ has wrinkles.

> No, in that other than Rust and Go (and maybe a few others that emit single binaries, zig?) this is how it works with OS distributed programming language packages.

Uhmm... No? E.g.:

- Python has long strongly recommended virtual environments.

- Not to talk about JavaScript which of course manage things per project by default.

- I don't remember what was the state of things in .NET Framework, but in modern .NET NuGet packages are distributed as DLLs with your app.

I don't know other ecosystems well but I believe they aren't different.

Well yes exactly, because essentially nothing else has a stable ABI.
Because only C/C++ apps have stable ABI. Everyone else would love to do it too but they're S.O.L.
That's not true. Scripting languages of course need no ABI. Managed languages like C# and Java often keep compatibility of the bytecode. Only AOT languages like Go and Rust cannot.
Interoperating witt other languages without having to use C as a middleman?
I agree that using the C ABI for interop between arbitrary non-C languages feels weird, but it's not like that wasn't a thing long before Rust ever existed. If you truly want a modern ABI for languages that are not C, something like the WASM component model is probably the closest thing that exists today.
An unstable ABI is entirely sufficient for that, as long as you update both sides in tandem.
Yep, and it also imposes a big security risk relying on a closed binary blob that could be injected anytime with a backdoor.

Afaik, odin seems to get it right requiring libraries to be distributed source only.

There is another thread complaining about compile times and tmp dir sizes.

Stable ABI dramatically improves the problem space there (without necessarily having anything to do with business model).

It's not a strict prerequisite, you can just require the library being distributed to use extern "C".
Well yes, but then your interface is a C ABI. That's fantastic if the side using my library is any language where C is the only common ground. When the application side is Rust though, it leaves a lot to be desired. It would be delicious to actually interface in a way that respects Rust!

Hell, even if all exposed functions and types would need to be fully monomorphized at the interface, it would be a lot nicer to pass a `&'a [i64]` rather than a `const * int64_t` together with a `size_t n` and have to marshall the slice on both sides.

Or to put it another way, it is a strict prerequisite and Rust already meets it via extern "C".
Rust will almost certainly never have a stable ABI by default, and libraries will continue to be compiled from source by default. It might one day have an opt-in stable ABI.
If you can drop the "native" requirement, then Wasm is also a way.
Why would you want libraries in any other format?
Not to waste time and space?