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

Consider isolating protobuf files to avoid conflicts with other projects #1177

Open
CMajeri opened this issue Dec 6, 2024 · 3 comments
Open
Assignees
Milestone

Comments

@CMajeri
Copy link

CMajeri commented Dec 6, 2024

Hello,

Golang's protobuf compiler bakes the name of the file used during compilation directly inside the generated source file, and tries to register it (see this long running thread golang/protobuf#1122).

Registering multiple files with the same name causes errors. This is not a blocking issue, since protoc will take the full path used, so running protoc a/common.proto and protoc b/common.proto will work, even if protoc -I a common.proto and protoc -I b common.proto will not.

Currently, the SDK is compiling (at least some of) its proto files, without prefixing them with any sort of path. This causes potential conflicts with projects importing the sdk. It would help reducing some friction if the proto files were compiled using a clear path.

I encountered this with the common.proto file, as our project also has a file with that name. While fixable on our end, it caused a lot of reworking our build process.

@0xivanov 0xivanov self-assigned this Dec 9, 2024
@0xivanov
Copy link
Contributor

0xivanov commented Dec 9, 2024

Hi @CMajeri , thanks for bringing this up. We will look into it.

@0xivanov
Copy link
Contributor

0xivanov commented Jan 3, 2025

Currently, the SDK is compiling (at least some of) its proto files, without prefixing them with any sort of path.

The proto generated files live in proto/... dir, so not sure how it would cause conflicts.

@0xivanov 0xivanov added this to the 2.54.0 milestone Jan 7, 2025
@CMajeri
Copy link
Author

CMajeri commented Jan 14, 2025

The paths where the files live does not matter, it's how protoc is called on them that does.

For instance, if you do protoc proto/common.proto it will reserve the name proto/common.proto, but if you do protoc -I proto common.proto it will reserve the name common.proto.
In go (at least using the common protobuf package), the name will become unusable for any other project trying to register the same name.

Ideally, the path should contain a reference to your repo/org, for instance, google's protobuf files usually live under google/... and we compile them by importing that whole directory.

On the other hand, this sdk comes with pre-compiled proto files, which have been generated without any prefix.

If you find you agree and want to fix it, it's a matter of recompiling the proto using appropriate scope for your include directives. It likely means changing the import directives in your .proto files to match the path as well.

So something like having files live under proto/hedera/..., replacing your imports with import "hedera/...", and then compiling with protoc -I proto hedera/...

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

No branches or pull requests

2 participants