Skip to content

VSCode Debug: Cargo invocation has failed: Error: could not launch cargo: Error: spawn cargo ENOENT #14066

@hehaoqian

Description

@hehaoqian

Behavior:

  1. Click "Run Test" button correctly run the rust unit tests
  2. Click "Debug" button does not spawn any process.
    It gives the following error message on the bottom right
Cargo invocation has failed: Error: could not launch cargo: Error: spawn cargo ENOENT

Related settings:

  1. My rust toolchain is not installed in HOME, nor it is installed in any directory that requires root permission.
  2. Environment variables, such as CARGO_HOME, PATH (which includes rustup and cargo), RUSTUP_HOME are not set,
    in ~/.bashrc, ~/.bash_profile, or ~/.profile
    So by default, in the terminal, there is no cargo in the PATH.
  3. Rust related env variables are set in the VSCode workspace settings as the following:
    Actual Path omitted.
    All settings of CARGO_HOME, PATH and RUSTUP_HOME are the same.
"rust-analyzer.runnableEnv": {
   "CARGO_HOME": "...",
   "PATH": "...",
   "RUSTUP_HOME": "...",
},
"rust-analyzer.server.extraEnv": {
   "CARGO_HOME": "...",
   "PATH": "...",
   "RUSTUP_HOME": "...",
},
"rust-analyzer.cargo.extraEnv": {
   "CARGO_HOME": "...",
   "PATH": "...",
   "RUSTUP_HOME": "...",
},
"rust-analyzer.check.extraEnv": {
   "CARGO_HOME": "...",
   "PATH": "...",
   "RUSTUP_HOME": "...",
},
"rust-analyzer.debug.engine": "ms-vscode.cpptools",
"rust-analyzer.debug.engineSettings": {
  "cppdbg": {
    "setupCommands": [
      {
        "description": "Enable pretty-printing for gdb",
        "text": "-enable-pretty-printing",
        "ignoreFailures": true
      }
    ],
    "environment": [
      {
        "name": "CARGO_HOME",
        "value": "...",
      },
      {
        "name": "PATH"
        "value": "...",
      }
      {
        "name": "RUSTUP_HOME"
        "value": "...",
      }
    ],
}
  1. Removing the "environment" settings in "rust-analyzer.debug.engineSettings" does NOT fix the problem.
  2. Set those environment variables directly in ~/.bashrc, kill VSCode server, and relaunch VSCode SOLVES the problem.
    But I do not want to use this way to solve the issue.
    I do not want rust related stuffs to pollute my ~/.bashrc, since only a small number of projects use it.
  3. This should be a regression. My setup was working in an old version, around 3 months ago.
    But I am not sure which old version.

rust-analyzer version (The version which has the bug):
rust-analyzer version: 0.3.1377-standalone

rustc version:
rustc 1.61.0 (fe5b13d68 2022-05-18)

Operating system:
CentOS Linux release 7.3.1611

rust-analyzer executable requires GLIBC 2.25,
while my environment uses GLIBC 2.17.
So the RPATH of rust-analyzer executabl is modified to
point to a custom compiled GLIBC 2.30


Possible cause guested by me:

Is rust-analyzer.runnableEnv really applied to Debug?
Can you check if the PATH has been applied?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-vscodevscode plugin issuesC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions