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

forced recompiling no code changes due to rust analyzer

Open tzemanovic opened this issue 1 year ago • 2 comments

Hi, thanks for rust-analyzer!

I'm having trouble with rust-analyzer forcing rebuild of a project and all its deps even though there are no code changes. I tried to diagnose what's causing it reading #16640 and with CARGO_LOG=cargo::core::compiler::fingerprint=info cargo build I'm seeing e.g.:

cargo::core::compiler::fingerprint: dependency on `build_script_build` is newer than we are 1714234960.242826421s > 1714234952.135008268s "/home/tz/.cargo/registry/src/github.com-1ecc6299db9ec823/crossbeam-utils-0.8.16"

...

cargo::core::compiler::fingerprint: fingerprint dirty for crossbeam-utils v0.8.16/Build/TargetInner { ..: lib_target("crossbeam-utils", ["lib"], "/home/tz/.cargo/registry/src/github.com-1ecc6299db9ec823/crossbeam-utils-0.8.16/src/lib.rs", Edition2018) }
cargo::core::compiler::fingerprint:     dirty: FsStatusOutdated(StaleDependency { name: "build_script_build", dep_mtime: FileTime { seconds: 1714234960, nanos: 242826421 }, max_mtime: FileTime { seconds: 1714234952, nanos: 135008268 } })
cargo::core::compiler::fingerprint: fingerprint dirty for crossbeam-utils v0.8.16/RunCustomBuild/TargetInner { ..: custom_build_target("build-script-build", "/home/tz/.cargo/registry/src/github.com-1ecc6299db9ec823/crossbeam-utils-0.8.16/build.rs", Edition2018) }
cargo::core::compiler::fingerprint:     dirty: UnitDependencyInfoChanged { old_name: "build_script_build", old_fingerprint: 2579957232512875769, new_name: "build_script_build", new_fingerprint: 11333844636011871432 }
cargo::core::compiler::fingerprint: fingerprint dirty for crossbeam-utils v0.8.16/Build/TargetInner { ..: custom_build_target("build-script-build", "/home/tz/.cargo/registry/src/github.com-1ecc6299db9ec823/crossbeam-utils-0.8.16/build.rs", Edition2018) }

This appears for all the deps with build scripts so it seems that for some reason there is difference in how the build scripts are compiled.

I tried to remove all my user settings (both in VSCode and in terminal) to make sure it's not due to my config.

I also tried to set "rust-analyzer.cargo.buildScripts.useRustcWrapper": false with no success. I'm using "rust-analyzer.rust.analyzerTargetDir": true as a workaround which unfortunately bloats the build artifacts.

rust-analyzer version: Release: 2024-04-22 (v0.3.1932)

rustc version: rustc 1.76.0 (07dca489a 2024-02-04)

editor or extension: VSCode v0.3.1932

tzemanovic avatar Apr 27 '24 16:04 tzemanovic

I have similar problem. Recently upgraded to rustc 1.79.0 rust-analyzer 0.3.2020

It happens to me only when I run a test from test explorer, but not when I debug.

Case 1: Debug a test from test explorer. Make a change in test file. Debug again. Only my code is recompiled.

Case 2: Run a test from test explorer. Make a change in test file,. Rust-analyzer starts a check which invalidates fingerprints. When I run again, everything is recompiled again.

I am learning rust, so I can't provide more info, but I am suspecting two different commands are executed when I run/debug, but I don't know how to check that. Also tried downgrading rust-analyzer, but it doesn't help.

mkonars avatar Jul 05 '24 11:07 mkonars

After cloning my repo again the problem seems to be gone.

mkonars avatar Aug 25 '24 09:08 mkonars

I'm running into the same issue, but I'm not sure rust-analyzer is the main culprit here: it may be cargo check.

If I edit and save a file in Zed, it will trigger rust-analyzer and through it, cargo check. Then get this slight timestamp issue on (*-sys type) sub-crates in the same directory. A full rebuild of all the subcrates as well as running build.rs is triggered (and that triggers a cxx build in this project…).

If I edit the same file in a simple editor like joe, which doesn't know anything abour rust-analyzer and cargo, only the necessary components will be rebuilt.

If, however, I run cargo check, without even touch any file, a subsequent cargo build will be a full rebuild.

However, cargo build followed by a cargo build, will do nothing.

So there's something weird going on with cargo check.

497e0bdf29873 avatar May 15 '25 16:05 497e0bdf29873