-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
protoc-gen-go: cannot compile package when import public example.proto
in is present in two or more files
#810
Comments
\cc @neild. I vaguely remember that we addressed this in the v2 re-write of |
import public m.proto
in two files results in a go package that cannot be compiledimport public m.proto
in two files results in a go package that cannot be compiled
import public m.proto
in two files results in a go package that cannot be compiledimport public example.proto
in is present in two files
import public example.proto
in is present in two filesimport public example.proto
in is present in two or more files
We did not, alas. This is, unfortunately, quite difficult to fix. The problem is that we generate each file in a package independently from every other file in the package. If a file includes a public import, we generate forwarding declarations for that import. If two files in the same package include the same public import, each one includes the same forwarding declarations and we have a problem. The fact that files are independent of each other is a rather nice property: It means that you can run protoc on each source We could fix this problem by only generating the forwarding declarations in one of the Or we can say that you should only |
Just as a sanity check, 1) what does C++ do? and 2) do they even support this? I ask because my understanding is that C++ also has the per-file property that we cherish as well, right? |
C++ has the advantage that the protobuf language and its namespace rules map precisely onto C++. I believe |
Java might be the more interesting case. |
Would it break any existing contracts or invariants if the plugin were to place all aliases for a given dependency in a single separate file. This file would be identified (named) by its corresponding public import path. For the example above, it would mean that the aliases for lib/lib.proto would reside in api/lib_lib.aliases.pb.go. Here, I included a path component aliases to avoid naming collisions with potential messages which might result in lib_lib.pb.go. This way, it exists once per package regardless of the number of proto files included in generation. |
Interesting thought. Not very friendly to build systems that want predictable outputs from each compilation action, though. I'll have to think on that. |
That's fair. What if the plugin were to standardize such that there is always a file called It would be somewhat conventional, and would succeed in providing predictable output for build systems. // package api is a foobar
package api
type LibType = lib.LibType |
Putting everything in a single I think the problems with build system integration rule out per-import files (e.g., The most practical answers I see so far are:
|
Ah, yes. I missed that case. |
This seems reasonable to me since For example, consider the following files: //a.proto
syntax = "proto2";
package foo;
message Foo{} //b.proto
syntax = "proto2";
package foo;
message Foo{} Compiling each one individually results in no complaint from
|
import public example.proto
in is present in two or more filesimport public example.proto
in is present in two or more files
There is a slightly unexpected behavior stemming from the use of
import public
.When two proto files in a single package both contain public imports of the same dependency, the resulting package cannot be compiled.
What version of protobuf and what language are you using?
Version: v3.6.1
What did you do?
import public "lib/lib.proto";
import public "lib/lib.proto";
What did you expect to see?
One would expect for the code generation to include at most one type-alias per package for a given public/aliased type.
What did you see instead?
api/foo.pb.go:
api/bar.pb.go:
proposal
generate the type aliases for all types in a given public import in a separate file. this way, the aliases will be present at most once per go package.
The text was updated successfully, but these errors were encountered: