rust-analyzer
rust-analyzer copied to clipboard
Unecessary extra compilation of dependencies vscode.
rust-analyzer version: 0.3.1756
rustc version: 1.74.1
In vscode. When I do cargo run with RA disabled, it acts normally, when I run cargo run with RA enabled, it recompiles a bunch of dependencies that it shouldn't need to. I only change one number in one of my files. The dependencies it recompiles are:
Blocking waiting for file lock on build directory
Compiling freetype-sys v0.13.1
Compiling expat-sys v2.1.6
Compiling crossfont v0.5.2
Compiling x11-dl v2.21.0
Compiling servo-fontconfig-sys v5.1.0
Compiling freetype-rs v0.26.0
Compiling servo-fontconfig v0.5.1
Compiling sctk-adwaita v0.4.3
Compiling winit v0.27.5
however when i use the run button above the main fn, it works
This usually happens because of differences in RUSTFLAGS or other environment variables.
The few times I've had this happen to me clippy would recompile after a cargo run, and cargo run would recompile after clippy. I think clippy can end up using a different compiler version than whatever you're building with. Iirc I solved it by deleting the Cargo.lock file and running cargo clean, then doing a cold compile.
The few times I've had this happen to me clippy would recompile after a
cargo run, andcargo runwould recompile after clippy. I think clippy can end up using a different compiler version than whatever you're building with. Iirc I solved it by deleting the Cargo.lock file and runningcargo clean, then doing a cold compile.
I tried deleting the cargo lock. But never clean, I'll try it
This is extremely annoying when using huge dependencies like deno_runtime.
Using the run command of rust-analyzer worked for me.
Even when using exactly the same command as rust-analyzer the recompile occurs. Looks like @lnicola is right and some ENVs are set differently. Does someone know which these are exactly and why they are needed?
RUSTFLAGS can only be set by the end user; we cannot say how different the environment variables are different without seeing your environment, unfortunately.
On Linux you can check the environment of a process by running something like cat /proc/PID/environ | tr '\0' $'\n' (at least in bash, for fish you can press Enter to insert a newline there). On Windows you can use Process Explorer.
There are a lot more ENVs set than in a default termial, the screenshot below contains all rust related ENVs (none of them is set in a terminal)
It looks like the first two are responsible, the others seem to be set to the default value.
Apart from not setting those ENVs, it might make sense to also apply them to VSCode builtin terminals like git does
I don't think RUST_RECURSION_COUNT and RUST_BACKTRACE should even cause recompilations. You might be able to use e.g. cargo build -v to see why it's doing it.
Of course, it might also be the --all-targets that we're passing..