Multi crate repository vs multiple repositories

So whenever it comes to deicde my decision making is really out of the water, as it is not really my thing. Yet, since I'm a bit OCD I prefer things to always be strict and have at least some reasoning about why. As you can imagine, although I'm still a newbie, I really love rust - there are so many constraints from the compiler like its my birthday.
However, now that I'm building a slightly larger project, which has different crates I started wondering should I put them in the same repo - like serde for instance or in different repo. Some of them are gona be developped independently, so I'm not too sure what is the benefit of being in the same repository? Or why not? I'm quite curious to hear what do you guys think and why/when you would chose one over the other?

You can look fo question related to monolithic repositories in git. After reading many of the linked articles I decided last month to put many related crates in the same repository.

From Rust/Cargo perspective fortunately there's no significant difference. It still locks versions, it still publishes each crate separately, etc.

I see it as a progression — if some functionality grows too big, it gets its own module. If the module grows too big, its moved into a crate in the same repo and workspace, and if that has life on its own, its moved to a separate repo as a project on its own.


For RustCrypto I've adopted the following approach: crates stored in the several repositories depending on the "type" of crate. Using workspaces it results in more effective compilation as all crates share the same "target" folder and it allows to test all crates with one command cargo test --all which makes CI config simpler. Also it makes significantly easier to track issues and pull requests.

So if you don't have a clear structure of your crates in your head yet, then I would recommend to start with one repo and move crates out (if they become too big or independent) or split repository depending on the situation.

1 Like