Best practice for multiple executables

We are using rust for an application that involves multiple executables. I'm trying to figure out the best way to do this with Cargo, ideally with good build times.

  1. Multiple executables at the top level crate. There seems to be some convention for this, with the convention of src/bin/*.rs, but I wasn't sure how well this works for multiple modules in main. It does build all of the executables any time there is a change that would affect any of them (dependencies, or any source file in the top level crate). This can be somewhat mitigated by cargo build --bin progname to only build one of the executables.
  2. Build a single executable and use subcommands to invoke the various other programs. This has the advantage of more of the code being shared in memory, but any change will always have to rebuild this executable. It also makes monitoring these programs a little harder, because the show up in top and ps as just the single executable name.
  3. Separate crate for each executable. As far as I can tell, this means each crate will also get its own target directory, and any shared dependencies will be rebuild for all of them.

From my analysis, I'm thinking that #3 is probably not very workable, but I'm not sure which or 1 or 2 is better. I can get more control over the directories in #1 by explicitly naming them in the Cargo.toml file, and giving a path for each.


1 Like