fermyon / spin

Spin is the open source developer tool for building and running serverless applications powered by WebAssembly.
https://developer.fermyon.com/spin
Apache License 2.0
5.53k stars 257 forks source link

Templates: support Cargo workspaces #2490

Open itowlson opened 6 months ago

itowlson commented 6 months ago

The current Rust templates generate a set of separate workspaces:

- app
  |- comp1
  |  |- Cargo.toml
  |- comp2
     |- Cargo.toml

with separate build commands for each.

This means each component gets a separate IDE experience, separate compilation, etc.

If we also had a workspace at the top level, with the components as workspace members:

- app
  |- Cargo.toml  // New! Exciting!
  |- comp1
  |  |- Cargo.toml
  |- comp2
     |- Cargo.toml

then app developers could open the top-level directory and work on all components in their application in a single IDE, and would benefit from shared compilation of dependencies (once a dependency had been compiled for one package in the workspace, it would not need to be recompiled for others). This is a non-trivial speedup for all the Wasm shenanigans drawn in by the Spin SDK!

This would involve some changes to the Rust template:

There is also some structural stuff:

The main challenge with this is editing the existing Cargo.toml to update the workspace.members array. The existing template system should be able to handle the rest, but it can't do that. It's probably not difficult but it's a very Rust-specific feature and I would really like to start getting that kind of stuff out of the template system and into "smarter" templates. Oh well.

Anyway this feels like it makes for more pleasant edit and build experiences for multi-component Rust projects.

itowlson commented 2 months ago

As far as I can tell, we need a dummy top-level src/lib.rs

Aha, we can get around this with a virtual workspace https://doc.rust-lang.org/cargo/reference/workspaces.html#virtual-workspace