From dd5036480d3aa5b18d6195aba06131a04f54e143 Mon Sep 17 00:00:00 2001 From: Alessandro Bertulli Date: Wed, 19 Mar 2025 15:12:47 +0100 Subject: [PATCH 1/3] [Doc] Improve rust analyzer section, distinguishing bzlmod and WORKSPACE --- docs/rust_analyzer.vm | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/rust_analyzer.vm b/docs/rust_analyzer.vm index b9743320b5..6822b95eb2 100644 --- a/docs/rust_analyzer.vm +++ b/docs/rust_analyzer.vm @@ -8,23 +8,46 @@ such a file. ### Setup +#### Bzlmod + 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. Next, load the dependencies for the `rust-project.json` generator tool: ```python +# BUILD.bazel + load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies") +``` -rust_analyzer_dependencies() +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 + +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 From 7744180f5238332d820dcaa3075181738dad19c0 Mon Sep 17 00:00:00 2001 From: Alessandro Bertulli Date: Wed, 30 Apr 2025 12:02:49 +0200 Subject: [PATCH 2/3] [Doc] Clean up the bzlmod approach as much as possible --- docs/rust_analyzer.vm | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/rust_analyzer.vm b/docs/rust_analyzer.vm index 6822b95eb2..14d69b3cc2 100644 --- a/docs/rust_analyzer.vm +++ b/docs/rust_analyzer.vm @@ -10,15 +10,12 @@ such a file. #### Bzlmod -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. - -Next, load the dependencies for the `rust-project.json` generator tool: +First, ensure `rules_rust` is setup in your workspace: ```python -# BUILD.bazel +# MODULE.bazel -load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies") +bazel_dep(name = "rules_rust", version = "0.59.2") ``` Bazel will create the target `@rules_rust//tools/rust_analyzer:gen_rust_project`, which you can build @@ -35,7 +32,8 @@ rust-analyzer can pick it up upon restart. #### WORKSPACE -As with Bzlmod, ensure `rules_rust` is setup in your 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()`: From efcf7bf6e8fb068be71adba447df061a2986cf31 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Wed, 30 Apr 2025 06:54:27 -0700 Subject: [PATCH 3/3] Update docs/rust_analyzer.vm --- docs/rust_analyzer.vm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/rust_analyzer.vm b/docs/rust_analyzer.vm index 14d69b3cc2..58d1789266 100644 --- a/docs/rust_analyzer.vm +++ b/docs/rust_analyzer.vm @@ -15,7 +15,9 @@ First, ensure `rules_rust` is setup in your workspace: ```python # MODULE.bazel -bazel_dep(name = "rules_rust", version = "0.59.2") +# 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