golang / protobuf

Go support for Google's protocol buffers
BSD 3-Clause "New" or "Revised" License
9.66k stars 1.58k forks source link

`protoc-gen-go` generates `github.com/golang/protobuf/ptypes/timestamp` imports #1473

Closed maoueh closed 1 year ago

maoueh commented 1 year ago

What version of protobuf and what language are you using?

protoc --version
libprotoc 3.21.4

protoc-gen-go --version
protoc-gen-go v1.28.0

What did you do?

On our project, I had to re-generate the Golang protobuf bindings, it appears for some reason I fail to understand right now that it generates well known types pointing to old package github.com/golang/protobuf/ptypes/timestamp.

cd /tmp
git clone https://github.com/streamingfast/sf-ethereum.git
cd sf-ethereum 
git checkout 01a180c137f8097ec054112a4b52ca8a8bda7fb8 // Just for reproducibility but the same happen on default branch develop
protoc -Iproto --go_out=types/pb --go_opt=paths=source_relative sf/ethereum/type/v1/type.proto
git diff types/pb/sf/ethereum/type/v1/type.pb.go  | grep -Ei 'timestamp(pb)? "'

What did you expect to see?

No changes to the timestamp well known generated types. I tried to replicate using a trimmed down version of our repository but did not succeed to reproduce.

What did you see instead?

Git diff shows that timestamppb "google.golang.org/protobuf/types/known/timestamppb" has changed to timestamp "github.com/golang/protobuf/ptypes/timestamp".

$ git diff types/pb/sf/ethereum/type/v1/type.pb.go  | grep -Ei 'timestamp(pb)? "'
+   timestamp "github.com/golang/protobuf/ptypes/timestamp"
-   timestamppb "google.golang.org/protobuf/types/known/timestamppb"

Anything else we should know about your project / environment?

I tried hard to replicate it on a trimmed down version of project, started with just a type.proto directly but every time it renders it with.

Even tried again back with protoc 3.19.4 and proto-gen-go version 1.25.0, 1.26.0, 1.27.0 and 1.28.0 but every time I get the same thing on this project.

Any clues to create a trimmed down reproducible repo would be appreciated.

puellanivis commented 1 year ago

I can at least repro with the whole project. This seems quite curious.

puellanivis commented 1 year ago

Huh… I found the problem. https://github.com/streamingfast/sf-ethereum/blob/develop/proto/google/protobuf/timestamp.proto#L37

puellanivis commented 1 year ago

I can confirm that changing the go_package on that proto file fixes the imports.

maoueh commented 1 year ago

🤦 oh gosh, didn't realized with had a committed version of the timestamp.proto file, thanks for spotting that and sorry for the trouble.