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

fix(build): Don't replace extern_paths #261

Merged
merged 5 commits into from
Feb 18, 2020

Conversation

cthulhua
Copy link
Contributor

@cthulhua cthulhua commented Feb 6, 2020

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.

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.
Copy link
Member

@LucioFranco LucioFranco left a 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
@cthulhua
Copy link
Contributor Author

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

Thanks, I've added to the docstring for extern_path clarifying the need for fully qualified paths

Copy link
Member

@LucioFranco LucioFranco left a 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
@cthulhua
Copy link
Contributor Author

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.

Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@LucioFranco LucioFranco changed the title tonic-build - don't replace extern_path'd paths fix(build): Don't replace extern_paths Feb 18, 2020
@LucioFranco LucioFranco merged commit 1b3d107 into hyperium:master Feb 18, 2020
@cthulhua cthulhua deleted the extern_path branch February 18, 2020 16:54
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.

3 participants