Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: organize go_proto_libraries #8003

Merged
merged 21 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions api/bazel/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@io_bazel_rules_go//proto:compiler.bzl", "go_proto_compiler")

licenses(["notice"]) # Apache 2

go_proto_compiler(
name = "pgv_plugin_go",
options = ["lang=go"],
plugin = "@com_envoyproxy_protoc_gen_validate//:protoc-gen-validate",
suffix = ".pb.validate.go",
valid_archive = False,
visibility = ["//visibility:public"],
)
58 changes: 58 additions & 0 deletions api/bazel/api_build_system.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@com_google_protobuf//:protobuf.bzl", _py_proto_library = "py_proto_library")
load("@com_envoyproxy_protoc_gen_validate//bazel:pgv_proto_library.bzl", "pgv_cc_proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_grpc_library", "go_proto_library")
load("@io_bazel_rules_go//proto:compiler.bzl", "go_proto_compiler")
load("@io_bazel_rules_go//go:def.bzl", "go_test")

_PY_SUFFIX = "_py"
Expand Down Expand Up @@ -180,3 +181,60 @@ def api_go_test(name, size, importpath, srcs = [], deps = []):
importpath = importpath,
deps = deps,
)

_GO_BAZEL_RULE_MAPPING = {
"@opencensus_proto//opencensus/proto/trace/v1:trace_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_proto_go",
htuch marked this conversation as resolved.
Show resolved Hide resolved
"@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_and_config_proto_go",
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@com_google_googleapis//google/api/expr/v1alpha1:cel_go_proto",
}

def go_proto_mapping(dep):
mapped = _GO_BAZEL_RULE_MAPPING.get(dep)
if mapped == None:
return _Suffix("@" + Label(dep).workspace_name + "//" + Label(dep).package + ":" + Label(dep).name, _GO_PROTO_SUFFIX)
return mapped

def api_proto_package(name, srcs = [], deps = [], has_services = False, visibility = ["//visibility:public"]):
native.proto_library(
name = name,
srcs = srcs,
deps = deps + [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:empty_proto",
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:timestamp_proto",
"@com_google_protobuf//:wrappers_proto",
"@com_google_googleapis//google/api:http_proto",
"@com_google_googleapis//google/api:annotations_proto",
"@com_google_googleapis//google/rpc:status_proto",
"@com_github_gogo_protobuf//:gogo_proto",
"@com_envoyproxy_protoc_gen_validate//validate:validate_proto",
],
visibility = visibility,
)

compilers = ["@io_bazel_rules_go//proto:go_proto", "//bazel:pgv_plugin_go"]
if has_services:
compilers = ["@io_bazel_rules_go//proto:go_grpc", "//bazel:pgv_plugin_go"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that go_proto and go_grpc will not be separate targets anymore? So users no longer have to refer to *_go_grpc and can always just use *_go_proto?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is generally the same go package for proto and gRPC in OSS. Internal rules might still create two different rules if necessary.


go_proto_library(
htuch marked this conversation as resolved.
Show resolved Hide resolved
name = _Suffix(name, _GO_PROTO_SUFFIX),
compilers = compilers,
importpath = _Suffix(_GO_IMPORTPATH_PREFIX, native.package_name()),
proto = name,
visibility = ["//visibility:public"],
deps = [go_proto_mapping(dep) for dep in deps] + [
"@com_github_gogo_protobuf//:gogo_proto_go",
"@com_github_golang_protobuf//ptypes:go_default_library",
"@com_github_golang_protobuf//ptypes/any:go_default_library",
htuch marked this conversation as resolved.
Show resolved Hide resolved
"@com_github_golang_protobuf//ptypes/duration:go_default_library",
"@com_github_golang_protobuf//ptypes/struct:go_default_library",
"@com_github_golang_protobuf//ptypes/timestamp:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@com_envoyproxy_protoc_gen_validate//validate:go_default_library",
"@com_google_googleapis//google/api:annotations_go_proto",
"@com_google_googleapis//google/rpc:status_go_proto",
],
)
15 changes: 14 additions & 1 deletion api/envoy/admin/v2alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_library_internal")
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_library_internal", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
name = "v2alpha",
srcs = glob(["*.proto"]),
kyessenov marked this conversation as resolved.
Show resolved Hide resolved
deps = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do you have default vs. explicit name = "v2",?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started naming them starting from envoy/api/v2/core, and then switched to using the default name. I'm fine making them all to be pkg. I thought envoy/api/v2:v2 looked better at first.

"//envoy/api/v2",
"//envoy/api/v2/auth",
"//envoy/api/v2/core",
"//envoy/config/bootstrap/v2:bootstrap_config",
"//envoy/service/tap/v2alpha:tap_service",
"//envoy/type",
],
)

