Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions docs/rust_analyzer.vm
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,46 @@ The `rust_analyzer` rules facilitate both approaches.
## rust-project.json approach
### Setup

First, ensure `rules_rust` is setup in your workspace. By default, `rust_register_toolchains` will
ensure a [rust_analyzer_toolchain](#rust_analyzer_toolchain) is registered within the WORKSPACE.
#### Bzlmod

Next, load the dependencies for the `rust-project.json` generator tool:
First, ensure `rules_rust` is setup in your workspace:

```python
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")
# MODULE.bazel

rust_analyzer_dependencies()
# See releases page for available versions:
# https://github.com/bazelbuild/rules_rust/releases
bazel_dep(name = "rules_rust", version = "{SEE_RELEASES}")
```

Bazel will create the target `@rules_rust//tools/rust_analyzer:gen_rust_project`, which you can build
with

```
bazel run @rules_rust//tools/rust_analyzer:gen_rust_project
```

Finally, run `bazel run @rules_rust//tools/rust_analyzer:gen_rust_project`
whenever dependencies change to regenerate the `rust-project.json` file. It
should be added to `.gitignore` because it is effectively a build artifact.
Once the `rust-project.json` has been generated in the project root,
rust-analyzer can pick it up upon restart.

#### WORKSPACE

Alternatively, you can use the legacy WORKSPACE approach. As with Bzlmod, ensure `rules_rust` is
setup in your workspace.

Moreover, when loading the dependencies for the tool, you should call the function `rust_analyzer_dependencies()`:

```python
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")

rust_analyzer_dependencies()
```

Again, you can now run `bazel run @rules_rust//tools/rust_analyzer:gen_rust_project`
whenever dependencies change to regenerate the `rust-project.json` file.

For users who do not use `rust_register_toolchains` to register toolchains, the following can be added
to their WORKSPACE to register a `rust_analyzer_toolchain`. Please make sure the Rust version used in
this toolchain matches the version used by the currently registered toolchain or the sources/documentation
Expand Down