@@ -8,23 +8,46 @@ such a file.
8
8
9
9
### Setup
10
10
11
+ #### Bzlmod
12
+
11
13
First, ensure `rules_rust` is setup in your workspace. By default, `rust_register_toolchains` will
12
14
ensure a [rust_analyzer_toolchain](#rust_analyzer_toolchain) is registered within the WORKSPACE.
13
15
14
16
Next, load the dependencies for the `rust-project.json` generator tool:
15
17
16
18
```python
19
+ # BUILD.bazel
20
+
17
21
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")
22
+ ```
18
23
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
20
29
```
21
30
22
- Finally, run `bazel run @rules_rust//tools/rust_analyzer:gen_rust_project`
23
31
whenever dependencies change to regenerate the `rust-project.json` file. It
24
32
should be added to `.gitignore` because it is effectively a build artifact.
25
33
Once the `rust-project.json` has been generated in the project root,
26
34
rust-analyzer can pick it up upon restart.
27
35
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
+
28
51
For users who do not use `rust_register_toolchains` to register toolchains, the following can be added
29
52
to their WORKSPACE to register a `rust_analyzer_toolchain`. Please make sure the Rust version used in
30
53
this toolchain matches the version used by the currently registered toolchain or the sources/documentation
0 commit comments