api_proto_library_internal(
name = "config_dump",
srcs = ["config_dump.proto"],
Expand Down
88 changes: 17 additions & 71 deletions api/envoy/api/v2/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@envoy_api//bazel:api_build_system.bzl", "api_go_grpc_library", "api_go_proto_library", "api_proto_library_internal")
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_library_internal", "api_proto_package")

licenses(["notice"]) # Apache 2

Expand All @@ -16,19 +16,29 @@ package_group(
],
)

api_proto_package(
name = "v2",
srcs = glob(["*.proto"]),
has_services = True,
deps = [
"//envoy/api/v2/auth",
"//envoy/api/v2/cluster",
"//envoy/api/v2/core",
"//envoy/api/v2/endpoint:endpoint_protos",
"//envoy/api/v2/listener:listener_protos",
"//envoy/api/v2/ratelimit:ratelimit_protos",
"//envoy/api/v2/route:route_protos",
"//envoy/type",
],
)

api_proto_library_internal(
name = "discovery",
srcs = ["discovery.proto"],
visibility = [":friends"],
deps = ["//envoy/api/v2/core:base"],
)

api_go_proto_library(
name = "discovery",
proto = ":discovery",
deps = ["//envoy/api/v2/core:base_go_proto"],
)

api_proto_library_internal(
name = "eds",
srcs = ["eds.proto"],
Expand All @@ -44,19 +54,6 @@ api_proto_library_internal(
],
)

api_go_grpc_library(
name = "eds",
proto = ":eds",
deps = [
":discovery_go_proto",
"//envoy/api/v2/core:address_go_proto",
"//envoy/api/v2/core:base_go_proto",
"//envoy/api/v2/core:health_check_go_proto",
"//envoy/api/v2/endpoint:endpoint_go_proto",
"//envoy/type:percent_go_proto",
],
)

api_proto_library_internal(
name = "cds",
srcs = ["cds.proto"],
Expand All @@ -79,26 +76,6 @@ api_proto_library_internal(
],
)

api_go_grpc_library(
name = "cds",
proto = ":cds",
deps = [
":discovery_go_proto",
":eds_go_grpc",
"//envoy/api/v2/auth:cert_go_proto",
"//envoy/api/v2/cluster:circuit_breaker_go_proto",
"//envoy/api/v2/cluster:filter_go_proto",
"//envoy/api/v2/cluster:outlier_detection_go_proto",
"//envoy/api/v2/core:address_go_proto",
"//envoy/api/v2/core:base_go_proto",
"//envoy/api/v2/core:config_source_go_proto",
"//envoy/api/v2/core:health_check_go_proto",
"//envoy/api/v2/core:protocol_go_proto",
"//envoy/api/v2/endpoint:endpoint_go_proto",
"//envoy/type:percent_go_proto",
],
)

api_proto_library_internal(
name = "lds",
srcs = ["lds.proto"],
Expand All @@ -112,17 +89,6 @@ api_proto_library_internal(
],
)

api_go_grpc_library(
name = "lds",
proto = ":lds",
deps = [
":discovery_go_proto",
"//envoy/api/v2/core:address_go_proto",
"//envoy/api/v2/core:base_go_proto",
"//envoy/api/v2/listener:listener_go_proto",
],
)

