1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
# protobuild
[](https://github.com/containerd/protobuild/actions?query=workflow%3ACI)
[](https://goreportcard.com/report/github.com/containerd/protobuild)
Build protobufs in Go, easily.
`protobuild` works by scanning the go package in a project and emitting correct
`protoc` commands, configured with the plugins, packages and details of your
choice.
The main benefit is that it makes it much easier to consume external types from
vendored projects. By integrating the protoc include paths with Go's vendoring
and GOPATH, builds are much easier to keep consistent across a project.
This comes from experience with generating protobufs with `go generate` in
swarmkit and the tool used with containerd. It should replace both.
## Status
Very early stages.
## Installation
To ensure easy use with builds, we'll try to support `go get`. Install with the
following command:
```
go get -u github.com/containerd/protobuild
```
## Usage
Protobuild works by providing a list of Go packages in which to build the
protobufs. To get started with a project, you must do the following:
1. Create a `Protobuild.toml` file in the root of your Go project. Use the
[example](Protobuild.toml) as a starting point.
2. Make sure that the packages where you want your protobuf files have a Go
file in place. Usually, adding a `doc.go` file is sufficient. A package for
protobuf should look like this:
```
foo.proto
doc.go
```
Where the contents of `doc.go` will have a package declaration in it. See
the [example](examples/foo/doc.go) for details. Make sure the package name
corresponds to what is in the `go_package` option.
3. Run the `protobuild` command:
```
go list ./... | grep -v vendor | xargs protobuild
```
## Version Compatibility
Originally protoc-gen-go was supporting gRPC through its plugins mechanism.
[However gRPC support is later extracted as protoc-gen-go-gprc binary](https://github.com/protocolbuffers/protobuf-go/releases/tag/v1.20.0#user-content-v1.20-grpc-support).
To use protoc-gen-go and protoc-gen-go-grpc. Please specify `version = "2"` and
both code generators instead of `plugins` like below.
```
version = "2"
generators = ["go", "go-grpc"]
```
## Project details
protobuild is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE).
As a containerd sub-project, you will find the:
* [Project governance](https://github.com/containerd/project/blob/master/GOVERNANCE.md),
* [Maintainers](https://github.com/containerd/project/blob/master/MAINTAINERS),
* and [Contributing guidelines](https://github.com/containerd/project/blob/master/CONTRIBUTING.md)
information in our [`containerd/project`](https://github.com/containerd/project) repository.
|