Rust-analyzer failed to run build scripts

I used rust-analyzer on vscode but it bubbles to warn me that:

rust-analyzer failed to run build scripts
Check the server logs for additional info.

I have tried to run vscode in administrator mode but it didn't work.

Here the logs. Help, please!
By the way, the code intelligence of the analyzer can run smoothly. It is just a bit annoying.

[ERROR rust_analyzer::lsp_utils] rust-analyzer failed to run build scripts

error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `c:\Users\rot\.vscode\extensions\rust-lang.rust-analyzer-0.3.1091-win32-x64\server\rust-analyzer.exe rustc - --crate-name ___ --print=file-names --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit code: 101)
  --- stderr
  拒绝访问。 (os error 5)

The error suggests you don't have Rust installed. Have you installed it?

If you have Rust (not just analyzer) installed, then make sure it's in PATH. It should have added itself to PATH during installation.

Can you try running c:\Users\rot\.vscode\extensions\rust-lang.rust-analyzer-0.3.1091-win32-x64\server\rust-analyzer.exe rustc -vV?

It said

unexpected argument: "rustc"

But I could run rustc -vV directly:

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-pc-windows-msvc
release: 1.61.0
LLVM version: 14.0.0

Emm... I have installed Rust by rustup. My rustc -vV is in my another reply :wink:

And, C:\Users\rot\.cargo\bin is in my PATH.

I solved it. It's windows defender who occupied the file, just ban it and everything runs smoothly.

Hi, may I know how to ban it? I encountered the same problem using Windows 10 and VSCode.

I got an error like this yesterday, have you figured how to ban it?

Hello, may i know you banned it in windows defender?

Turn off the option "real time protection" in the windows defender menu. I dont know the exact translation of it.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.