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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With