pb is a Protocol Buffers Build tool that manages dependencies and build configuration
for protoc.
proto-path- Path to.prototo compile using configurationconfig- Path to configuration file to use for compilation
Configuration is provided in HCL with the following top-level configuration fields:
go configures protoc dependencies based on the go.mod, and includes any modules
that contain *.proto files. Fields are:
path- Path to thego.modfile. Relative to configuration or absoluteignores- array of directory paths to ignore for importing*.protofiles
go {
path = "go.mod"
ignores = ["internal"]
}dependencies configures the label dependencies for the provided type at the
version provided
The fields are:
type(label) - The dependency type (either:gitorlocal)name(label) - The name and location of the dependencyversion- The tag or commit to use as a version
dependency "git" "github.com/googleapis/googleapis" {
version = "5518740a67d22a7ad1b0b7656c98211ca5e19307"
}plugin configures protoc plugins for code generation. The fields are:
name- The binary name suffix (i.e. protoc-gen-<name>)path- The path to place generated files, relative to the configurationrel_path- The path to place generated files, relative to the*.protofile being generated foroptions- Options to provide theprotocplugin
plugin "go" {
rel_path = "."
options = {
"paths": "source_relative",
}
}
plugin "go-grpc" {
rel_path = "."
options = {
"paths": "source_relative",
}
}go {
path = "./go.mod"
ignore = ["vendor", "test", "example", "internal"]
}
dependency "git" "github.com/googleapis/googleapis" {
version = "5518740a67d22a7ad1b0b7656c98211ca5e19307"
}
plugin "go" {
rel_path = "."
options = {
"paths": "source_relative",
}
}
plugin "go-grpc" {
rel_path = "."
options = {
"paths": "source_relative",
}
}
plugin "swagger" {
path = "./genspec/openapi/"
options = {
"allow_merge": "true",
"merge_file_name": "api"
}
}
plugin "grpc-gateway" {
rel_path = "."
options = {
"paths": "source_relative",
"allow_patch_feature": "false",
}
}You can use this tool with go generate in place of using Makefiles for protoc generate, by adding a build-tag to a file alongside the .proto file:
//go:generate go run github.com/enmand/pb -proto-path=path/to/service.proto --config=path/to/proto.hcl
package service