Skip to content

Commit 90f8af5

Browse files
hauserxUebelAndre
andauthored
Add prost and tonic deps in rust-project.json if needed for proto (#3270)
Generated rust code references prost (and possibly tonic), so those dependencies are needed for rust-analyzer to correctly inspect code. Fixes #3189 Co-authored-by: UebelAndre <github@uebelandre.com>
1 parent db73f12 commit 90f8af5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

extensions/prost/private/prost.bzl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
44
load("@rules_proto//proto:defs.bzl", "ProtoInfo", "proto_common")
55
load("@rules_proto//proto:proto_common.bzl", proto_toolchains = "toolchains")
6-
load("@rules_rust//rust:defs.bzl", "rust_common")
6+
load("@rules_rust//rust:defs.bzl", "rust_analyzer_aspect", "rust_common")
77

88
# buildifier: disable=bzl-visibility
99
load("@rules_rust//rust/private:providers.bzl", "RustAnalyzerGroupInfo", "RustAnalyzerInfo")
@@ -233,6 +233,7 @@ def _rust_prost_aspect_impl(target, ctx):
233233

234234
rustfmt_toolchain = ctx.toolchains["@rules_rust//rust/rustfmt:toolchain_type"]
235235
prost_toolchain = ctx.toolchains[TOOLCHAIN_TYPE]
236+
rust_analyzer_deps = []
236237
for prost_runtime in [prost_toolchain.prost_runtime, prost_toolchain.tonic_runtime]:
237238
if not prost_runtime:
238239
continue
@@ -246,12 +247,15 @@ def _rust_prost_aspect_impl(target, ctx):
246247
cc_info = prost_runtime[CcInfo] if CcInfo in prost_runtime else None,
247248
build_info = None,
248249
))
250+
if RustAnalyzerInfo in prost_runtime:
251+
rust_analyzer_deps.append(prost_runtime[RustAnalyzerInfo].deps)
252+
if RustAnalyzerGroupInfo in prost_runtime:
253+
rust_analyzer_deps.extend(prost_runtime[RustAnalyzerGroupInfo].deps)
249254

250255
proto_deps = getattr(ctx.rule.attr, "deps", [])
251256

252257
direct_deps = []
253258
transitive_deps = [depset(runtime_deps)]
254-
rust_analyzer_deps = []
255259
for proto_dep in proto_deps:
256260
proto_info = proto_dep[ProstProtoInfo]
257261

@@ -474,6 +478,7 @@ rust_prost_toolchain = rule(
474478
doc = "The Prost runtime crates to use.",
475479
providers = [[rust_common.crate_info], [rust_common.crate_group_info]],
476480
mandatory = True,
481+
aspects = [rust_analyzer_aspect],
477482
),
478483
"prost_types": attr.label(
479484
doc = "The Prost types crates to use.",
@@ -500,6 +505,7 @@ rust_prost_toolchain = rule(
500505
"tonic_runtime": attr.label(
501506
doc = "The Tonic runtime crates to use.",
502507
providers = [[rust_common.crate_info], [rust_common.crate_group_info]],
508+
aspects = [rust_analyzer_aspect],
503509
),
504510
}, **proto_toolchains.if_legacy_toolchain({
505511
"_legacy_proto_toolchain": attr.label(

0 commit comments

Comments
 (0)