Skip to content

Commit

Permalink
Add support for generated sources to rust-analyzer. (#2654)
Browse files Browse the repository at this point in the history
At the moment, rust_analyzer's rust-project.json will list the root of a
proto crate as, for example:
`$HOME/.cache/bazel/_bazel_msta/60654fdd7bbd86377eab8595eb8577e8/execroot/_main/bazel-out/k8-dbg/bin/examples/prost/proto/example_proto.lib.rs`.
However, this file does not exist, since it wasn't actually declared as
the output of any rule.

With this change, tools/rust-analyzer will actually generate the
generated sources.
  • Loading branch information
matts1 committed May 16, 2024
1 parent a6222cd commit 1566bad
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions proto/prost/private/prost.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def _rust_prost_aspect_impl(target, ctx):
package_info = package_info_file,
),
rust_analyzer_info,
OutputGroupInfo(rust_generated_srcs = [lib_rs]),
]

rust_prost_aspect = aspect(
Expand Down
4 changes: 3 additions & 1 deletion proto/protobuf/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
),
)

return rustc_compile_action(
providers = rustc_compile_action(
ctx = ctx,
attr = ctx.attr,
toolchain = toolchain,
Expand All @@ -233,6 +233,8 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
),
output_hash = output_hash,
)
providers.append(OutputGroupInfo(rust_generated_srcs = [lib_rs]))
return providers

def _rust_protogrpc_library_impl(ctx, is_grpc):
"""Implementation of the rust_(proto|grpc)_library.
Expand Down
2 changes: 1 addition & 1 deletion tools/rust_analyzer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn generate_crate_info(
"--aspects={}//rust:defs.bzl%rust_analyzer_aspect",
rules_rust.as_ref()
))
.arg("--output_groups=rust_analyzer_crate_spec")
.arg("--output_groups=rust_analyzer_crate_spec,rust_generated_srcs")
.args(targets)
.output()?;

Expand Down

0 comments on commit 1566bad

Please sign in to comment.