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: protobuf namespace conflicts #62

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

guillaumemichel
Copy link
Contributor

@guillaumemichel guillaumemichel commented Jan 17, 2025

Problem

Importing multiple .proto files sharing the same name from distinct repositories will cause protobuf namespace conflicts. In Go, protobuf registers the source of the .proto file as the relative path to where the protoc command was run. Hence we are ending up registering multiple generic record.proto or pb/record.proto across our repos.

Even when the go_package option is set the protobuf registration doesn't take it into account. This is a known issue for Go, but there are no current plans to address it.

For instance go-libp2p-kad-dht depends on both github.com/ipfs/boxo/ipns/pb/record.proto and github.com/libp2p/go-libp2p-record/pb/record.proto, generating a conflict.

panic: proto: file "record.proto" is already registered
		previously from: "github.com/ipfs/boxo/ipns/pb"
		currently from:  "github.com/libp2p/go-libp2p-record/pb"
	See https://protobuf.dev/reference/go/faq#namespace-conflict

Also see ipfs/boxo#788

Solution

Register protobuf files with their full package path (e.g github.com/libp2p/go-libp2p-record/pb/record.proto) prevents namespace conflicts. There is no working option in protoc to include a custom package name that will be registered as the package source. We cannot move or rename record.proto since it would break downstream users.

I updated the protobuf makefile to make this change possible. If there is a better solution, I am happy to adopt it.
Edit: I replaced the makefile with go generate commands.

References

@guillaumemichel guillaumemichel merged commit eecb476 into master Jan 23, 2025
9 checks passed
@guillaumemichel guillaumemichel deleted the fix/pb-namespace-conflicts branch January 23, 2025 12:17
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