Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support compiling multiple .proto files with a single command #245

Closed
rwlincoln opened this issue Aug 13, 2018 · 7 comments · Fixed by #249
Closed

Support compiling multiple .proto files with a single command #245

rwlincoln opened this issue Aug 13, 2018 · 7 comments · Fixed by #249

Comments

@rwlincoln
Copy link

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.
@johanbrandhorst
Copy link
Collaborator

There's kind of a precedent for not doing this unfortunately: golang/protobuf#39

@rwlincoln
Copy link
Author

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.

@johanbrandhorst
Copy link
Collaborator

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

@stanley-cheung
Copy link
Collaborator

stanley-cheung commented Aug 13, 2018

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.

@rwlincoln
Copy link
Author

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.

@ytkang
Copy link

ytkang commented Jul 5, 2019

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

@hungpv-2039
Copy link

This is worked for me
protoc --grpc-web_out=import_style=typescript,mode=grpcweb:$OUT_DIR \ ./protos/*.proto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants