Cargo dependency on private git repo with a workspace

For the top level crate in a workspace I can pull in the git repo and everything builds fine.

How in the Cargo.toml dependencies section do I tell it I also want to pull in an additional create from that git workspace?

I tried { git=".....", path="path_to_crate_in_workspace" } but seems you can't have path and git specified at the same time..

I read the docs here but they didn't say what to do in this case:
https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories

Is there an incantation I can use to achieve this today in cargo or is it currently not possible to depend on a crate inside a workspace via git?

I can't try it out, but googling for "rust dependency git subfolder" suggests that foo = { git = "giturl" } should work out of the box if any crate.toml in the repository specifies a package "foo".

2 Likes

That works! It crossed my mind, but I discounted it as 'cargo wouldn't be that clever'. I will try and update the docs to indicate that this is how one does it - many thanks!

Doc++ here: Git repos pointing to workspaces by gilescope · Pull Request #6306 · rust-lang/cargo · GitHub