Organize larger project in a rust-analyzer-friendly way

I have a project that started from a small test but over time took over and now has grown quite a bit. I'd like to get some suggestions on how I should organize it in terms of crates/packages/workspaces/repositories... In particular, I'd like a solution that plays well with rust-analyzer.

Some info on the current project structure

The project has a total of 6 binaries and 11 libraries. The binaries target different architectures:

  • 3 of them are compiled for aarch64-unknown-linux-gnu
  • 2 for x86_64-unknown-linux-musl and x86_64-pc-windows-gnu
  • 1 for armv7r-none-eabi, that is no_std

The x86_64 binaries run on a controlling computer, while the aarch64 and armv7r binaries run on a dedicated hardware that talks to the computer via network.

Each binary is in its own package [1], and the default target is specified in the package's .cargo/config file. The aarch64 binaries have also special settings for custom linker and sysroot.

The libraries also have each their own package in the project root. Not all binaries use all libraries, but there is some overlap. Two of the libraries have build.rs scripts.

As of now, everything sits in the same git repository. This has the advantage that it's easy to keep the development of all binaries and libraries synchronized.

Problems

The major downside of my current approach, and the reason for this post, is that rust-analyzer is rather slow to start working properly (3–4 minutes). During this start-up time, I can see on the mode line [2] that rust-analyzer is looking at the same crates [3] over and over again. I suspect this has to do with the different targets and cargo features present in my packages.

I've once tried to create a workspace, but I didn't have much success. First, running cargo from the workspace was ignoring the packages' .cargo/config files, so I couldn't figure out how to have different targets for different packages in the workspace. Second, rust-analyzer was much faster to start, but was not really working: syntax checking and the like was not working on most of the files [4].

Solutions?

Do you have some suggestions on how to structure my project? If possible I'd really like to keep everything or most in the same repository to avoid the overhead of making sure all the repos are synchronized.

Thanks in advance!


  1. "cargo folder" with its own Cargo.toml ↩︎

  2. I'm using Emacs with Spacemacs ↩︎

  3. including std and core ↩︎

  4. again, I suspect it was due to different targets ↩︎

This thing should really happen only once. Other times, it does a quick scan of its existing "cache".

Rust-Analyzer doesn’t support persistent caching, meaning that every time you restart/reload your editor r-a will reindex the whole project.

https://github.com/rust-lang/rust-analyzer/issues/4712

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.