Create bazel rules for Go gRPC client libraries (#340)

Add Go bazel rules for protos and gRPC.

Signed-off-by: misterwilliam <misterwilliam@google.com>
pull/374/head
William Chang 7 years ago committed by htuch
parent b7e2251090
commit c3bfbc75d9
  1. 2
      .circleci/config.yml
  2. 8
      WORKSPACE
  3. 229
      api/BUILD
  4. 1
      api/base.proto
  5. 2
      bazel/api_build_system.bzl
  6. 48
      bazel/repositories.bzl
  7. 2
      ci/run_envoy_docker.sh
  8. 19
      test/build/BUILD
  9. 18
      test/build/go_build_test.go

@ -2,7 +2,7 @@ version: 2
jobs: jobs:
test: test:
docker: docker:
- image: lyft/envoy-build:114e24c6fd05fc026492e9d2ca5608694e5ea59d - image: envoyproxy/envoy-build:52f6880ffbf761c9b809fc3ac208900956ff16b4
resource_class: xlarge resource_class: xlarge
working_directory: /source working_directory: /source
steps: steps:

@ -30,15 +30,13 @@ new_http_archive(
url = "https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55", url = "https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55",
) )
git_repository( http_archive(
name = "io_bazel_rules_go", name = "io_bazel_rules_go",
remote = "https://github.com/bazelbuild/rules_go.git", url = "https://github.com/bazelbuild/rules_go/releases/download/0.8.1/rules_go-0.8.1.tar.gz",
commit = "4374be38e9a75ff5957c3922adb155d32086fe14", sha256 = "90bb270d0a92ed5c83558b2797346917c46547f6f7103e648941ecdb6b9d0e72",
) )
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains") load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
load("@com_lyft_protoc_gen_validate//bazel:go_proto_library.bzl", "go_proto_repositories") load("@com_lyft_protoc_gen_validate//bazel:go_proto_library.bzl", "go_proto_repositories")
go_proto_repositories(shared=0) go_proto_repositories(shared=0)
go_rules_dependencies() go_rules_dependencies()
go_register_toolchains() go_register_toolchains()
load("@io_bazel_rules_go//proto:def.bzl", "proto_register_toolchains")
proto_register_toolchains()

