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

I am running a Rust project using Docker. It's fast, but there is a problem when I add an external dependency. Since Docker starts a new one every time I run the "load load" command, it pulls external dependencies from the internet again.

While this is related to the issue I ran into with Docker, I don't think it is limited to docker as it can be a problem for a wide range of settings. What I'm looking for is simple regardless of Docker or whatever: install the dependencies in the Rust project folder instead of installing it globally, for example in the Node.

+3


source to share


1 answer


Dependencies are already built into every project; in the directory target

. The source code of the dependencies is cached in your user directory under $HOME/.cargo

.

If you don't want to use a custom load cache, you can specify an environment variable CARGO_HOME

and have a separate cache:

CARGO_HOME=$PWD/cargo cargo build

      




As you used the npm analogy, note that Cargo's solution is basically what yarn does - a global download cache and project-specific dependencies are created / linked in a directory node_modules

.

+3


source







All Articles