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

Import Protobuf types from other packages #295

Open
dmdashenkov opened this issue Sep 19, 2019 · 20 comments · May be fixed by #298
Open

Import Protobuf types from other packages #295

dmdashenkov opened this issue Sep 19, 2019 · 20 comments · May be fixed by #298

Comments

@dmdashenkov
Copy link

dmdashenkov commented Sep 19, 2019

Assuming we have 2 Dart packages.
Package A is a library. It defines Protobuf types and Dart utilities to work with them.
Package B depends on A. It also defines Protobuf types, which depend on types from A.

When trying to build B, we cannot avoid re-generating Dart code for Protobuf types is A. If we don't generate A types again, B types are generated with relative imports for B types and do not compile.
Is there a way to make the plugin use absolute imports and configure the mapping of imported types to the Dart packages which contain them?

@sigurdm
Copy link
Collaborator

sigurdm commented Sep 24, 2019

No, I don't think we support such a thing currently.

Are you in control of both A and B? maybe you could gather all the proto files in a shared package C?

@dmdashenkov
Copy link
Author

For us, A is a library and B uses it. We control A but not B.
As the last resort, we have an option of manually substituting import statements. But I was hoping that, maybe, there is already a solution for that.

@sigurdm
Copy link
Collaborator

sigurdm commented Sep 24, 2019

No unfortunately we do not have a thing like that.

How would such an option work? Would it be an option in the .proto file or on the protoc invocation?
I don't think proto imports can have options

@dmdashenkov
Copy link
Author

I'd expect there to be a file-level Protobuf option. Something like

option dart_package = 'helpful_library';

Now when generating code, a protoc compiler has access to the descriptor of imported types (through CodeGeneratorRequest.proto_file). So, when generating Dart code it is possible to scan for this option and use a package-based import instead of a path-based one.

Maybe, you'll have a better idea. The main disadvantage of this solution is that it'd require changing the standard library types (or hardcoding them). In general, this works only if the upstream types are declared with the option.

@dmdashenkov
Copy link
Author

This is similar to other options such as java_pacakge and go_package.

@sigurdm
Copy link
Collaborator

sigurdm commented Sep 26, 2019

That would work I think - but would have to go into package A.

@sigurdm
Copy link
Collaborator

sigurdm commented Sep 27, 2019

Ah - I read again - you control package A. Then this is the right thing to do.

@sigurdm sigurdm linked a pull request Sep 27, 2019 that will close this issue
@sigurdm
Copy link
Collaborator

sigurdm commented Sep 30, 2019

@dmdashenkov would #298 work for your use case?

@dmdashenkov
Copy link
Author

Yes, that PR should solve my problem, as far as I can see. Thanks.

@dmdashenkov
Copy link
Author

Hi. Any updates on the feature status?

@sigurdm
Copy link
Collaborator

sigurdm commented Oct 22, 2019

Sorry for the silence.
I am trying to get a proper option into protobuf itself. (So you would no longer need to import dart_options) it is taking some time.
Hopefully I'll manage, it seems the right way to go.

@dmdashenkov
Copy link
Author

@sigurdm, thanks for the update.
I'd be grateful if there was a channel I could monitor (e.g. a GitHub issue etc.), so you wouldn't have to serve as a data bus). A quick search in protocolbuffers/protobuf didn't give any relevant issue.

@sigurdm
Copy link
Collaborator

sigurdm commented Oct 25, 2019

Sorry - this is currently only tracked on an internal PR.
It would appear as optional string dart_package = 48; in descriptor.proto

@dmdashenkov
Copy link
Author

Hi. Are there any updates on this issue?

@sigurdm
Copy link
Collaborator

sigurdm commented Mar 20, 2020

No unfortunately I had some trouble landing this in the google internal protobuf library, and got swept away with other priorities.

@dave
Copy link

dave commented May 11, 2020

Hey is this going to be back on your radar any time soon? I've been trying to find a workaround for a couple of days now, and without this fix it seems my only option is to bundle all my code together in one package instead of splitting it up.

It sounds like we're waiting for an internal google change, but if there's anything I can help with to get it moving, let me know - I'm happy to help...

@dave
Copy link

dave commented Nov 2, 2020

Just another quick ping on this issue... It would be really great to get it resolved. There's no convenient work-around unfortunately...

@eldrig0
Copy link

eldrig0 commented Jan 20, 2022

any updates on this?

@oklimberg
Copy link

Are there any news on this?

@loeffel-io
Copy link

highly needed

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

Successfully merging a pull request may close this issue.

7 participants