I'm trying to use google/protobuf/timestamp.proto
in with gRPC plugin and Go. This is how I run protoc
:
protoc -I ./ ./*.proto --go_out=plugins=grpc:.
And this is my .proto
:
#domain.proto
syntax = "proto3";
option java_multiple_files = true;
option java_package = "com.viant.xyz";
option java_outer_classname = "domain";
import "google/protobuf/timestamp.proto";
message Foo {
Timestamp modifiedTime = 1;
...
}
I'm seeing the following errors:
domain.proto: Import "google/protobuf/timestamp.proto" was not found or had errors.
domain.proto:44:5: "Timestamp" is not defined.
Am I missing something, or this is not yet supported?
Add /usr/local/include
to include paths to use /usr/local/include/google/api/timestamp.proto
:
protoc -I/usr/local/include -I. --go_out=plugins=grpc:. *.proto
As you can see in timestamp.proto
, Timestamp
exists in package google.protobuf
, so you have to modify to use Timestamp
like this:
message Foo {
google.protobuf.Timestamp modifiedTime = 1;
...
}
In my case problem was in my Fedora 29 setup.
# Install Protoc compiler. By default it is 3.5.0 version
sudo dnf -y install protoc
This was my bad setup. So i fixed it with following steps. Pay attention to grayed out command lines too.
# Uninstall old 3.5.0 version
sudo dnf remove protobuf
# Make sure you grab the latest version
curl -OL
https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip
# Unzip
unzip protoc-3.6.1-linux-x86_64.zip -d protoc3
# Move protoc to /usr/local/bin/
sudo mv protoc3/bin/* /usr/local/bin/
# Move protoc3/include to /usr/local/include/
sudo mv protoc3/include/* /usr/local/include/
# Optional: change owner
sudo chown $USER /usr/local/bin/protoc
sudo chown -R $USER /usr/local/include/google
After this I am able to use:
import "google/protobuf/timestamp.proto";
message Session {
google.protobuf.Timestamp create_time = 1;
}
It is not fully supported yet, but you can make it work by changing
message Foo {
google.protobuf.Timestamp modifiedTime = 1;
...
}
and by fixing generated file import
import google_protobuf "google/protobuf/timestamp.pb"
to
import google_protobuf "github.com/golang/protobuf/ptypes/timestamp"
If you are facing this inside an alpine docker image, make sure you do an apk add protobuf-dev
before generating your files using protoc
.
After scratching my head for hours, I've found the issue.
My /usr/local/include directory doesn't have /google/protobuf files and without that once can't use predefined types. To solve this issue.
curl -OL https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-linux-x86_64.zip
unzip protoc-3.2.0-linux-x86_64.zip -d protoc3
sudo mv protoc3/bin/* /usr/local/bin/
sudo mv protoc3/include/* /usr/local/include/
Now you can simply use this command
protoc -I/usr/local/include -I. --go_out= {output_directory_path} {proto_file_path}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With