I'm trying to convert a rather complex application into Rust. Therefore I've split the project into several repositories, containing several crates and cargo workspaces depending on each other.
The initial development will be mainly about filling in the module structure of all crates and a good amount of refactoring. Here are my problems:
Multiple targets in single workspace
It seems to be hard to have multiple targets in a single cargo workspace. Building the root doesn't respect the default target (set via
.cargo/config.toml) of the crate. While this is just annoying from the command line, it's a real problem in VSCode and rust-analyzer.
I needed this for a workspace containing a portable library and several platform dependent (native, WASM) launchers.
The workaround was to move the launchers out of the workspace.
A similar problem were
examples with different compilation targets. I had to move them into a separate crate (one for each target).
Working on multiple crates
The project comprises of about 20 (top-level-)crates and workspaces. When working on several crates simultaneously I have three choices:
- Open one VSCode instance per crate. This gives the best support from the IDE and rust-analyzer but makes it hard to do global searches and refactorings. Another problem is, that when I change something in another crates (jump to source makes this quite convenient), VSCode doesn't refresh the analysis and keeps reporting all sorts of errors until I re-open the entire project.
- Open the root directory of all crates within this project. rust-analyzer reports a missing manifest. While this can be somewhat fixed by adding a virtual cargo workspace (doesn't work with nested workspaces, I think) it has the multi-target problem. Also VSCode only reads their config from the root level, and doesn't respect the per-project settings.
- Create a VSCode-workspace and add the crates as folders. rust-analyzer still ignores its settings about the build target. One cannot set the target as folder setting - only for the entire workspace
I don't think my use-case is too weird so I'm likely missing something here. Are there best practices for working on multi-crate projects?