-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix(build): Don't replace extern_paths #261
Conversation
tonic-build will replace all paths except for google well known types with one rooted at the super module. For paths that have already been replaced with a fully qualified path via the extern_path config option, (e.g. "::uuid::Uuid"), this results in an invalid path (e.g. "super::::uuid::Uuid"), and a build failure. These paths should also be excluded when prefixing relative modules with super.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay in review! I think this makes sense, though we should add this somewhere to the docs. I think under extern_path state that you need to prefix them with ::
. Otherwise LGTM
extern_path expects fully qualified proto and rust paths
Thanks, I've added to the docstring for extern_path clarifying the need for fully qualified paths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see one last thing, I am worried that rustfmt
removes the leading ::
so I'm curious if we could add a test https://github.com/hyperium/tonic/tree/master/tests here to make sure this doesn't happen.
add a test that extern path does indeed result in service types using the specified type from an external crate. we test this by creating a service type that has a proto from a different crate, and asserting that it does indeed impl a trait from that crate
Sorry about the delay; been caught up in quite a bit recently. I adapted my repro crates into tests; i just assert that a type generated from a service uses an external crate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks!
tonic-build will replace all paths except for google well known types
with one rooted at the super module. For paths that have already been
replaced with a fully qualified path via the extern_path config option,
(e.g. "::uuid::Uuid"), this results in an invalid path
(e.g. "super::::uuid::Uuid"), and a build failure. These paths should
also be excluded when prefixing relative modules with super.
Motivation
See commit message, and #260
When extern_path'd are used in service method definitions, prost-build panics.
See https://github.com/cthulhua/tonic_extern_path/tree/master for a repro of the issue (it works when build against this branch).
Solution
Similar to how google well known types are handled, in the event an absolute path would be made relative, leave it absolute.