Skip to content
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

Rebuild thrashing when using Rust Analyzer in VSCode with fast build config #14271

Closed
hintron opened this issue Jul 10, 2024 · 13 comments
Closed
Labels
A-Build-System Related to build systems or continuous integration C-Bug An unexpected or incorrect behavior C-Docs An addition or correction to our documentation O-Windows Specific to the Windows desktop operating system
Milestone

Comments

@hintron
Copy link

hintron commented Jul 10, 2024

My problem is that VSCode's Rust Analyzer extension seems to get confused when fingerprinting, marking things as dirty and forcing some crates to rebuild. Perhaps Rust Analyzer isn't respecting the rust flags, or perhaps the envs are different. So Rust Analyzer rebuilds, then I call cargo check or cargo build in the terminal to rebuild, and this repeats, back and forth...

Has anyone else run into this issue? I've only just noticed this on Windows + Git Bash after wondering why my rebuilds were so slow.

My Cargo.toml contains:

[profile.dev.package."*"]
opt-level = 3

[dependencies]
bevy = { version = "0.14", features = ["dynamic_linking"] }

and my .cargo/config.toml comprises of

[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = [
  "-Clink-arg=-fuse-ld=lld",
  "-Zshare-generics=y",
  "-Zthreads=0",
]

[target.x86_64-apple-darwin]
rustflags = [
  "-Zshare-generics=y",
  "-Zthreads=0",
]

[target.aarch64-apple-darwin]
rustflags = [
  "-Zshare-generics=y",
  "-Zthreads=0",
]

[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
rustdocflags = ["-Clinker=rust-lld.exe"]
rustflags = [
  "-Zshare-generics=n", # This needs to be off if you use dynamic linking on Windows
  "-Zthreads=0",
]

The workaround is probably just to make sure the VSCode Rust Analyzer has its own target directory, but that seems brittle since it's per-IDE and isn't versioned to my repo. I tried "rust-analyzer.cargo.targetDir": true, but it still thrashes for me.

While I don't think this is Bevy's fault, I do think that this "foot gun" and possible workaround should be warned about in the fast build config docs, since Rust Analyzer hasn't addressed the issue. Also, I'm curious if others can reproduce this.

@hintron hintron added C-Docs An addition or correction to our documentation S-Needs-Triage This issue needs to be labelled labels Jul 10, 2024
@hintron
Copy link
Author

hintron commented Jul 10, 2024

The workaround is probably just to make sure the VSCode Rust Analyzer has its own target directory, but that seems brittle since it's per-IDE and isn't versioned to my repo. I tried "rust-analyzer.cargo.targetDir": true, but it still thrashes for me.

Actually, I was able to get this workaround working, but only after commenting out the cargo check call in my Git pre-commit hook, as that was yet a third source of the thrashing.

@Earthmark
Copy link
Contributor

I believe this is an alternative report of BLAKE3-team/BLAKE3#324

@hintron
Copy link
Author

hintron commented Jul 11, 2024

Ah, interesting. I did notice that blake3 was the first package that was being recompiled, so I believe it

@janhohenheim
Copy link
Member

janhohenheim commented Jul 11, 2024

I was about to close this issue, but since this has come up time and again, I think it would be good if we documented it somewhere.

@hintron
Copy link
Author

hintron commented Jul 11, 2024

@janhohenheim Has this come up in any other Bevy issues to date? I'm trying to get more info

@janhohenheim
Copy link
Member

janhohenheim commented Jul 11, 2024

@hintron not sure about GitHub issues, but this has definitely come up on Discord a lot.
I think this is only an issue on Windows, but I'm not sure. Let me know if I should remove the O-Windows label.

@janhohenheim janhohenheim added C-Bug An unexpected or incorrect behavior A-Build-System Related to build systems or continuous integration O-Windows Specific to the Windows desktop operating system and removed S-Needs-Triage This issue needs to be labelled labels Jul 11, 2024
@DGriffin91
Copy link
Contributor

Not directly bevy related, but this totally wrecks hot reloading in https://github.com/DGriffin91/ridiculous_bevy_hot_reloading

@hintron
Copy link
Author

hintron commented Jul 11, 2024

I believe I was able to fix the issue upstream in BLAKE3 with this PR: BLAKE3-team/BLAKE3#413.

For anyone else having this issue, can you try my bug fix to see if it works? Simply add this to your Cargo.toml and let me know if it works for you!:

[patch.crates-io]
# For testing fix for blake3 env change rebuild thrashing issue
blake3 = { git = "https://github.com/hintron/BLAKE3", branch = "hintron/fix-blake-rebuild-issue"}

@janhohenheim
Copy link
Member

Ping @MiniaczQ, you just had this issue

@DGriffin91
Copy link
Contributor

@hintron Works for me, thanks!

@hintron
Copy link
Author

hintron commented Jul 12, 2024

I confirmed that the issue does not happen on Linux. It seems to be a Windows-only issue.

@janhohenheim
Copy link
Member

Since blake3 just release version 1.5.2 which includes your changes, I'll close it as complete.
@hintron thank you so much for fixing this! I have also run into this in the past and I'm glad that new users won't be bothered by sporadic rebuilds anymore :)

@hintron
Copy link
Author

hintron commented Jul 12, 2024

It was fun to debug! Glad to be of help.

For anyone else with this issue on Windows with Bevy 0.13 or 0.14, just do cargo update blake3 or cargo update to pull in the fix.

@janhohenheim janhohenheim added this to the 0.14.1 milestone Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Build-System Related to build systems or continuous integration C-Bug An unexpected or incorrect behavior C-Docs An addition or correction to our documentation O-Windows Specific to the Windows desktop operating system
Projects
None yet
Development

No branches or pull requests

4 participants