api_proto_library_internal(
name = "rds",
srcs = ["rds.proto"],
Expand All @@ -136,17 +102,6 @@ api_proto_library_internal(
],
)

api_go_grpc_library(
name = "rds",
proto = ":rds",
deps = [
":discovery_go_proto",
"//envoy/api/v2/core:base_go_proto",
"//envoy/api/v2/core:config_source_go_proto",
"//envoy/api/v2/route:route_go_proto",
],
)

api_proto_library_internal(
name = "srds",
srcs = ["srds.proto"],
Expand All @@ -158,12 +113,3 @@ api_proto_library_internal(
"//envoy/api/v2/route",
],
)

api_go_grpc_library(
name = "srds",
proto = ":srds",
deps = [
":discovery_go_proto",
"//envoy/api/v2/core:base_go_proto",
],
)
19 changes: 9 additions & 10 deletions api/envoy/api/v2/auth/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@envoy_api//bazel:api_build_system.bzl", "api_go_proto_library", "api_proto_library_internal")
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_library_internal", "api_proto_package")

licenses(["notice"]) # Apache 2

Expand All @@ -15,6 +15,14 @@ package_group(
],
)

api_proto_package(
name = "auth",
srcs = glob(["*.proto"]),
deps = [
"//envoy/api/v2/core",
],
)

api_proto_library_internal(
name = "cert",
srcs = ["cert.proto"],
Expand All @@ -24,12 +32,3 @@ api_proto_library_internal(
"//envoy/api/v2/core:config_source",
],
)

api_go_proto_library(
name = "cert",
proto = ":cert",
deps = [
"//envoy/api/v2/core:base_go_proto",
"//envoy/api/v2/core:config_source_go_proto",
],
)
1 change: 0 additions & 1 deletion api/envoy/api/v2/auth/cert.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package envoy.api.v2.auth;
option java_outer_classname = "CertProto";
option java_multiple_files = true;
option java_package = "io.envoyproxy.envoy.api.v2.auth";
option go_package = "auth";

import "envoy/api/v2/core/base.proto";
import "envoy/api/v2/core/config_source.proto";
Expand Down
28 changes: 9 additions & 19 deletions api/envoy/api/v2/cluster/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
load("@envoy_api//bazel:api_build_system.bzl", "api_go_proto_library", "api_proto_library_internal")
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_library_internal", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
name = "cluster",
srcs = glob(["*.proto"]),
deps = [
"//envoy/api/v2/core",
],
)

api_proto_library_internal(
name = "circuit_breaker",
srcs = ["circuit_breaker.proto"],
Expand All @@ -13,14 +21,6 @@ api_proto_library_internal(
],
)

api_go_proto_library(
name = "circuit_breaker",
proto = ":circuit_breaker",
deps = [
"//envoy/api/v2/core:base_go_proto",
],
)

api_proto_library_internal(
name = "outlier_detection",
srcs = ["outlier_detection.proto"],
Expand All @@ -29,20 +29,10 @@ api_proto_library_internal(
],
)

api_go_proto_library(
name = "outlier_detection",
proto = ":outlier_detection",
)

api_proto_library_internal(
name = "filter",
srcs = ["filter.proto"],
visibility = [
"//envoy/api/v2:__pkg__",
],
)

api_go_proto_library(
name = "filter",
proto = ":filter",
)
1 change: 0 additions & 1 deletion api/envoy/api/v2/cluster/circuit_breaker.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package envoy.api.v2.cluster;
option java_outer_classname = "CircuitBreakerProto";
option java_multiple_files = true;
option java_package = "io.envoyproxy.envoy.api.v2.cluster";
option go_package = "cluster";
option csharp_namespace = "Envoy.Api.V2.ClusterNS";
option ruby_package = "Envoy.Api.V2.ClusterNS";

Expand Down
Loading