Cargo - ffi dependency libraries download from dependent repo

I have a project that is stored in a git repo. The project uses ffi and refers to a dependent library(dll/so) also stored in the project, for example:


This all compiles perfectly and gets stored into a repo

I have another repo that wants to use the repo as a dependency.


in here I refer to the repo

client = { git="", branch="master" }

When I compile the dependency correctly pulls client, however I need the extra step of getting the lib/ as well. Is there and [an easy way] | [common pattern] | [am I nuts] for doing this?

This won't work well.

  • If it's a common system-wide library, you should ask users to install it themselves.
  • If it's a private library, prefer linking statically. Ideally build it from source (with the cc crate).

The problem is that executables have to embed paths to libraries they link with (rpath), and whatever path you choose, it's going to be problematic:

  • the path can be relative to the executable:

    • you will need to copy the library to all the places where Cargo puts executables and tests. Cargo has no support for this.
    • or you will need to set LD_LIBRARY_PATH to the library's location. The executable won't work without it. This may be acceptable for development, but these paths are supposed to be managed by the system.
  • if the path is absolute:

    • if it's the path to your crate's current location, it will be a path to a temporary directory that works only on your machine, and the executable will stop working when Cargo cleans up its temp directories.
    • if it's absolute to some standard permanent system-wide location, then you're making Cargo modify the system in a non-standard way, and that's usually frowned upon.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.