rfcs
rfcs copied to clipboard
Support dynamic linking with Rust ABI and not C ABI
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.
RUSTC_1.49::<Crate>_<version>
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
- [ ] When including crate version, should we include full version (major.minor.build) or just major.minor?
- [ ] Does Cargo currently pass crate versions to rustc, and if not we will have to define a way to do this.
- [ ] Expose a mechanism in cargo to build a crate as dynamic library, or use a crate as dynamic library
- [ ] Provide a way in cargo to pick a prebuilt shared library, in a way that the above symbol is verified before linking and not during linking
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.