rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Unecessary extra compilation of dependencies vscode.

Open jonathandw743 opened this issue 1 year ago • 9 comments

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

jonathandw743 avatar Dec 09 '23 15:12 jonathandw743

however when i use the run button above the main fn, it works

jonathandw743 avatar Dec 09 '23 15:12 jonathandw743

This usually happens because of differences in RUSTFLAGS or other environment variables.

lnicola avatar Dec 09 '23 16:12 lnicola

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.

Walnut356 avatar Dec 10 '23 06:12 Walnut356

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.

I tried deleting the cargo lock. But never clean, I'll try it

jonathandw743 avatar Dec 10 '23 19:12 jonathandw743

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?

hansSchall avatar Aug 12 '24 17:08 hansSchall

RUSTFLAGS can only be set by the end user; we cannot say how different the environment variables are different without seeing your environment, unfortunately.

davidbarsky avatar Aug 12 '24 17:08 davidbarsky

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.

lnicola avatar Aug 12 '24 17:08 lnicola

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)

grafik

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

hansSchall avatar Aug 13 '24 09:08 hansSchall

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..

lnicola avatar Aug 14 '24 12:08 lnicola