How to manage the dependencies of a third-party project as expected

I am using the combination of VSCode and Rust-Analyzer as my development environment. I have some trouble with managing dependencies of a third-party project.

More precisely, i git clone a rust project from Github and open this folder by VSCode at first. Then, as you know, Rust-Analyzer automatically run "cargo metadata" and download all dependencies to the global cache directory $HOME/.cargo. I wish i can specify something before the process so that the dependencies will be installed to a local directory such as /ProjectName/store other than disturbing the $HOME/.cargo. Just like "npm install" rather than "npm install -g". I have tried "cargo vendor" and "[install] root = ...". However, "cargo vendor" is not convenient for modifying this project, "[install] root = ..." didn't work.

What can i do to solve this problem, thanks for your response.

What Rust is doing is not comparable to a global npm install. The $HOME/.cargo folder is used only to avoid downloading the same dependency twice if you use it in several places — the dependency is not actually installed in any sense of the word like what npm install would do. A dependency is available only to libraries that specify it in their Cargo.toml.

1 Like

Thanks for your response. Of course, after compiling, rust project doesn't rely on those packages, it is different from node.js or python with runtime dependencies. Besides, i totally approve your insight( The $HOME/.cargo folder is used only to avoid downloading the same dependency twice if you use it in several places).

One more quetion. When i run "cargo metadata", cargo will resolve the cargo.toml and download libraries' source code into $HOME/.cargo (CARGO_HOME). Suppose i download a project, and i want to specify another directory for downloading libraries' source code before run "cargo metadata". How can i do that other than modify the environment variable (CARGO_HOME) again and again.

You can only configure it with the CARGO_HOME environment variable.

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.