Skip to content

Commit ea35d34

Browse files
bertulliUebelAndre
andauthored
[Doc] Improve rust analyzer section, distinguishing bzlmod and WORKSPACE (#3365)
The documentation for the `rust-analyzer` section is outdated, and realtive to the WORKSPACE approach. i tried improving it slightly, distinguishing the bzlmod approach. Right now, calling `rust_analyzer_dependencies()` when using bzlmod seems to throw an error. References issue #2997 --------- Co-authored-by: UebelAndre <github@uebelandre.com>
1 parent b10771c commit ea35d34

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

docs/rust_analyzer.vm

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,46 @@ The `rust_analyzer` rules facilitate both approaches.
1010
## rust-project.json approach
1111
### Setup
1212

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

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

1817
```python
19-
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")
18+
# MODULE.bazel
2019

21-
rust_analyzer_dependencies()
20+
# See releases page for available versions:
21+
# https://github.com/bazelbuild/rules_rust/releases
22+
bazel_dep(name = "rules_rust", version = "{SEE_RELEASES}")
23+
```
24+
25+
Bazel will create the target `@rules_rust//tools/rust_analyzer:gen_rust_project`, which you can build
26+
with
27+
28+
```
29+
bazel run @rules_rust//tools/rust_analyzer:gen_rust_project
2230
```
2331

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

37+
#### WORKSPACE
38+
39+
Alternatively, you can use the legacy WORKSPACE approach. As with Bzlmod, ensure `rules_rust` is
40+
setup in your workspace.
41+
42+
Moreover, when loading the dependencies for the tool, you should call the function `rust_analyzer_dependencies()`:
43+
44+
```python
45+
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")
46+
47+
rust_analyzer_dependencies()
48+
```
49+
50+
Again, you can now run `bazel run @rules_rust//tools/rust_analyzer:gen_rust_project`
51+
whenever dependencies change to regenerate the `rust-project.json` file.
52+
3053
For users who do not use `rust_register_toolchains` to register toolchains, the following can be added
3154
to their WORKSPACE to register a `rust_analyzer_toolchain`. Please make sure the Rust version used in
3255
this toolchain matches the version used by the currently registered toolchain or the sources/documentation

0 commit comments

Comments
 (0)