Incremental compilation of cargo fails

Generally speaking, I will compile the project code once in the terminal. Then use nvim to edit. During the compilation process, I opened the built-in terminal of nvim to compile, and then I found that cargo will recompile. Why is this happening and how can I fix it?

Such recompilations may happen because of:

  • Different environment variables that affect the compilation (RUSTFLAGS)
  • Different features enabled on the command line
  • Different features enabled via compiling a whole workspace vs. a single package in it (possibly implicitly by being in a different working directory when issuing the Cargo command)
4 Likes

In fact, none of these cases. I simply run cargo build on my project directory. Then open the terminal in nvim and execute cargo build. Then the cache is invalidated

I know why. I use nix flake to manage the project environment, and the cargo it uses is not the same as the cargo in the nvim terminal