1

I have a Rust project which continually builds rdkafka-sys every time anything changes.

Normally, I would expect Cargo not to rebuild dependencies if they have not changed. For all other dependencies in the project, this is the observed behaviour.

However, if I make a change to any of my code, and trigger another Cargo build, Cargo first goes and builds the whole of rdkafka-sys, but none of the other dependencies, despite the fact that nothing in rdkafka-sys has changed.

Can anyone indicate as to why this might be happening? This is presumably not the expected behaviour?

FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
  • I've had this problem while having a rust-analyzer based editor open on the same project while building. You could try setting `CARGO_TARGET_DIR` for your `cargo build`s to something that's definitely not used by something else in parallel. – Caesar Jun 30 '23 at 10:03
  • That sounds familiar, I am using the Rust analyzer, but I don't understand the suggested solution. Can you explain a bit further? – FreelanceConsultant Jun 30 '23 at 10:24
  • Its not really a solution yet, more an investigation approach: try running `env CARGO_BUILD_TARGET=alttarget cargo build` twice and see if that also rebuilds rdkafka. If it doesn't, you can be relatively sure that something (most likely rust analyzer - try exiting that for a while, too, maybe?) is messing with your `target/` dir. How to spin a solution out of that... Always setting `CARGO_BUILD_TARGET` to something sure works, but it's a hack. – Caesar Jun 30 '23 at 10:39

1 Answers1

0

This seems to work...

CTRL+SHIFT+P

"settings.json" -> Open User Settings.json

Add:


    "rust-analyzer.cargo.extraArgs": [
        "--target-dir",
        "rust_analyzer_target"
  ],
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225