bazelbuild / bazelbuild/rules_rust

gen_rust_project: support unit tests

Open
#2,909 2 comments 5 reactions 0 assignees View on GitHub
awaiting-response rust-analyzer
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

Currently, `rules_rust`'s `rust-project.json` generation code does not provide enough information for rust-analyzer to know how to launch a unit test. It looks like this and tries to run `cargo` when clicking on `Debug`:
![image](https://github.com/user-attachments/assets/7fd65eaf-ab84-4fbe-aadd-75123e05f626)

When it works, it should look like this and properly run the selected test:
![image](https://github.com/user-attachments/assets/5e65db78-ab8c-45be-b52f-bb5851144894)

Some investigation made me understand that the additional content is needed:
- in the root object, provide a `runnables` list:
```json
{
"sysroot": "...",
"sysroot_src": "...",
"runnables": [
{
"program": "bazel",
"args": [
"test",
"--test_output=streamed",
"{label}",
"--test_arg={test_id}",
"--test_arg=--nocapture",
"--test_arg=--color=always",
"--test_arg=--exact"
],
"cwd": "/Users/lucas/projets/issue-rust-analyzer-tests-bazel/",
"kind": "testOne"
}
],
...
```
- for each crate, provide a `build` record:
```json
{
"display_name": "engine",
"build": {
"label": "//rs/engine:tests",
"build_file": "/Users/lucas/projets/issue-rust-analyzer-tests-bazel/rs/engine/BUILD.bazel",
"target_kind": "test"
},
...
```

Is it already planned to add support for tests in cargoless setups ? Are there unexpected roadblocks ?

Here is the demo repository I have used to experiment with `rust-project.json` configuration. It's not usable as is, you need to run `./gen_rust_project.sh` to obtain a version that works on your machine, then manually edit it to add the fields I describe above in the issue. https://github.com/TheLortex/issue-rust-analyzer-tests-bazel

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.