@ -1,4 +1,5 @@
load("//bazel:api_build_system.bzl", "api_proto_library") load("//bazel:api_build_system.bzl", "api_proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library", "go_grpc_library")
licenses(["notice"]) # Apache 2 licenses(["notice"]) # Apache 2
@ -7,12 +8,39 @@ api_proto_library(
srcs = ["address.proto"], srcs = ["address.proto"],
) )
go_proto_library(
name = "address_go_proto",
importpath = "github.com/envoyproxy/data-plane-api/api/address",
proto = ":address",
visibility = ["//visibility:public"],
deps = [
"@com_github_gogo_protobuf//:gogo_proto_go",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
],
)
api_proto_library( api_proto_library(
name = "base", name = "base",
srcs = ["base.proto"], srcs = ["base.proto"],
deps = [":address"], deps = [":address"],
) )
go_proto_library(
name = "base_go_proto",
importpath = "github.com/envoyproxy/data-plane-api/api/base",
proto = ":base",
visibility = ["//visibility:public"],
deps = [
":address_go_proto",
"@com_github_gogo_protobuf//:gogo_proto_go",
"@com_github_golang_protobuf//ptypes/duration:go_default_library",
"@com_github_golang_protobuf//ptypes/struct:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
],
)
api_proto_library( api_proto_library(
name = "bootstrap", name = "bootstrap",
srcs = ["bootstrap.proto"], srcs = ["bootstrap.proto"],
@ -27,12 +55,44 @@ api_proto_library(
], ],
) )
go_proto_library(
name = "bootstrap_go_proto",
importpath = "github.com/envoyproxy/data-plane-api/api/bootstrap",
proto = ":bootstrap",
visibility = ["//visibility:public"],
deps = [
":address_go_proto",
":base_go_proto",
":cds_go_grpc",
":lds_go_grpc",
":sds_go_grpc",
":stats_go_proto",
":trace_go_proto",
"@com_github_gogo_protobuf//:gogo_proto_go",
"@com_github_golang_protobuf//ptypes/duration:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
],
)
api_proto_library( api_proto_library(
name = "health_check", name = "health_check",
srcs = ["health_check.proto"], srcs = ["health_check.proto"],
deps = [":base"], deps = [":base"],
) )
go_proto_library(
name = "health_check_go_proto",
importpath = "github.com/envoyproxy/data-plane-api/api/health_check",
proto = ":health_check",
visibility = ["//visibility:public"],
deps = [
":base_go_proto",
"@com_github_golang_protobuf//ptypes/duration:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
],
)
api_proto_library( api_proto_library(
name = "cds", name = "cds",
srcs = ["cds.proto"], srcs = ["cds.proto"],
@ -47,6 +107,27 @@ api_proto_library(
], ],
) )
go_grpc_library(
name = "cds_go_grpc",
importpath = "github.com/envoyproxy/data-plane-api/api/cds",
proto = ":cds",
visibility = ["//visibility:public"],
deps = [
":address_go_proto",
":base_go_proto",
":discovery_go_grpc",
":health_check_go_proto",
":protocol_go_proto",
":sds_go_grpc",
"@com_github_gogo_protobuf//:gogo_proto_go",
"@com_github_golang_protobuf//ptypes/duration:go_default_library",
"@com_github_golang_protobuf//ptypes/struct:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
"@googleapis//:http_api_go_proto",
],
)
api_proto_library( api_proto_library(
name = "discovery", name = "discovery",
srcs = ["discovery.proto"], srcs = ["discovery.proto"],
@ -54,6 +135,17 @@ api_proto_library(
deps = [":base"], deps = [":base"],
) )
go_grpc_library(
name = "discovery_go_grpc",
importpath = "github.com/envoyproxy/data-plane-api/api/discovery",
proto = ":discovery",
visibility = ["//visibility:public"],
deps = [
":base_go_proto",
"@com_github_golang_protobuf//ptypes/any:go_default_library",
],
)
api_proto_library( api_proto_library(
name = "eds", name = "eds",
srcs = ["eds.proto"], srcs = ["eds.proto"],
@ -66,6 +158,23 @@ api_proto_library(
], ],
) )
go_grpc_library(
name = "eds_go_grpc",
importpath = "github.com/envoyproxy/data-plane-api/api/eds",
proto = ":eds",
visibility = ["//visibility:public"],
deps = [
":address_go_proto",
":base_go_proto",
":discovery_go_grpc",
":health_check_go_proto",
"@com_github_golang_protobuf//ptypes/duration:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
"@googleapis//:http_api_go_proto",
],
)
api_proto_library( api_proto_library(
name = "grpc_cluster", name = "grpc_cluster",
srcs = ["grpc_cluster.proto"], srcs = ["grpc_cluster.proto"],
@ -81,6 +190,19 @@ api_proto_library(
], ],
) )
go_grpc_library(
name = "hds_go_grpc",
importpath = "github.com/envoyproxy/data-plane-api/api/hds",
proto = ":hds",
visibility = ["//visibility:public"],
deps = [
":base_go_proto",
":health_check_go_proto",
"@com_github_golang_protobuf//ptypes/duration:go_default_library",
"@googleapis//:http_api_go_proto",
],
)
api_proto_library( api_proto_library(
name = "lds", name = "lds",
srcs = ["lds.proto"], srcs = ["lds.proto"],
@ -93,6 +215,23 @@ api_proto_library(
], ],
) )
go_grpc_library(
name = "lds_go_grpc",
importpath = "github.com/envoyproxy/data-plane-api/api/lds",
proto = ":lds",
visibility = ["//visibility:public"],
deps = [
":address_go_proto",
":base_go_proto",
":discovery_go_grpc",
":sds_go_grpc",
"@com_github_golang_protobuf//ptypes/struct:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
"@googleapis//:http_api_go_proto",
],
)
api_proto_library( api_proto_library(
name = "metrics", name = "metrics",
srcs = ["metrics_service.proto"], srcs = ["metrics_service.proto"],
@ -109,12 +248,33 @@ api_proto_library(
srcs = ["protocol.proto"], srcs = ["protocol.proto"],
) )
go_proto_library(
name = "protocol_go_proto",
importpath = "github.com/envoyproxy/data-plane-api/api/protocol",
proto = ":protocol",
visibility = ["//visibility:public"],
deps = [
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
],
)
api_proto_library( api_proto_library(
name = "rls", name = "rls",
srcs = ["rls.proto"], srcs = ["rls.proto"],
has_services = 1, has_services = 1,
) )
go_grpc_library(
name = "rls_go_grpc",
importpath = "github.com/envoyproxy/data-plane-api/api/rls",
proto = ":rls",
visibility = ["//visibility:public"],
deps = [
"@com_lyft_protoc_gen_validate//validate:go_default_library",
],
)
api_proto_library( api_proto_library(
name = "rds", name = "rds",
srcs = ["rds.proto"], srcs = ["rds.proto"],
@ -126,6 +286,23 @@ api_proto_library(
], ],
) )
go_grpc_library(
name = "rds_go_grpc",
importpath = "github.com/envoyproxy/data-plane-api/api/rds",
proto = ":rds",
visibility = ["//visibility:public"],
deps = [
":auth_go_proto",
":base_go_proto",
":discovery_go_grpc",
"@com_github_gogo_protobuf//:gogo_proto_go",
"@com_github_golang_protobuf//ptypes/duration:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
"@googleapis//:http_api_go_proto",
],
)
api_proto_library( api_proto_library(
name = "sds", name = "sds",
srcs = ["sds.proto"], srcs = ["sds.proto"],
@ -136,6 +313,20 @@ api_proto_library(
], ],
) )
go_grpc_library(
name = "sds_go_grpc",
importpath = "github.com/envoyproxy/data-plane-api/api/sds",
proto = ":sds",
visibility = ["//visibility:public"],
deps = [
":base_go_proto",
":discovery_go_grpc",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
"@googleapis//:http_api_go_proto",
],
)
api_proto_library( api_proto_library(
name = "stats", name = "stats",
srcs = ["stats.proto"], srcs = ["stats.proto"],
@ -144,11 +335,35 @@ api_proto_library(
], ],
) )
go_proto_library(
name = "stats_go_proto",
importpath = "github.com/envoyproxy/data-plane-api/api/stats",
proto = ":stats",
visibility = ["//visibility:public"],
deps = [
":address_go_proto",
"@com_github_golang_protobuf//ptypes/struct:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
],
)
api_proto_library( api_proto_library(
name = "trace", name = "trace",
srcs = ["trace.proto"], srcs = ["trace.proto"],
) )
go_proto_library(
name = "trace_go_proto",
importpath = "github.com/envoyproxy/data-plane-api/api/trace",
proto = ":trace",
visibility = ["//visibility:public"],
deps = [
"@com_github_golang_protobuf//ptypes/struct:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
],
)
api_proto_library( api_proto_library(
name = "auth", name = "auth",
srcs = ["auth.proto"], srcs = ["auth.proto"],
@ -157,6 +372,20 @@ api_proto_library(
], ],
) )
go_proto_library(
name = "auth_go_proto",
importpath = "github.com/envoyproxy/data-plane-api/auth",
proto = ":auth",
visibility = ["//visibility:public"],
deps = [
"//api:address_go_proto",
"//api:sds_go_grpc",
"@com_github_golang_protobuf//ptypes/struct:go_default_library",
"@com_github_golang_protobuf//ptypes/timestamp:go_default_library",
"@googleapis//:rpc_status_go_proto",
],
)
# TODO(htuch): Grow this to cover everything we want to generate docs for, so we can just invoke # TODO(htuch): Grow this to cover everything we want to generate docs for, so we can just invoke
# bazel build //api --aspects tools/protodoc/protodoc.bzl%proto_doc_aspect --output_groups=rst # bazel build //api --aspects tools/protodoc/protodoc.bzl%proto_doc_aspect --output_groups=rst
proto_library( proto_library(

@ -1,7 +1,6 @@
syntax = "proto3"; syntax = "proto3";
package envoy.api.v2; package envoy.api.v2;
option go_package = "api";
import "api/address.proto"; import "api/address.proto";

@ -36,6 +36,8 @@ def api_py_proto_library(name, srcs = [], deps = [], has_services = 0):
# TODO(htuch): has_services is currently ignored but will in future support # TODO(htuch): has_services is currently ignored but will in future support
# gRPC stub generation. # gRPC stub generation.
# TODO(htuch): Automatically generate go_proto_library and go_grpc_library
# from api_proto_library.
def api_proto_library(name, srcs = [], deps = [], has_services = 0, require_py = 1): def api_proto_library(name, srcs = [], deps = [], has_services = 0, require_py = 1):
# This is now vestigial, since there are no direct consumers in # This is now vestigial, since there are no direct consumers in
# data-plane-api. However, we want to maintain native proto_library support # data-plane-api. However, we want to maintain native proto_library support

@ -16,6 +16,7 @@ def api_dependencies():
url = "https://github.com/googleapis/googleapis/archive/" + GOOGLEAPIS_SHA + ".tar.gz", url = "https://github.com/googleapis/googleapis/archive/" + GOOGLEAPIS_SHA + ".tar.gz",
build_file_content = """ build_file_content = """
load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library", "py_proto_library") load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library", "py_proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
filegroup( filegroup(
name = "http_api_protos_src", name = "http_api_protos_src",
@ -26,6 +27,13 @@ filegroup(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
go_proto_library(
name = "descriptor_go_proto",
importpath = "github.com/golang/protobuf/protoc-gen-go/descriptor",
proto = "@com_google_protobuf//:descriptor_proto",
visibility = ["//visibility:public"],
)
proto_library( proto_library(
name = "http_api_protos_proto", name = "http_api_protos_proto",
srcs = [":http_api_protos_src"], srcs = [":http_api_protos_src"],
@ -57,6 +65,17 @@ py_proto_library(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = ["@com_google_protobuf//:protobuf_python"], deps = ["@com_google_protobuf//:protobuf_python"],
) )
go_proto_library(
name = "http_api_go_proto",
importpath = "google.golang.org/genproto/googleapis/api/annotations",
proto = ":http_api_protos_proto",
visibility = ["//visibility:public"],
deps = [
":descriptor_go_proto",
],
)
filegroup( filegroup(
name = "rpc_status_protos_src", name = "rpc_status_protos_src",
srcs = [ srcs = [
@ -81,6 +100,17 @@ cc_proto_library(
], ],
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
go_proto_library(
name = "rpc_status_go_proto",
importpath = "google.golang.org/genproto/googleapis/rpc/status",
proto = ":rpc_status_protos_lib",
visibility = ["//visibility:public"],
deps = [
"@com_github_golang_protobuf//ptypes/any:go_default_library",
],
)
py_proto_library( py_proto_library(
name = "rpc_status_protos_py", name = "rpc_status_protos_py",
srcs = [ srcs = [
@ -101,6 +131,7 @@ py_proto_library(
url = "https://github.com/gogo/protobuf/archive/" + GOGOPROTO_SHA + ".tar.gz", url = "https://github.com/gogo/protobuf/archive/" + GOGOPROTO_SHA + ".tar.gz",
build_file_content = """ build_file_content = """
load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library", "py_proto_library") load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library", "py_proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
proto_library( proto_library(
name = "gogo_proto", name = "gogo_proto",
@ -113,6 +144,13 @@ proto_library(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
go_proto_library(
name = "descriptor_go_proto",
importpath = "github.com/golang/protobuf/protoc-gen-go/descriptor",
proto = "@com_google_protobuf//:descriptor_proto",
visibility = ["//visibility:public"],
)
cc_proto_library( cc_proto_library(
name = "gogo_proto_cc", name = "gogo_proto_cc",
srcs = [ srcs = [
@ -124,6 +162,16 @@ cc_proto_library(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
go_proto_library(
name = "gogo_proto_go",
importpath = "gogoproto",
proto = ":gogo_proto",
visibility = ["//visibility:public"],
deps = [
":descriptor_go_proto",
],
)
py_proto_library( py_proto_library(
name = "gogo_proto_py", name = "gogo_proto_py",
srcs = [ srcs = [

@ -2,7 +2,7 @@
set -e set -e
[[ -z "${IMAGE_NAME}" ]] && IMAGE_NAME="lyft/envoy-build-ubuntu" [[ -z "${IMAGE_NAME}" ]] && IMAGE_NAME="envoyproxy/envoy-build"
[[ -z "${IMAGE_ID}" ]] && IMAGE_ID="latest" [[ -z "${IMAGE_ID}" ]] && IMAGE_ID="latest"
[[ -z "${ENVOY_API_DOCKER_BUILD_DIR}" ]] && ENVOY_API_DOCKER_BUILD_DIR=/tmp/envoy-api-docker-build [[ -z "${ENVOY_API_DOCKER_BUILD_DIR}" ]] && ENVOY_API_DOCKER_BUILD_DIR=/tmp/envoy-api-docker-build

@ -1,4 +1,5 @@
load("//bazel:api_build_system.bzl", "api_cc_test") load("//bazel:api_build_system.bzl", "api_cc_test")
load("@io_bazel_rules_go//go:def.bzl", "go_test")
licenses(["notice"]) # Apache 2 licenses(["notice"]) # Apache 2
@ -17,3 +18,21 @@ api_cc_test(
"//api/filter/accesslog", "//api/filter/accesslog",
], ],
) )
go_test(
name = "go_build_test",
size = "small",
srcs = ["go_build_test.go"],
importpath = "go_build_test",
deps = [
"//api:bootstrap_go_proto",
"//api:cds_go_grpc",
"//api:discovery_go_grpc",
"//api:eds_go_grpc",
"//api:hds_go_grpc",
"//api:lds_go_grpc",
"//api:rds_go_grpc",
"//api:rls_go_grpc",
"//api:sds_go_grpc",
],
)

@ -0,0 +1,18 @@
package go_build_test
import (
"testing"
_ "github.com/envoyproxy/data-plane-api/api/bootstrap"
_ "github.com/envoyproxy/data-plane-api/api/discovery"
_ "github.com/envoyproxy/data-plane-api/api/cds"
_ "github.com/envoyproxy/data-plane-api/api/eds"
_ "github.com/envoyproxy/data-plane-api/api/hds"
_ "github.com/envoyproxy/data-plane-api/api/lds"
_ "github.com/envoyproxy/data-plane-api/api/rds"
_ "github.com/envoyproxy/data-plane-api/api/rls"
_ "github.com/envoyproxy/data-plane-api/api/sds"
)
func TestNoop(t *testing.T) {
// Noop test that verifies the successful importation of Envoy V2 API protos
}
Loading…
Cancel
Save