Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to install Cargo dependencies in the same directory as my project?

I'm running my Rust project with Docker. It is fast, but there is a problem when I add an external dependency. Since Docker starts a new every time I run the "cargo run" command, it then fetches the external dependencies from the Internet again.

While this is related to an issue I have with Docker, I don't believe this is restricted to Docker as it can be an issue for a broad range of setups. What I'm looking for is simple regardless of Docker or anything else: Install the dependencies in the Rust project folder instead of having it installed globally, like in Node package manager.

like image 281
Omar Abid Avatar asked Jul 20 '17 18:07

Omar Abid


1 Answers

The dependencies are already built inside every project; in the target directory. The dependencies source code is cached in your user directory at $HOME/.cargo.

If you wish to not use the user-wide download cache, you can specify the CARGO_HOME environment variable and have a separate cache:

CARGO_HOME=$PWD/cargo cargo build

As you drew the analogy to npm, note that Cargo's solution is basically what yarn does — a global cache of downloads and the project's specific dependencies are built / linked into the node_modules directory.

like image 61
Shepmaster Avatar answered Sep 30 '22 16:09

Shepmaster