-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Multiple binaries/shared library project structure best practice #8362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can use a cargo workspace. This will also share the target dir used by cargo for all crates. To make a cargo workspace add a file [workspace]
include = ["binary_a", "binary_b", "lib/lib_a", "lib/lib_b"] |
Yes I'd used that method for a while, the problem is when you have multiple binaries open at once there's only one Cargo lock and so only one window seems to check at a time. |
Rust analyzer doesn't support sharing the server instance between multiple editor instances, so one way or another if you use multiple vscode windows, rust analyzer will run multiple times. |
Perhaps I'm not explaining my situation clearly, apologies.
Is there another alternative? |
For anyone else with a similar issue, I've found setting the 'linked projects' setting solves this. My assumption is rather by specifying just one Cargo.toml RA won't automatically run an instance for each Cargo.toml. Thus, specify something like the following:
|
I'm encountering bad performance penalties from what is presumably a bad project file structure.
I have a monorepo containing multiple binaries performing unrelated tasks with a
lib
folder with a bunch of crates these binaries use (each uses some but not all crates) and these lib crates have dependencies between themselves.Here's a rough guide to the file structure:
A binary's Cargo.toml looks somewhat like:
and a library's:
I then have VSCode workspace for each binary that includes the binary and the
lib
folder:However, this seems to spin up a cargo check for every single crate in
lib
the binary is using and becomes almost unusably performance draining. It also seems to duplicate indexing/checking external dependencies (i.e. serde is indexed N times).I had previously use a root Cargo workspace which included every binary and library. The performance was better, although it still did two cargo checks, but editing multiple binaries at once (hence two VSCode workspaces) didn't really work as one would have a lock and the other wouldn't.
Opening just the binary folder sees much better performance but then I can easily access files in
lib
which is where 90% of the code is. I've tried finding a way to disable the plugin on just thelib
folder but it doesn't seem possible.What's the best structure to use here? I feel like I'm definitely doing something wrong, so I'm quite happy to completely rearrange everything if required. Thanks!
The text was updated successfully, but these errors were encountered: