3 ms·
>> Dynamic linkage by default >> By default, the Rust ecosystem assumes that crates will be statically linked into binaries. The usual benefits of dynamic libra
by thesuperbigfrog 5y ago
>> Dynamic linkage by default
>> By default, the Rust ecosystem assumes that crates will be statically linked into binaries. The usual benefits of dynamic libraries are upgrades (whether for security or functionality) and decreased memory usage. Rust’s lack of a stable binary interface and usage of cross-crate information flow prevents upgrading libraries without upgrading all dependent code. Even when the same crate is used by two different programs on the system, it is unlikely to be provided by the same shared object4 due to the precision with which Rust identifies its crates. This makes Rust binaries more portable but also results in larger disk and memory footprints.
>> This is problematic for Android devices where resources like memory and disk usage must be carefully managed because statically linking all crates into Rust binaries would result in excessive code duplication (especially in the standard library). However, our situation is also different from the standard host environment: we build Android using global decisions about dependencies. This means that nearly every crate is shareable between all users of that crate. Thus, we opt to link crates dynamically by default for device targets. This reduces the overall memory footprint of Rust in Android by allowing crates to be reused across multiple binaries which depend on them.
>> Since this is unusual in the Rust community, not all third-party crates support dynamic compilation. Sometimes we must carry small patches while we work with upstream maintainers to add support.
Having a dynamic linking option for Rust would be a tremendous improvement.
It would help to solve vendoring issues and hopefully improve interop with existing systems and programming languages.
Good dynamic linking support and enhanced interop with C would make it much easier to do a piece-wise replacement of C components with Rust components, allowing for a gradual migration in places where it makes sense to do so.