Extensive rebuilding when using cross together with clippy in VS Code + Rust Analyzer

I use cross to develop for different targets. The cross command essentially replaces cargo with the same arguments.

There is an extra extension to make it possible to easily control targets for rust analyzer: https://marketplace.visualstudio.com/items?itemName=vsrs.cross-rust-analyzer

I also configure my check command to be clippy. But there is a problem: The check command always run cargo <whatever my check sub command is> and I would like it to instead run cross <...>.

When using cargo and cross interchanging like this, there is unfortunately a bug (or limitation) that the incremental build functionality stops working and the entire project is rebuilt every time.

A solution would be to always use cross. But I can't find such a setting in Rust Analyzer extension? Is there a way to get around this?

1 Like

A really hacky way to work around this would be to create a shell script called cargo that just calls into cross, then make sure the script is on your $PATH (e.g. by overriding $PATH in rust-analyzer.check.extraEnv).

did you try the rust-analyzer.check.overrideCommand configuration?

1 Like

For some reason I missed this when trying to find a solution.

Setting both

rust-analyzer.check.overrideCommand
rust-analzyer.cargo.buildScripts.overrideCommand

works perfectly!