Skip to content

Commit

Permalink
Add go_proto_library plus generated files for "go build". (#72)
Browse files Browse the repository at this point in the history
Generating Go code like this matches the pattern precedented by https://github.com/google/go-genproto for Google APIs.

Generated files are placed in:
- v2/ for remote execution, matching the style used by go-genproto for versioned APIs, e.g. https://github.com/google/go-genproto/blob/master/googleapis/appengine/v1/appengine.pb.go#L4
- semver/ for semver library, matching the style used by go-genproto for unversioned APIs, e.g. https://github.com/google/go-genproto/blob/master/googleapis/api/distribution/distribution.pb.go#L4

Unlike go-genproto, we use Bazel to generate the Go code, which is much simpler, since it handles calling protoc for us. We add a pre-commit hook to generate Go code before each commit, and add it to that commit.

go.mod and go.sum generated by:

```
go mod init github.com/bazelbuild/remote-apis
go build ./...
```

I tested this by creating a Go project that imports this proto and confirmed that I can build it with Bazel and go build.

This addresses issue #65.
  • Loading branch information
jasharpe authored and Ola Rozenfeld committed May 7, 2019
1 parent df1bd78 commit 5556e9c
Show file tree
Hide file tree
Showing 9 changed files with 3,541 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,28 @@ Bazel, you will possibly want to declare `cc_proto_library`,

Other build systems will have to run protoc on the protobuf files, and link in
the googleapis and well-known proto types, manually.

### Go (for non-Bazel build systems)

This repository contains the generated Go code for interacting with the API via
gRPC. Get it with:

```
go get github.com/bazelbuild/remote-apis
```

Import it with, for example:

```
repb "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2"
```

## Development

Enable the git hooks to automatically generate Go proto code on commit:

```
git config core.hooksPath hooks/
```

This is a local setting, so applies only to this repository.
22 changes: 22 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,25 @@ bind(
name = "grpc_lib",
actual = "@com_github_grpc_grpc//:grpc++",
)

# We have to import zlib directly ourselves, because protobuf_deps.bzl isn't
# part of the protobuf release yet
# (https://github.com/protocolbuffers/protobuf/issues/5918). This should be
# fixed in 3.8.0.
http_archive(
name = "net_zlib",
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
sha256 = "6d4d6640ca3121620995ee255945161821218752b551a1a180f4215f7d124d45",
strip_prefix = "zlib-1.2.11",
urls = ["https://zlib.net/zlib-1.2.11.tar.gz"],
)

# Pull in go rules.
http_archive(
name = "io_bazel_rules_go",
sha256 = "86ae934bd4c43b99893fc64be9d9fc684b81461581df7ea8fc291c816f5ee8c5",
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.18.3/rules_go-0.18.3.tar.gz"],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()
20 changes: 20 additions & 0 deletions build/bazel/remote/execution/v2/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package(default_visibility = ["//visibility:public"])
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

licenses(["notice"])

Expand Down Expand Up @@ -37,3 +39,21 @@ cc_grpc_library(
use_external = False,
)

go_proto_library(
name = "remote_execution_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2",
proto = ":remote_execution_proto",
deps = [
"//build/bazel/semver:go_default_library",
"@go_googleapis//google/api:annotations_go_proto",
"@go_googleapis//google/longrunning:longrunning_go_proto",
"@go_googleapis//google/rpc:status_go_proto",
],
)

go_library(
name = "go_default_library",
embed = [":remote_execution_go_proto"],
importpath = "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2",
)
Loading

0 comments on commit 5556e9c

Please sign in to comment.