Isolate native dependencies

Can the Rust compiler please isolate native dependencies used across different crates?

It takes forever and a day for crate authors to update native dependencies, so they inevitabily get out of sync, breaking compilation.

Each Rust crate should be able to invoke native dependencies without any collision whatsoever between other Rust crates.

Do you have a concrete example? *-sys packages can set the package.links field for exactly such cases. If set properly, Cargo disallows two packages linking the same native library.

I believe what you are describing is the problem @mcandre wants a solution to.

The problem is that only some platforms support being able to load two native libraries with the same symbol names and keep them distinct. In particular, Windows and macOS do (in different ways), but Linux does not. Rust cannot solve this problem itself because even if Rust provided its own linker, Rust does not provide the loader (the system component that loads executables and dynamic libraries into a process’s memory).

Without such isolation, loading two libraries with overlapping names can cause UB. Cargo’s links mechanism is intended to minimize that risk, though it does have false positives.

3 Likes

Right, misread it. My bad. I read it as if collisions was referring to duplicated symbols in the native libraries, not collisions between Rust packages.

As a concrete example, all the crates that depend on xz, xz2, etc.

On second thought, isolation may be risky. For example, a hypothetical native device driver, that ends up initializing multiple times.