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

rust-analyzer picks on crates used in build.rs (error[E0514]) while "cargo build", builds project just fine

Open samadariyan opened this issue 1 year ago • 10 comments

I receive this message from PROBLEMS section of vscode:

found crate cc compiled by an incompatible version of rustc rustc(Click for full compiler diagnostics) the following crate versions were found: crate cc compiled by rustc 1.90.0 (1159e78c4 2025-09-14): /Users/samadariyan/Learning/embedded- rust/Exercises/flappy_bird_ffi/target/debug/deps/libcc-89fccd86b939197f.rlib please recompile that crate using this compiler (rustc 1.88.0 (6b00bc388 2025-06-23) (built from a source tarball)) (consider running cargo clean first)

and after click on " rustc(Click for full compiler diagnostics)" it. shows this:

error[E0514]: found crate cc compiled by an incompatible version of rustc --> build.rs:9:22 | 9 | let mut builder: cc::Build = cc::Build::new(); | ^^ | = note: the following crate versions were found: crate cc compiled by rustc 1.90.0 (1159e78c4 2025-09-14): /Users/samadariyan/Learning/embedded-rust/Exercises/flappy_bird_ffi/target/debug/deps/libcc-89fccd86b939197f.rlib = help: please recompile that crate using this compiler (rustc 1.88.0 (6b00bc388 2025-06-23) (built from a source tarball)) (consider running cargo clean first)

But the project builds just fine with the command: 'cargo build' because cc crate is used in build.rs, and it's normal to compile against the host toolchain while my project compiles against "thumbv7em-none-eabihf"

rust-analyzer version: Identifier rust-lang.rust-analyzer Version 0.3.2593

rustc version: rustc 1.90.0 (1159e78c4 2025-09-14)

editor or extension: VSCode Version: 1.104.1

relevant settings: rustup show: Default host: x86_64-apple-darwin rustup home: /Users/samadariyan/.rustup

installed toolchains

stable-x86_64-apple-darwin (active, default)

active toolchain

name: stable-x86_64-apple-darwin active because: it's the default toolchain installed targets: thumbv7em-none-eabihf x86_64-apple-darwin cargo home: /Users/samadariyan/.cargo

repository link (if public, optional): Owner avatar flappy-bird-ffi

code snippet to reproduce:

cc::Build::new();

samadariyan avatar Oct 03 '25 09:10 samadariyan

Same story with clippy

samadariyan avatar Oct 03 '25 09:10 samadariyan

This diagnostic comes from rustc, not rust-analyzer, so something is wrong with your setup, not with r-a.

Try running cargo check --workspace. Also, do you have special r-a settings?

ChayimFriedman2 avatar Oct 03 '25 10:10 ChayimFriedman2

I put build.rs in the exception list:

{ "rust-analyzer.files.exclude": ["build.rs", "/build.rs"], }

cargo check --workspace:

Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.36s

samadariyan avatar Oct 03 '25 10:10 samadariyan

@ChayimFriedman2 Even changed rust toolchain to 1.88.0, but the same message

samadariyan avatar Oct 03 '25 10:10 samadariyan

I guess r.a checkin cc crate againest build target, And for the environment, I tried uninstalling from rustup self-uninstall and installed everything again.

samadariyan avatar Oct 03 '25 10:10 samadariyan

And here results of "1.88.0" toolchain:

crate cc compiled by rustc 1.88.0 (6b00bc388 2025-06-23): /Users/samadariyan/Learning/embedded-rust/flappy-bird-ffi/target/debug/deps/libcc-3aeac5ea6784feef.rlib = help: please recompile that crate using this compiler (rustc 1.88.0 (6b00bc388 2025-06-23) (built from a source tarball)) (consider running cargo clean first)

samadariyan avatar Oct 03 '25 10:10 samadariyan

error is showing same version and same hash and same date! but asking to re-compile.

samadariyan avatar Oct 03 '25 10:10 samadariyan

I'll check on this

ShoyuVanilla avatar Oct 03 '25 10:10 ShoyuVanilla

@ShoyuVanilla I've made a bare minimum project and

cargo check

and

cargo build

works fine but with

cargo clippy

I receive same error

➜ empty-rust git:(main) ✗ cargo clippy Compiling empty-rust v0.1.0 (/Users/samadariyan/Learning/empty-rust) error[E0514]: found crate cc compiled by an incompatible version of rustc --> build.rs:2:19 | 2 | let builder = cc::Build::new(); | ^^ | = note: the following crate versions were found: crate cc compiled by rustc 1.90.0 (1159e78c4 2025-09-14): /Users/samadariyan/Learning/empty-rust/target/debug/deps/libcc-f2b71ba11f1f4946.rlib = help: please recompile that crate using this compiler (rustc 1.88.0 (6b00bc388 2025-06-23) (built from a source tarball)) (consider running cargo clean first)

For more information about this error, try rustc --explain E0514. error: could not compile empty-rust (build script) due to 1 previous error

I hope this info helps repo link empty-rust

samadariyan avatar Oct 03 '25 12:10 samadariyan

Sorry guys @ShoyuVanilla and @ChayimFriedman2 , I. found rustc 1.88.0 was installed using mac ports and that was the source of the issue, which cost me a month and searching the whole system from root to find it.

samadariyan avatar Oct 03 '25 19:10 samadariyan