How to depend on a single crate from a github repo of multiple crates?

Hello, I want to use the crosvm_control library. You can see it here within the greater crosvm repo: crosvm/crosvm_control at main · google/crosvm · GitHub. As you can see, the crosvm_control library is just a crate WITHIN the crosvm crate.
Now the problem is: I just want the crosvm_control crate WITHOUT the entire crosvm crate in my project. How can I do this?

crosvm = {git = "https://github.com/google/crosvm.git"}

https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories

Cargo fetches the git repository at that location and traverses the file tree to find Cargo.toml file for the requested crate anywhere inside the git repository.

1 Like

From my understanding that's going to include the entire CrosVM project which isn't desirable. Also I had tried this and there's an issue where whenever I try to reload my project I get an error that one of the packages audio_streams can't be found. I think this is because this package is only referenced in the [patch.crates-io] section which is a problem because there is no crates.io for CrosVM.

Generally you can't download only a subdirectory of a git repository. But that's only the download, cargo effectively ignores other crates unless they become transitive dependency of yours.

2 Likes