Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo metadata exited with an error: error: could not execute process rustc -vV (never executed) #16561

Closed
Geobert opened this issue Feb 14, 2024 · 6 comments · Fixed by #16563
Labels
A-cargo cargo related issues C-bug Category: bug

Comments

@Geobert
Copy link
Contributor

Geobert commented Feb 14, 2024

rust-analyzer version: 0.4.1840

rustc version: 1.68.2

Since version 0.4.1840 RA can’t start:

2024-02-14T08:42:24.398537Z ERROR rust_analyzer::main_loop: FetchWorkspaceError:
rust-analyzer failed to load workspace: Failed to load the project at /home/geobert/work/project/Cargo.toml: Failed to read Cargo metadata from Cargo.toml file /home/geobert/work/project/Cargo.toml, Some(Version { major: 1, minor: 68, patch: 2 }): Failed to run `cd "/home/geobert/work/project" && "/home/geobert/.rustup/toolchains/1.68.2-x86_64-unknown-linux-gnu/bin/cargo" "metadata" "--format-version" "1" "--manifest-path" "/home/geobert/work/project/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: could not execute process `rustc -vV` (never executed)

Caused by:
  No such file or directory (os error 2)

In VSCode on WSL2

0.4.1838 works fine

@Geobert Geobert added the C-bug Category: bug label Feb 14, 2024
@Veykril
Copy link
Member

Veykril commented Feb 14, 2024

Hmm, why does cargo metadata not find rustc? This is most likely caused by #16537, we now invoke cargo with the full sysroot path, but that shouldn't have an effect here now for it to execute rustc should it?

@oing9179
Copy link

oing9179 commented Feb 14, 2024

rust-analyzer version: rust-analyzer version: 0.4.1840-standalone (3770f73bd 2024-02-12)
rustc version: rustc 1.76.0 (07dca489a 2024-02-04)

An issue happened to me and I believe they have something in similar, I'm on
windows and here's my error output of Rust Analyzer Language Server:

2024-02-14T09:15:58.338514Z ERROR rust_analyzer::main_loop: FetchBuildDataError:
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `c:\Users\fuckms\.vscode-oss\extensions\rust-lang.rust-analyzer-0.4.1840-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=split-debuginfo --print=crate-name --print=cfg` (exit code: 101)
  --- stderr
  program not found

I installed Rust in MSYS2 with environment variable RUSTUP_HOME and
CARGO_HOME set to /home/<Username>/.rustup and /home/<Username>/.cargo
respectively. In order to make Rust Analyzer work for my environment I have to
set rust-analyzer.server.extraEnv and 4 simliar others with 2 env vars
previously mentioned to C:\\msys64\\home\\<Username>\\.rustup and .cargo.
I suspect the issue is caused by this commit,
because on Rust Analyzer verison 0.3.1839 it worked just fine.

Edit: missing information.

@lnicola
Copy link
Member

lnicola commented Feb 14, 2024

Child processes will inherit environment variables from their parent process by default. Environment variables explicitly set using Command::envs take precedence over inherited variables. You can disable environment variable inheritance entirely using Command::env_clear or for a single key using Command::env_remove.

Not sure why it would be a981db5, then.

@Veykril
Copy link
Member

Veykril commented Feb 14, 2024

process didn't exit successfully: c:\Users\fuckms\.vscode-oss\extensions\rust-lang.rust-analyzer-0.4.1840-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=split-debuginfo --print=crate-name --print=cfg (exit code: 101)

🤨 That looks like the rustc_wrapper causing troubles somehow

@Veykril
Copy link
Member

Veykril commented Feb 14, 2024

a981db5 should be irrelevant here as that doesn't involve build scripts.

@Veykril
Copy link
Member

Veykril commented Feb 14, 2024

So it has to be #16537. Instead of running cargo from CARGO_HOME etc we invoke it from the sysroot directly (so cargo no longer does any toolchain selection here) which presumably changes how additional tools are invoked? I would assume cargo would just pick the rustc besides it in the toolchain when invoked this way...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cargo cargo related issues C-bug Category: bug
Projects
None yet
4 participants