bazelbuild / bazelbuild/rules_rust

Error if dependency of dependency is not provided to `proto_library`

Open
#2,681 1 comment 0 reactions 1 assignee Claimed by @UebelAndre View on GitHub
needs-triage proto
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

I have a setup where a `proto_library` (e.g.`bar`) depends on a message from another `proto_library` (e.g. `foo`), and `foo` has an associated service that depends on an external dependency (Google's "empty" PB type).

If I do not include `"@com_google_protobuf//:empty_proto",` as a dependency of `bar`, then building a `rust_prost_library` based on `bar` fails with an error along the lines of `could not find google in the crate root`. However, I don't think I should have to repeat this dependency given `bar` does not use it directly, and it's already specified for `foo`. Repeating the dependency is not required when compiling Go code from these `proto_library` definitions.

I've attached a minimal reproducible example to this issue. To run it:

```console
$ tar -xzvf reproducer.tar.gz
$ bazel build :bar_lib
...
error[E0433]: failed to resolve: could not find `google` in the crate root
--> bazel-out/k8-fastbuild/bin/bar_proto.lib.rs:382:47
|
382 | tonic::Response,
| ^^^^^^ could not find `google` in the crate root

error[E0433]: failed to resolve: could not find `google` in the crate root
--> bazel-out/k8-fastbuild/bin/bar_proto.lib.rs:411:47
|
411 | tonic::Response,
| ^^^^^^ could not find `google` in the crate root

error[E0433]: failed to resolve: could not find `google` in the crate root
--> bazel-out/k8-fastbuild/bin/bar_proto.lib.rs:498:59
|
498 | ... type Response = super::super::google::protobuf::Empty;
| ^^^^^^ could not find `google` in the crate root
...
```

Note if you uncomment line 66 in `BUILD.bazel` (adding the "empty" proto definition as a dependency of `bar_proto`), this error goes away and the library compiles successfully, as expected.

[reproducer.tar.gz](https://github.com/user-attachments/files/15570975/reproducer.tar.gz)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.