Closed comdiv closed 1 year ago
sudo find / -name "github" | grep proto - empty sudo find / -name "protoc" - only one `/usr/bin/protoc (3.21.12) sudo find / -name "protoc-gen-go":
~/go/pkg/mod/google.golang.org/protobuf@v1.28.1/cmd/protoc-gen-go
~/go/bin/protoc-gen-go
no idea why it could generate old type reference
What are your results from running protoc-gen-go --version
?
I remember someone else having a similar problem, and searching through the issues, 🤔 this can be a complex set of issues. Could you run a sudo find / -name "anypb"
and seeing if you have any local copies of that protobuf installed?
protoc-gen-go --version
->
protoc-gen-go v1.28.1
find:
~/go/pkg/mod/google.golang.org/protobuf@v1.28.1/types/known/anypb
~/go/src/google.golang.org/protobuf/types/known/anypb
Hm, ok, try sudo find / -name "any.proto"
The only thing I can think here is that you have an any.proto
installed somewhere, which is why I suggested the search for anypb
but silly me, that’s not the directory the proto is from, but the directory it gets built into.
Are you certain you're using protoc --go_out
, and not --gogo_out
or some other plugin? What's the exact protoc
line?
One thought on verifying you're using the protoc-gen-go
version you expect:
$ DIR=$(dirname `which protoc`)
$ echo $DIR
/usr/local/bin (or whatever directory contains protoc)
$ rm $DIR/protoc-gen-go
(remove any protoc-gen-go in that directory)
$ mkdir /tmp/out
$ PATH=$DIR protoc --go_out=/tmp/out your.proto
This should fail with an error that `protoc-gen-go` is not found, since it isn't in $PATH.
$ mkdir /tmp/bin
$ GOBIN=/tmp/bin go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
Install protoc-gen-go in /tmp.
$ PATH=$DIR:/tmp/bin protoc --go_out=/tmp/out your.proto
Use the newly-installed protoc.
$ /tmp/bin/protoc-gen-go --version
echo $(dirname
which protoc)
-> /usr/bin
protoc-gen-go
not in same directory, it is at ~/go/bin
delete it
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--go_out: protoc-gen-go: Plugin failed with status code 1.
/tmp/bin/protoc-gen-go --version protoc-gen-go v1.28.1
But.... less my.pb.go
any1 "github.com/golang/protobuf/ptypes/any"
is it possible, that during install it uses not valid src
from GOPATH/src?
checked version of src - no src from github
Check your copy of google/golang/any.proto
? If protoc
is in /usr/bin
it should be in (I think) /usr/include/google/protobuf/any.proto
and should include a line:
option go_package = "google.golang.org/protobuf/types/known/anypb";
oops:
syntax = "proto3";
package google.protobuf;
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
option go_package = "github.com/golang/protobuf/ptypes/any";
option java_package = "com.google.protobuf";
option java_outer_classname = "AnyProto";
option java_multiple_files = true;
option objc_class_prefix = "GPB";
catched, but how to fix?
You should have gotten updated versions of the well-known type .proto
files along with protoc
. The binary distributions available from https://github.com/protocolbuffers/protobuf/releases all include them.
Thank you very much! Replaced with new one from tar
/src/google/protobuf
and reinstall go install ... protoc-gen-go
and now all work well.
Don't know what was the moment of previous include dir creation and why it was not updated when i installed new versions before...
All my team installs
protoc
andprotoc-gen-go
same way:(OS: Linux Mint)
protoc
from https://grpc.io/docs/protoc-installation/, now version v3.21.12protoc-gen-go
withgo install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
All my teammates and CI got:
but at my computer i got:
All checked - $GOPATH, $GOROOT, caches cleaned, mods cleaned - no existence of
github.com/golang/...
related staff on disk. Github version protoc-gen-go was removed in 2021, no mods or bins of it in disk.So I switched to google.golang.org version of protoc-gen-go, but it still generates old
Any
reference, no Idea why. Have discussed it on https://stackoverflow.com/questions/75106683/invalid-proto-any-import-in-golang-protobuf-definiton-github-com-golang-vs-goAll suggestions was to cleanup $GOPATH, $PATH and so on. Especially interesting that it same for new accounts - created fresh account at same computer - install go, protoc, protoc-gen-go - still generates invalid ones!
What I missed?