Skip to content

Commit 28d5f41

Browse files
authored
proto: unify envoy_proto_library/api_proto_library. (#4233)
In the latest iteration of #4220, it was necessary to use PGV constraints on fuzzer inputs. To do this would require PGV generation in envoy_build_system.bzl. There is also quite a bit of mess in how we were doing envoy_proto_library() today. So, this PR allows us to throw away the custom envoy_proto_library() and benefit from leveraging a single source of Envoy proto build truth. Risk level: Low Testing: bazel test //test/... Signed-off-by: Harvey Tuch <htuch@google.com>
1 parent f7d3cb6 commit 28d5f41

File tree

22 files changed

+83
-99
lines changed

22 files changed

+83
-99
lines changed

api/bazel/api_build_system.bzl

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,16 @@ def api_proto_library_internal(visibility = ["//visibility:private"], **kwargs):
8888
# gRPC stub generation.
8989
# TODO(htuch): Automatically generate go_proto_library and go_grpc_library
9090
# from api_proto_library.
91-
def api_proto_library(name, visibility = ["//visibility:private"], srcs = [], deps = [], has_services = 0, require_py = 1):
91+
def api_proto_library(
92+
name,
93+
visibility = ["//visibility:private"],
94+
srcs = [],
95+
deps = [],
96+
external_proto_deps = [],
97+
external_cc_proto_deps = [],
98+
has_services = 0,
99+
linkstatic = None,
100+
require_py = 1):
92101
# This is now vestigial, since there are no direct consumers in
93102
# the data plane API. However, we want to maintain native proto_library support
94103
# in the proto graph to (1) support future C++ use of native rules with
@@ -99,15 +108,14 @@ def api_proto_library(name, visibility = ["//visibility:private"], srcs = [], de
99108
native.proto_library(
100109
name = name,
101110
srcs = srcs,
102-
deps = deps + [
111+
deps = deps + external_proto_deps + [
103112
"@com_google_protobuf//:any_proto",
104113
"@com_google_protobuf//:descriptor_proto",
105114
"@com_google_protobuf//:duration_proto",
106115
"@com_google_protobuf//:empty_proto",
107116
"@com_google_protobuf//:struct_proto",
108117
"@com_google_protobuf//:timestamp_proto",
109118
"@com_google_protobuf//:wrappers_proto",
110-
"@googleapis//:api_httpbody_protos_proto",
111119
"@googleapis//:http_api_protos_proto",
112120
"@googleapis//:rpc_status_protos_lib",
113121
"@com_github_gogo_protobuf//:gogo_proto",
@@ -123,17 +131,29 @@ def api_proto_library(name, visibility = ["//visibility:private"], srcs = [], de
123131
pgv_cc_proto_library(
124132
name = _Suffix(name, _CC_SUFFIX),
125133
srcs = srcs,
134+
linkstatic = linkstatic,
126135
deps = [_LibrarySuffix(d, _CC_SUFFIX) for d in deps],
127-
external_deps = [
136+
external_deps = external_cc_proto_deps + [
128137
"@com_google_protobuf//:cc_wkt_protos",
129138
"@googleapis//:http_api_protos",
130139
"@googleapis//:rpc_status_protos",
131140
"@com_github_gogo_protobuf//:gogo_proto_cc",
132141
],
133142
visibility = ["//visibility:public"],
134143
)
144+
py_export_suffixes = []
135145
if (require_py == 1):
136146
api_py_proto_library(name, srcs, deps, has_services)
147+
py_export_suffixes = ["_py", "_py_genproto"]
148+
149+
# Allow unlimited visibility for consumers
150+
export_suffixes = ["", "_cc", "_cc_validate", "_cc_proto", "_cc_proto_genproto"] + py_export_suffixes
151+
for s in export_suffixes:
152+
native.alias(
153+
name = name + "_export" + s,
154+
actual = name + s,
155+
visibility = ["//visibility:public"],
156+
)
137157

138158
def api_cc_test(name, srcs, proto_deps):
139159
native.cc_test(

bazel/envoy_build_system.bzl

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library", "py_proto_library")
2+
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_library")
23

34
def envoy_package():
45
native.package(default_visibility = ["//visibility:public"])
@@ -398,55 +399,23 @@ def _proto_header(proto_path):
398399
return None
399400

400401
# Envoy proto targets should be specified with this function.
401-
def envoy_proto_library(
402-
name,
403-
srcs = [],
404-
deps = [],
405-
external_deps = [],
406-
generate_python = True):
407-
# Ideally this would be native.{proto_library, cc_proto_library}.
408-
# Unfortunately, this doesn't work with http_api_protos due to the PGV
409-
# requirement to also use them in the non-native protobuf.bzl
410-
# cc_proto_library; you end up with the same file built twice. So, also
411-
# using protobuf.bzl cc_proto_library here.
412-
cc_proto_deps = []
413-
py_proto_deps = ["@com_google_protobuf//:protobuf_python"]
414-
402+
def envoy_proto_library(name, external_deps = [], **kwargs):
403+
external_proto_deps = []
404+
external_cc_proto_deps = []
415405
if "api_httpbody_protos" in external_deps:
416-
cc_proto_deps.append("@googleapis//:api_httpbody_protos")
417-
py_proto_deps.append("@googleapis//:api_httpbody_protos_py")
418-
419-
if "http_api_protos" in external_deps:
420-
cc_proto_deps.append("@googleapis//:http_api_protos")
421-
py_proto_deps.append("@googleapis//:http_api_protos_py")
422-
423-
if "well_known_protos" in external_deps:
424-
# WKT is already included for Python as part of standard deps above.
425-
cc_proto_deps.append("@com_google_protobuf//:cc_wkt_protos")
426-
427-
cc_proto_library(
428-
name = name,
429-
srcs = srcs,
430-
default_runtime = "@com_google_protobuf//:protobuf",
431-
protoc = "@com_google_protobuf//:protoc",
432-
deps = deps + cc_proto_deps,
406+
external_cc_proto_deps.append("@googleapis//:api_httpbody_protos")
407+
external_proto_deps.append("@googleapis//:api_httpbody_protos_proto")
408+
return api_proto_library(
409+
name,
410+
external_cc_proto_deps = external_cc_proto_deps,
411+
external_proto_deps = external_proto_deps,
433412
# Avoid generating .so, we don't need it, can interfere with builds
434413
# such as OSS-Fuzz.
435414
linkstatic = 1,
436-
alwayslink = 1,
437415
visibility = ["//visibility:public"],
416+
**kwargs
438417
)
439418

440-
if generate_python:
441-
py_proto_library(
442-
name = name + "_py",
443-
srcs = srcs,
444-
default_runtime = "@com_google_protobuf//:protobuf_python",
445-
protoc = "@com_google_protobuf//:protoc",
446-
deps = deps + py_proto_deps,
447-
visibility = ["//visibility:public"],
448-
)
449-
450419
# Envoy proto descriptor targets should be specified with this function.
451420
# This is used for testing only.
452421
def envoy_proto_descriptor(name, out, srcs = [], external_deps = []):

source/common/ratelimit/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ envoy_cc_library(
1414
srcs = ["ratelimit_impl.cc"],
1515
hdrs = ["ratelimit_impl.h"],
1616
deps = [
17-
":ratelimit_proto",
17+
":ratelimit_proto_cc",
1818
"//include/envoy/grpc:async_client_interface",
1919
"//include/envoy/grpc:async_client_manager_interface",
2020
"//include/envoy/ratelimit:ratelimit_interface",

test/common/access_log/BUILD

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ envoy_cc_library(
2424
envoy_proto_library(
2525
name = "access_log_formatter_fuzz_proto",
2626
srcs = ["access_log_formatter_fuzz.proto"],
27-
generate_python = 0,
2827
deps = ["//test/fuzz:common_proto"],
2928
)
3029

@@ -33,7 +32,7 @@ envoy_cc_fuzz_test(
3332
srcs = ["access_log_formatter_fuzz_test.cc"],
3433
corpus = "access_log_formatter_corpus",
3534
deps = [
36-
":access_log_formatter_fuzz_proto",
35+
":access_log_formatter_fuzz_proto_cc",
3736
"//source/common/access_log:access_log_formatter_lib",
3837
"//test/fuzz:utility_lib",
3938
],

test/common/grpc/BUILD

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ envoy_cc_test(
1818
"//test/mocks/http:http_mocks",
1919
"//test/mocks/tracing:tracing_mocks",
2020
"//test/mocks/upstream:upstream_mocks",
21-
"//test/proto:helloworld_proto",
21+
"//test/proto:helloworld_proto_cc",
2222
],
2323
)
2424

@@ -40,7 +40,7 @@ envoy_cc_test(
4040
deps = [
4141
"//source/common/buffer:buffer_lib",
4242
"//source/common/grpc:codec_lib",
43-
"//test/proto:helloworld_proto",
43+
"//test/proto:helloworld_proto_cc",
4444
],
4545
)
4646

@@ -51,7 +51,7 @@ envoy_cc_test(
5151
"//source/common/grpc:common_lib",
5252
"//source/common/http:headers_lib",
5353
"//test/mocks/upstream:upstream_mocks",
54-
"//test/proto:helloworld_proto",
54+
"//test/proto:helloworld_proto_cc",
5555
"//test/test_common:utility_lib",
5656
],
5757
)
@@ -66,7 +66,7 @@ envoy_cc_test(
6666
"//source/common/tracing:http_tracer_lib",
6767
"//test/mocks/grpc:grpc_mocks",
6868
"//test/mocks/tracing:tracing_mocks",
69-
"//test/proto:helloworld_proto",
69+
"//test/proto:helloworld_proto_cc",
7070
"//test/test_common:test_time_lib",
7171
] + envoy_select_google_grpc(["//source/common/grpc:google_async_client_lib"]),
7272
)
@@ -99,7 +99,7 @@ envoy_cc_test_library(
9999
"//source/common/http/http2:conn_pool_lib",
100100
"//test/integration:integration_lib",
101101
"//test/mocks/local_info:local_info_mocks",
102-
"//test/proto:helloworld_proto",
102+
"//test/proto:helloworld_proto_cc",
103103
"//test/test_common:test_time_lib",
104104
],
105105
)

test/common/http/BUILD

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ envoy_cc_test_library(
9696
envoy_proto_library(
9797
name = "conn_manager_impl_fuzz_proto",
9898
srcs = ["conn_manager_impl_fuzz.proto"],
99-
external_deps = ["well_known_protos"],
100-
generate_python = 0,
10199
deps = [
102100
"//test/fuzz:common_proto",
103101
],
@@ -108,7 +106,7 @@ envoy_cc_fuzz_test(
108106
srcs = ["conn_manager_impl_fuzz_test.cc"],
109107
corpus = "conn_manager_impl_corpus",
110108
deps = [
111-
":conn_manager_impl_fuzz_proto",
109+
":conn_manager_impl_fuzz_proto_cc",
112110
"//source/common/common:empty_string",
113111
"//source/common/http:conn_manager_lib",
114112
"//source/common/http:date_provider_lib",
@@ -211,15 +209,14 @@ envoy_cc_test(
211209
envoy_proto_library(
212210
name = "header_map_impl_fuzz_proto",
213211
srcs = ["header_map_impl_fuzz.proto"],
214-
external_deps = ["well_known_protos"],
215212
)
216213

217214
envoy_cc_fuzz_test(
218215
name = "header_map_impl_fuzz_test",
219216
srcs = ["header_map_impl_fuzz_test.cc"],
220217
corpus = "header_map_impl_corpus",
221218
deps = [
222-
":header_map_impl_fuzz_proto",
219+
":header_map_impl_fuzz_proto_cc",
223220
"//source/common/http:header_map_lib",
224221
],
225222
)
@@ -254,7 +251,7 @@ envoy_cc_fuzz_test(
254251
srcs = ["utility_fuzz_test.cc"],
255252
corpus = "utility_corpus",
256253
deps = [
257-
":utility_fuzz_proto",
254+
":utility_fuzz_proto_cc",
258255
"//source/common/http:utility_lib",
259256
"//test/test_common:utility_lib",
260257
],

test/common/http/conn_manager_impl_corpus/example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ actions {
6060
stream_action {
6161
stream_id: 0
6262
response {
63-
continue_100_headers {}
63+
continue_headers {}
6464
}
6565
}
6666
}

test/common/http/conn_manager_impl_fuzz.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ message RequestAction {
6666
// TODO(htuch): Model and fuzz encoder filter buffering/resumption and different status returns.
6767
message ResponseAction {
6868
oneof response_action_selector {
69-
test.fuzz.Headers continue_100_headers = 1;
69+
test.fuzz.Headers continue_headers = 1;
7070
test.fuzz.Headers headers = 2;
7171
uint32 data = 3;
7272
test.fuzz.Headers trailers = 4;

test/common/http/conn_manager_impl_fuzz_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ class FuzzStream {
290290
const test::common::http::ResponseAction& response_action) {
291291
const bool end_stream = response_action.end_stream();
292292
switch (response_action.response_action_selector_case()) {
293-
case test::common::http::ResponseAction::kContinue100Headers: {
293+
case test::common::http::ResponseAction::kContinueHeaders: {
294294
if (state == StreamState::PendingHeaders) {
295295
auto headers = std::make_unique<TestHeaderMapImpl>(
296-
Fuzz::fromHeaders(response_action.continue_100_headers()));
296+
Fuzz::fromHeaders(response_action.continue_headers()));
297297
headers->setReferenceKey(Headers::get().Status, "100");
298298
decoder_filter_->callbacks_->encode100ContinueHeaders(std::move(headers));
299299
}

test/common/http/http2/BUILD

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ envoy_package()
1313
envoy_proto_library(
1414
name = "codec_impl_fuzz_proto",
1515
srcs = ["codec_impl_fuzz.proto"],
16-
external_deps = ["well_known_protos"],
17-
generate_python = 0,
1816
deps = ["//test/fuzz:common_proto"],
1917
)
2018

@@ -23,7 +21,7 @@ envoy_cc_fuzz_test(
2321
srcs = ["codec_impl_fuzz_test.cc"],
2422
corpus = "codec_impl_corpus",
2523
deps = [
26-
":codec_impl_fuzz_proto",
24+
":codec_impl_fuzz_proto_cc",
2725
"//source/common/http:header_map_lib",
2826
"//source/common/http/http2:codec_lib",
2927
"//test/fuzz:utility_lib",

0 commit comments

Comments
 (0)