I'm sharing .proto files across multiple projects using git-submodules.
Now my question is how to setup the imports properly?
In a microservice environment all service-repositories have a git-submodule containing the shared .proto files:
- git.dev/fooservice
- proto (contains
git.dev/proto
as submodule) - ... some java code
- proto (contains
- git.dev/barservice
- proto (contains
git.dev/proto
as submodule) - ... some go code
- proto (contains
- git.dev/bazservice
- proto (contains
git.dev/proto
as submodule) - ... some javascript code
- proto (contains
- git.dev/proto
- shared
- shared.proto
- fooservice
- fooservice.proto (imports
shared/shared.proto
)
- fooservice.proto (imports
- barservice
- barservice.proto (imports
shared/shared.proto
)
- barservice.proto (imports
- shared
The typical header of a service proto file currently looks like this:
git.dev/proto/fooservice/fooservice.proto
syntax = "proto3";
package abc.foo;
import "shared/shared.proto";
option go_package = "foopb";
option java_multiple_files = true;
option java_outer_classname = "FooProto";
option java_package = "com.abc.foo";
Question 1: Import path
- Having it
import "shared/shared.proto";
works for linting of the git.dev/proto repo, but causes import-problems during code generation. - Having it
import "proto/shared/shared.proto";
works for code generation in the service-repos but of course causes linting problems in the git.dev/proto repo - Should the import statement contain the
proto
folder?
Question 2: go_package Option
- to build the go stubs we currently use prototool to and set the
go_options.import_path
to e.g.git.dev/fooservice
which generates correct golang import paths - another option would be to run something like
for x in proto/**/*.proto; do protoc -Iproto --go_out=plugins=grpc,paths=source_relative:src/proto $x; done
but this does not result in valid golang import paths as long as I don't add the full git path to the go_package option. Doing that of course conflicts with the git-submodule approach (which git repo path to choose, /proto or /*service.git ?).
- What's best practice using go_package in combination with git-submodules?
Question 3: submodules and 3rd-party tools
- Is using git-submodules and 3rd-party tools like prototool the right way to work with proto files across multiple projects?
Thanks!