swift protoc conversion fails with error "google.type.LatLng" is not defined

727 views Asked by At

I am converting .proto files to swift files using command

protoc --swift_out=. my_proto_file.proto

protoc version being used is libprotoc 3.13.0.

my_proto_file has several import statements like

import "google/protobuf/duration.proto";
import "google/type/latlng.proto";

When I run protoc on this proto file I get error like

trackProto.proto:8:1: Import "google/type/latlng.proto" was not found or had errors.
trackProto.proto:153:3: "google.type.LatLng" is not defined.
trackProto.proto:169:3: "google.type.LatLng" is not defined.
trackProto.proto:174:3: "google.type.LatLng" is not defined.

I believe the dependency is on google/type repo. These are not the well known types like google.protobuf.Any, google.protobuf.Api etc so protoc fails to find the dependency and hence fails to generate .swift files

How can I resolve this dependency ?

1

There are 1 answers

0
WorkingMatt On

I downloaded google/type/latlong.proto from https://github.com/googleapis/googleapis/blob/master/google/type/latlng.proto and put that in a local folder e.g. C:\grpc_includes. I repeated for other protos I needed to import e.g. google/protobuf/timestamp.proto. I matched the folder structure indicated by the path e.g. C:\grpc_includes\google\type\latlong.proto.

Then I added --path_proto=<path to my .proto> --path_proto=C:\grpc_includes to my protoc command line. -I=<path to my .proto> -I=C:\grpc_includes also works.

This allowed protoc to find the imports. To use the resultant types of the imports I needed to include the namespace e.g. google.type.LatLng and google.protobuf.Timestamp when using them in my .proto file.

There is some useful information that lead me to the solution here: https://developers.google.com/protocol-buffers/docs/proto?csw=1#generating and here: https://developers.google.com/protocol-buffers/docs/proto3#importing_definitions