So this seems to be another one of those artifacts of Google's mono-repo (Bazel) view of the world -- where each file is used with the full path and uniquely identify it.
Thanks for the link to the issue: this is a 4 years old issue, with dozen of followers. For the record, and anyone ending in this thread: the long story (in the issue) short: there is no clean solution, and proto maintainers are not likely to solve it (my understanding from reading the issue in github) I proposed a relatively simple work around by wrapping protoc with a script that uses the go import path (of the package in the current directory) as a unique key along the file name, which seems the correct result to achieve for a global unique name: see https://github.com/golang/protobuf/issues/1122#issuecomment-2518289653 Thanks Em, the pointers are very appreciated. Jan On Wednesday, December 4, 2024 at 5:35:11 PM UTC+1 Em Rauch wrote: > I believe the issue is more inherent to protobuf in general and not a Go > specific thing; basically if you have a file that does `import "x.proto"` > that needs to be able to be resolved uniquely. Note that it should not > require the _file names_ themselves to be globally unique, the problem > arises when you invoke protoc with something like this: > > protoc -Iproject1 project1/foo.proto > protoc -Iproject2 project2/foo.proto > > Which results in the two files being represented as their (necessarily > globally unique name) of just "foo.proto". > > If you instead invoke proto without the -I, there would be no conflict > (because the two files will have their canonical file names as > "project1/foo.proto" and "project2/foo.proto"): > > protoc project1/foo.proto > protoc project2/foo.proto > > You may find more discussion about this (including some details which are > Go specific) here: https://github.com/golang/protobuf/issues/1122 > > > On Wed, Dec 4, 2024 at 11:18 AM Jan Pfeifer <[email protected]> wrote: > >> hi all, >> >> Today I bumped into the conflicting file name registration runtime error >> below. >> >> ``` >> panic: proto: file "sentencepiece_model.proto" is already registered >> previously from: "github.com/eliben/go-sentencepiece/internal/model >> <http://127.0.0.1:8889/eliben/go-sentencepiece/internal/model>" >> currently from: "github.com >> /gomlx/go-huggingface/tokenizers/sentencepiece/private/protos >> <http://127.0.0.1:8889/gomlx/go-huggingface/tokenizers/sentencepiece/private/protos>" >> >> See https://protobuf.dev/reference/go/faq#namespace-conflict >> ``` >> >> The two libraries I'm using define the protos under different proto >> `package` names, as well as different `option go_package` paths -- so in >> principle, I understand, the protos they define should be unrelated and >> have no conflict. >> >> For the record, `syntax = "proto2"` is defined in both proto files. >> >> Just the last part of the file name ("sentencepiece_model.proto") are the >> same, they are in different paths. >> >> I own one of these libraries, so I could change the file name to >> something like: >> >> "sentencepiece_model_<unique_hash>.proto" >> >> And that works as expected -- but it is a sad solution :). >> >> Am I misunderstanding the error ? Any suggestions on how to prevent such >> conflicts ? >> >> Many thanks in advance. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Protocol Buffers" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion visit >> https://groups.google.com/d/msgid/protobuf/9ab9719e-dda1-4809-ac61-89b41a4a9ae7n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/protobuf/9ab9719e-dda1-4809-ac61-89b41a4a9ae7n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/protobuf/7b338de6-db5b-4ad6-aaed-e281a7e26625n%40googlegroups.com.
