-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
api_build_system.bzl
152 lines (139 loc) · 6.4 KB
/
api_build_system.bzl
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
load("@com_lyft_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//go:def.bzl", "go_test")
_PY_SUFFIX = "_py"
_CC_SUFFIX = "_cc"
_GO_PROTO_SUFFIX = "_go_proto"
_GO_GRPC_SUFFIX = "_go_grpc"
_GO_IMPORTPATH_PREFIX = "github.com/envoyproxy/data-plane-api/api/"
def _Suffix(d, suffix):
return d + suffix
def _LibrarySuffix(library_name, suffix):
# Transform //a/b/c to //a/b/c:c in preparation for suffix operation below.
if library_name.startswith("//") and ":" not in library_name:
library_name += ":" + Label(library_name).name
return _Suffix(library_name, suffix)
# TODO(htuch): has_services is currently ignored but will in future support
# gRPC stub generation.
# TODO(htuch): Convert this to native py_proto_library once
# https://github.com/bazelbuild/bazel/issues/3935 and/or
# https://github.com/bazelbuild/bazel/issues/2626 are resolved.
def api_py_proto_library(name, srcs = [], deps = [], has_services = 0):
py_proto_library(
name = _Suffix(name, _PY_SUFFIX),
srcs = srcs,
default_runtime = "@com_google_protobuf//:protobuf_python",
protoc = "@com_google_protobuf//:protoc",
deps = [_LibrarySuffix(d, _PY_SUFFIX) for d in deps] + [
"@com_lyft_protoc_gen_validate//validate:validate_py",
"@googleapis//:api_httpbody_protos_py",
"@googleapis//:http_api_protos_py",
"@googleapis//:rpc_status_protos_py",
"@com_github_gogo_protobuf//:gogo_proto_py",
],
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",
"@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_github_golang_protobuf//ptypes/any:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
"@googleapis//: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",
"@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_github_golang_protobuf//ptypes/any:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
"@googleapis//:http_api_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.
if visibility == ["//visibility:private"]:
visibility = ["//docs"]
elif visibility != ["//visibility:public"]:
visibility = visibility + ["//docs"]
api_proto_library(visibility = visibility, **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"], srcs = [], deps = [], has_services = 0, require_py = 1):
# This is now vestigial, since there are no direct consumers in
# the data plane API. However, we want to maintain native proto_library support
# in the proto graph to (1) support future C++ use of native rules with
# cc_proto_library (or some Bazel aspect that works on proto_library) when
# it can play well with the PGV plugin and (2) other language support that
# can make use of native proto_library.
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",
"@googleapis//:api_httpbody_protos_proto",
"@googleapis//:http_api_protos_proto",
"@googleapis//:rpc_status_protos_lib",
"@com_github_gogo_protobuf//:gogo_proto",
"@com_lyft_protoc_gen_validate//validate:validate_proto",
],
visibility = visibility,
)
# Under the hood, this is just an extension of the Protobuf library's
# bespoke cc_proto_library. It doesn't consume proto_library as a proto
# provider. Hopefully one day we can move to a model where this target and
# the proto_library above are aligned.
pgv_cc_proto_library(
name = _Suffix(name, _CC_SUFFIX),
srcs = srcs,
deps = [_LibrarySuffix(d, _CC_SUFFIX) for d in deps],
external_deps = [
"@com_google_protobuf//:cc_wkt_protos",
"@googleapis//:http_api_protos",
"@googleapis//:rpc_status_protos",
"@com_github_gogo_protobuf//:gogo_proto_cc",
],
visibility = ["//visibility:public"],
)
if (require_py == 1):
api_py_proto_library(name, srcs, deps, has_services)
def api_cc_test(name, srcs, proto_deps):
native.cc_test(
name = name,
srcs = srcs,
deps = [_LibrarySuffix(d, _CC_SUFFIX) for d in proto_deps],
)
def api_go_test(name, size, importpath, srcs = [], deps = []):
go_test(
name = name,
size = size,
srcs = srcs,
importpath = importpath,
deps = deps,
)