bevy-website icon indicating copy to clipboard operation
bevy-website copied to clipboard

Document fixes / workarounds for rust-analyzer breaking incremental recompiles

Open alice-i-cecile opened this issue 2 years ago • 6 comments

A user ran into this problem after following the linked advice on fast compiles.

I'm not entirely sure on the best solution.

We could:

  1. Suggest that they change the target directory for rust-analyzer, using https://github.com/rust-lang/rust-analyzer/pull/15681
  2. Suggest they use sccache to share build artifacts (very useful when playing with many Bevy projects).
  3. Use the workarounds listed here.
  4. Do something else that I haven't thought of! I'm not a compiler/build tools wizard 😅

alice-i-cecile avatar Oct 26 '23 19:10 alice-i-cecile

Presumably this is a problem for other Language Server Protocols (LSPs) as well. rust-analyzer is the one I'm most concerned about though, as new programmers tend to use VSCode and have less capacity for troubleshooting this sort of thing on their own.

alice-i-cecile avatar Oct 26 '23 19:10 alice-i-cecile

I think sccache and setting the targetDir config to true should both be recommended but starting with the targetDir suggestion first. sccache is just a nice bonus on top. The targetDir fix should also help with rust-analyzer locking cargo commands for too long.

IceSentry avatar Oct 26 '23 20:10 IceSentry

A user

Thats me! Ended up trying option 1

in settings.json

"rust-analyzer.rust.analyzerTargetDir": true

and everything seems to be working fine now

ethanniser avatar Oct 26 '23 20:10 ethanniser

You can also tell rust analyzer to use the same features you are using with cargo run. (Usually bevy/dynamic_linking) that way it's able to reuse build artifacts between them. That has the advantage of not doubling the size of the target directories on disk, but the drawback of sometimes locking the build until it finishes, the build will be faster when it does run though. I have an answer here that goes over how to do the features in clion (rustrover should be similar) and vscode: https://stackoverflow.com/a/75561975

I personally started using the separate build directory, but I have seen people complain about the size of the target directory before so I'm not sure doubling it is ideal for everyone.

paul-hansen avatar Oct 27 '23 05:10 paul-hansen

sccache looks interesting. Does it actually solve any compilation issues or is it just for saving drive space?

So I'm seeing two approaches here:

  1. Have a separate directory for rust-analyzer output and use sccache to drive down the space consumption.
  2. Share the --feature bevy/dynamic_linking flag with rust-analyzer and your debugger. Maybe rust-analyzer.cargo.features would be useful here?

musjj avatar Nov 03 '23 11:11 musjj

Sscache doesn't cache incrementally compiled crates, which for debug builds by default means your project crate and any path dependencies. It also doesn't work for dynlib crates, so not bevy if you use dynamic_linking. Source: https://github.com/mozilla/sccache#rust So I think it's pretty minor benefit for debug builds. Could be interesting to get some comparison numbers though. You would want to do one of the other two approaches in addition to sscache anyway since it would still have to pull the different results from the cache into your target directory each time.

So imo sscache is not really a good solution to this problem, just might make the conflict resolution happen quicker and is limited at doing that. The other two approaches prevent the conflict.

paul-hansen avatar Nov 03 '23 18:11 paul-hansen