-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Support dynamic linking with Rust ABI and not C ABI #3075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can already link to Cargo also knows how to link to Provided the crates are all reproducible, the shared objects cargo produces and links to should all be the same for every crate build and therefore it should be sufficient to just keep one of them. |
@nagisa In that case would it possible to pick a Also would it be possible to link a crate that is not defined as I know in case of generics, we would still have to compile the source at call site, but that is minor thing compared to compiling all dependent crates every time. |
not that it fully fixes the issue, but as a temporary measure have you considered something like sccache? |
It'll become interesting if build reproducibility plays some role here. I've no objection since reproducible build becomes super important for many reasons, but it's clearly a dramatic step. :) As raised on internals, we need |
It would be nice to be able to link against pre-compiled dylib, without having to use the C ABI. This becomes very important on large projects, where compiling multiple crates can be time consuming. For example, a game engine, where whoever uses it to build their games would have to recompile the entire engine, when it could just be precompiled, at least in debug mode. |
In theory, Rust could leverage ELF shared object symbol versioning and similar tricks to prevent version mismatches between binaries and libraries. Unfortunately this mechanism is limited to 1) ELF targets and 2) Quite possibly GNU/Linux targets specifically. Short of inventing a brand new Truly Unified Rusty Binary Format there's gonna be no way around establishing some kind of stable ABI for Rust before dylibs/dynamic linking before something that's seriously usable without going through the C ABI. As for "crates could ship precompiled binaries" this has happened before (serde_derive) and was seen as extremely controversial and problematic due to multiple reasons. So it's unlikely that that's going to be a motivating use case for enabling "Rust-ABI" dylibs. |
Would crABI (rust-lang/rust#111423) solve this? |
Now I know the rust team has shot down the idea of having stable ABI, and I am in favor of it, but there is a way to support dynamic linking with Rust ABI without defining a stable ABI. It is lot more cumbersome, but definitely possible. What I am proposing is that each crate creates a single shared library and exports a symbol like below.
This symbol will then be required by the executable linking to this shared library at runtime.
But to achieve this we will have to solve a few questions first
This advantage of supporting this form of shared libraries, is that as long as the rust compiler is same and the whole ecosystem is controlled (like in embedded linux world), we can leverage the use of shared libraries and reduce disk space and memory usage. Both memory and disk space can be a big issue in embedded linux systems.
The text was updated successfully, but these errors were encountered: