Skip to content

Debug unit test code lens fails with a cargo linking failure #7608

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

Open
adaszko opened this issue Feb 9, 2021 · 4 comments
Open

Debug unit test code lens fails with a cargo linking failure #7608

adaszko opened this issue Feb 9, 2021 · 4 comments
Labels
A-vscode vscode plugin issues C-bug Category: bug E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now

Comments

@adaszko
Copy link
Contributor

adaszko commented Feb 9, 2021

Hi 👋

When I click the "Debug" code lens over a unit test, it fails with a linking error:

error: linking with `cc` failed: exit code: 1
[...]
  = note: /usr/bin/ld: cannot find -lpython3.6m
          collect2: error: ld returned 1 exit status

The source of the problem is this: The PATH environment variable needs to include the /opt/miniconda/bin directory. The problem is, even when I put in the env section in launch.json, it's seems like it's not being respected because it doesn't fix the problem:

{
    "type": "lldb",
    "request": "launch",
    "name": "Debug benchmark 'bench_main'",
    "env": {
        "PATH": ".:/root/.cargo/bin:/opt/miniconda/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin"
    },
    "cargo": {
        "args": [
            "test",
            "--no-run",
            "--bench=bench_main",
            "--package=ddx"
        ],
        "filter": {
            "name": "bench_main",
            "kind": "bench"
        }
    },
    "args": [],
    "cwd": "${workspaceFolder}"
}

OTOH, if I build the code via this launch configuration:

{
	"type": "cargo",
	"command": "build",
	"env": {
		"PATH": ".:/root/.cargo/bin:/opt/miniconda/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin"
	},
	"problemMatcher": [
		"$rustc"
	],
	"group": "build",
	"label": "rust: cargo build"
}

there isn't any linking problem and the code builds fine. So I thought I could use the preLaunchTask in launch.json:

"preLaunchTask": "rust: cargo build",

but it also is being ignored and doesn't address the linking problem.

@lnicola
Copy link
Member

lnicola commented Feb 9, 2021

See rust-lang/vscode-rust#887 for previous discussion:

So the crucial question is: Where does rust-analyzer take the recipe to build from for the "Debug unit test" code lens?

I think we invoke cargo build around editors/code/src/debug.ts, thus losing the server environment variables.

@vsrs
Copy link
Contributor

vsrs commented Feb 11, 2021

@adaszko,

You may try rust-analyzer.runnableEnv setting:

"rust-analyzer.runnableEnv": {
    "PATH": ".:/root/.cargo/bin:/opt/miniconda/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin"
}

@adaszko
Copy link
Contributor Author

adaszko commented Feb 11, 2021

@vsrs I have it configured because I use for "Run test" code lens and it works for that. It doesn't work unfortunately for "Debug unit test" code lens.

@vsrs
Copy link
Contributor

vsrs commented Feb 11, 2021

Ups, I forgot that we do not use runnableEnv to get executable:
https://github.com/rust-analyzer/rust-analyzer/blob/b0f20a795d6b1f8d36d1cbe294e54ac592b98f5e/editors/code/src/debug.ts#L105-L106

Looks like it should be enough to reuse task env vars in getDebugExecutable and Cargo::executableFromArgs functions:
https://github.com/rust-analyzer/rust-analyzer/blob/b0f20a795d6b1f8d36d1cbe294e54ac592b98f5e/editors/code/src/debug.ts#L128-L134

@lnicola lnicola added E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now labels Feb 11, 2021
@Veykril Veykril added the A-vscode vscode plugin issues label Dec 14, 2021
@Veykril Veykril added the C-bug Category: bug label Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-vscode vscode plugin issues C-bug Category: bug E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

4 participants