Skip to content

Document fixes / workarounds for rust-analyzer breaking incremental recompiles #778

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

Open
alice-i-cecile opened this issue Oct 26, 2023 · 6 comments

Comments

@alice-i-cecile
Copy link
Member

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 Add config option to use rust-analyzer specific target dir rust-lang/rust-analyzer#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
Copy link
Member Author

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.

@IceSentry
Copy link
Contributor

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.

@ethanniser
Copy link

ethanniser commented Oct 26, 2023

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

@paul-hansen
Copy link
Contributor

paul-hansen commented Oct 27, 2023

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.

@musjj
Copy link

musjj commented Nov 3, 2023

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?

@paul-hansen
Copy link
Contributor

paul-hansen commented Nov 3, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants