How does Cargo handle system-wide libraries and conflicts on a Gentoo system?


#1

Hey folks,

I’m brand new to Rust and exploring the system.

I use Gentoo Linux, and since the distro compiles all libraries and programs it’s recommended not to use installation systems such as pip as the resulting library files may conflict with it.

That said, with pip you can specify the --user flag which installs the program/lib at a user level so that a library that pip uses doesn’t interfere with a system-side version.

How does Cargo handle this? Installing [https://github.com/way-cooler/way-cooler](http://Way Cooler) i note that it’s pulling in dbus libraries that i already have installed system-wide. Where are dependencies put, and if i install 3 programs that use dbus am i going to have 3 copies of the same library + the system library?

Thank you,

Bearcat


#2

Unless you are doing something special, it’s expected that cargo will always be run with user permissions, so everything that downloads lives under ~/.cargo folder.

Actually the same case is for installing rust through rustup.


#3

Yes. But none of these versions will conflict with each other. The source code for cargo dependencies will be downloaded/cached into ~/.cargo/registry/src/ and the build artifacts will be stored somewhere in the target directory of your project folder (the folder containing Cargo.toml).

That’s how it works for normal rust dependencies.
It’s a little different for native library dependencies. Some projects will automatically download the source (generally C code), build it, and then statically link with it. Other projects will include code to automatically look for a system-installed version and use it if found.

way-cooler seems to depend on the dbus-rs crate, which is found here: https://github.com/diwic/dbus-rs
And the dbus-rs crate will require that you have a system-installed version of libdbus


#4

Thank you @eminence and @ericho. That answers my questions nicely.

If i would end up with 3 copies of a library in that case, and disc space is tight, is there a way to reduce the duplication?