Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] protos with the same package name prefix fail to compile #2923

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

houqp
Copy link

@houqp houqp commented Oct 6, 2024

When proto files sharing the same package name prefixes reference types from each other, protoc_wrapper will generate code with incorrect module scope resulting in the following compilation error:

error[E0412]: cannot find type `CMessage` in module `super`
  --> bazel-out/darwin_arm64-fastbuild/bin/proto/prost/private/tests/shared_package_prefix/shared_pkg_prefix_proto.lib.rs:21:46
   |
21 |         pub c: ::core::option::Option<super::CMessage>,
   |                                              ^^^^^^^^ not found in `super`
   |
help: consider importing this struct
   |
15 +     use crate::pkg::CMessage;
   |
help: if you import `CMessage`, refer to it directly
   |
21 -         pub c: ::core::option::Option<super::CMessage>,
21 +         pub c: ::core::option::Option<CMessage>,

This Patch refactors the module tree walk implementation to ensure generated rust code are wrapped with the correct rust module hierarchy.

When proto files sharing the same package name prefixes reference types from
each other, protoc_wrapper will generate code with incorrect module
scope resulting in the following compilation error:

```
error[E0412]: cannot find type `CMessage` in module `super`
  --> bazel-out/darwin_arm64-fastbuild/bin/proto/prost/private/tests/shared_package_prefix/shared_pkg_prefix_proto.lib.rs:21:46
   |
21 |         pub c: ::core::option::Option<super::CMessage>,
   |                                              ^^^^^^^^ not found in `super`
   |
help: consider importing this struct
   |
15 +     use crate::pkg::CMessage;
   |
help: if you import `CMessage`, refer to it directly
   |
21 -         pub c: ::core::option::Option<super::CMessage>,
21 +         pub c: ::core::option::Option<CMessage>,
```

This Patch refactors the module tree walk implementation to ensure
generated rust code are wrapped with the correct rust module hierarchy.
Copy link

google-cla bot commented Oct 6, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@houqp
Copy link
Author

houqp commented Oct 9, 2024

@UebelAndre the CI error looks like infra related and not caused by my change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant