Grpc-web: Support compiling multiple .proto files with a single command

Created on 13 Aug 2018  路  6Comments  路  Source: grpc/grpc-web

protoc supports passing multiple .proto files with a single call. Typically, the output directory is specified and the file names are based on the names of the .proto files.

Currently, if more than one service is defined in more than one .proto file, protoc returns an error:

... Tried to write the same file twice.

Most helpful comment

I'm looking for similar but, In my case,

serviceA/a.proto
serviceB/b.proto
...
serviceN/n.proto

I can build these all by one command
protoc --go_out=plugins=grpc:. **/*.proto

All 6 comments

There's kind of a precedent for not doing this unfortunately: https://github.com/golang/protobuf/issues/39

That issue refers to:

Passing multiple packages' worth of *.proto files...

I have a single package that is defined across multiple .proto files in the same directory. Compiling them works unless there are services defined in more than one of the .proto files. In that case, the above error is returned.

Ah ok, slightly different issue then. Sorry for any confusion.

Can you give me an example of your use case? Something abbreviated like below, but illustrating what you mean by "single package that is defined across multiple .proto files", would be great.

file-a.proto

package foo
service FooService {
 rpc Method1(Request1) returns (Response1);
}

file-b.proto

package foo
service FooService {
 rpc Method2....
}

As much details is appreciated.

Here is an example with two separate services defined in the same package. It also relates to #244:

apis/myproject/mayapi/v1/service-a.proto

// Copyright 2018. All rights reserved.

syntax = "proto3";

package myproject.myapi.v1;

import "google/protobuf/wrappers.proto";

service ServiceA {
  rpc MethodA (google.protobuf.StringValue) returns (google.protobuf.StringValue);
}

apis/myproject/mayapi/v1/service-b.proto

// Copyright 2018. All rights reserved.

syntax = "proto3";

package myproject.myapi.v1;

import "google/protobuf/wrappers.proto";

service ServiceB {
  rpc MethodB (google.protobuf.StringValue) returns (google.protobuf.StringValue);
}

With wrappers.proto vendored into apis/google/protobuf/wrappers.proto. It should be possible to call protoc like this:

$ protoc -I./apis ... ./apis/myproject/mayapi/v1/service-a.proto ./apis/myproject/mayapi/v1/service-b.proto

This is possible with the aforementioned golang/protobuf plug-in, which would generate:

./pkg/myproject/myapi/v1/service_a.pb.go
./pkg/myproject/myapi/v1/service_b.pb.go

However, with grpc-web I have to call protoc separately for each file with a service and specify the output file name rather than just the output directory.

Perhaps the out configuration option could be made optional and when omitted a file could be generated for each input .proto that contains a service, with the file name determined by the name of the .proto file.

I'm looking for similar but, In my case,

serviceA/a.proto
serviceB/b.proto
...
serviceN/n.proto

I can build these all by one command
protoc --go_out=plugins=grpc:. **/*.proto

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ivan-sysoi picture ivan-sysoi  路  5Comments

TBoshoven picture TBoshoven  路  4Comments

henpanta picture henpanta  路  5Comments

sirudog picture sirudog  路  3Comments

oferb picture oferb  路  5Comments