@ -7,9 +7,23 @@ _PY_SUFFIX = "_py"
_CC_SUFFIX = " _cc "
_CC_EXPORT_SUFFIX = " _export_cc "
_GO_PROTO_SUFFIX = " _go_proto "
_GO_GRPC_SUFFIX = " _go_grpc "
_GO_IMPORTPATH_PREFIX = " github.com/envoyproxy/data-plane-api/api/ "
_COMMON_PROTO_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 " ,
]
def _Suffix ( d , suffix ) :
return d + suffix
@ -61,41 +75,6 @@ def py_proto_library(name, deps = []):
visibility = [ " //visibility:public " ] ,
)
def api_go_proto_library ( name , proto , deps = [ ] ) :
go_proto_library (
name = _Suffix ( name , _GO_PROTO_SUFFIX ) ,
importpath = _Suffix ( _GO_IMPORTPATH_PREFIX , name ) ,
proto = proto ,
visibility = [ " //visibility:public " ] ,
deps = deps + [
" @com_github_gogo_protobuf//:gogo_proto_go " ,
" @io_bazel_rules_go//proto/wkt:any_go_proto " ,
" @io_bazel_rules_go//proto/wkt:duration_go_proto " ,
" @io_bazel_rules_go//proto/wkt:struct_go_proto " ,
" @io_bazel_rules_go//proto/wkt:timestamp_go_proto " ,
" @io_bazel_rules_go//proto/wkt:wrappers_go_proto " ,
" @com_envoyproxy_protoc_gen_validate//validate:go_default_library " ,
" @com_google_googleapis//google/rpc:status_go_proto " ,
] ,
)
def api_go_grpc_library ( name , proto , deps = [ ] ) :
go_grpc_library (
name = _Suffix ( name , _GO_GRPC_SUFFIX ) ,
importpath = _Suffix ( _GO_IMPORTPATH_PREFIX , name ) ,
proto = proto ,
visibility = [ " //visibility:public " ] ,
deps = deps + [
" @com_github_gogo_protobuf//:gogo_proto_go " ,
" @io_bazel_rules_go//proto/wkt:any_go_proto " ,
" @io_bazel_rules_go//proto/wkt:duration_go_proto " ,
" @io_bazel_rules_go//proto/wkt:struct_go_proto " ,
" @io_bazel_rules_go//proto/wkt:wrappers_go_proto " ,
" @com_envoyproxy_protoc_gen_validate//validate:go_default_library " ,
" @com_google_googleapis//google/api:annotations_go_proto " ,
] ,
)
# This is api_proto_library plus some logic internal to //envoy/api.
def api_proto_library_internal ( visibility = [ " //visibility:private " ] , * * kwargs ) :
# //envoy/docs/build.sh needs visibility in order to generate documents.
@ -108,8 +87,6 @@ def api_proto_library_internal(visibility = ["//visibility:private"], **kwargs):
# TODO(htuch): has_services is currently ignored but will in future support
# gRPC stub generation.
# TODO(htuch): Automatically generate go_proto_library and go_grpc_library
# from api_proto_library.
def api_proto_library (
name ,
visibility = [ " //visibility:private " ] ,
@ -124,20 +101,7 @@ def api_proto_library(
native . proto_library (
name = name ,
srcs = srcs ,
deps = deps + external_proto_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 " ,
] ,
deps = deps + external_proto_deps + _COMMON_PROTO_DEPS ,
visibility = visibility ,
)
pgv_cc_proto_library (
@ -181,3 +145,50 @@ 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 " ,
" @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 = " pkg " , srcs = [ ] , deps = [ ] , has_services = False , visibility = [ " //visibility:public " ] ) :
if srcs == [ ] :
srcs = native . glob ( [ " *.proto " ] )
native . proto_library (
name = name ,
srcs = srcs ,
deps = deps + _COMMON_PROTO_DEPS ,
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 " ]
go_proto_library (
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 " ,
" @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 " ,
] ,
)