Skip to content

Commit eec09aa

Browse files
Alessandro Bertullibertulli
Alessandro Bertulli
authored andcommitted
[Doc] Improve rust analyzer section, distinguishing bzlmod and WORKSPACE
1 parent 633e56d commit eec09aa

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

Diff for: docs/rust_analyzer.vm

+25-2
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,46 @@ such a file.
88

99
### Setup
1010

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

1416
Next, load the dependencies for the `rust-project.json` generator tool:
1517

1618
```python
19+
# BUILD.bazel
20+
1721
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")
22+
```
1823

19-
rust_analyzer_dependencies()
24+
Bazel will create the target `@rules_rust//tools/rust_analyzer:gen_rust_project`, which you can build
25+
with
26+
27+
```
28+
bazel run @rules_rust//tools/rust_analyzer:gen_rust_project
2029
```
2130

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

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

0 commit comments

Comments
 (0)