Skip to content

Commit 21b52ba

Browse files
authored
go proto: include (opt-in) vtprotobuf generation (#31172)
See envoyproxy/go-control-plane#824 for more information This PR adds the vtprotobuf protoc plugin for Go. This works on top of the existing protoc-gen-go, to add optimized marshal functions that callers can opt in to using. This is not like gogo, which was a very invasive change -- everything is layered and opt-in. See issue for benchmarks, etc. Additionally, to avoid possible binary size increase, the entire new code is protected under a go build tag. Users will need to opt-in at build time (-tags=vtprotobuf). By default, there is no impact for users at all. Risk Level: Low - only additional opt-in code Testing: Manually tested in Istio codebase Signed-off-by: John Howard <[email protected]>
1 parent f520e8e commit 21b52ba

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

api/bazel/BUILD

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ go_proto_compiler(
2626
visibility = ["//visibility:public"],
2727
)
2828

29+
go_proto_compiler(
30+
name = "vtprotobuf_plugin_go",
31+
options = ["features=marshal_strict+size"],
32+
plugin = "@com_github_planetscale_vtprotobuf//cmd/protoc-gen-go-vtproto",
33+
suffix = "_vtproto.pb.go",
34+
valid_archive = False,
35+
visibility = ["//visibility:public"],
36+
)
37+
2938
json_data(
3039
name = "repository_locations",
3140
data = load_repository_locations_spec(REPOSITORY_LOCATIONS_SPEC),

api/bazel/api_build_system.bzl

+9-2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ def api_proto_package(
146146
has_services = has_services,
147147
)
148148

149-
compilers = ["@io_bazel_rules_go//proto:go_proto", "@envoy_api//bazel:pgv_plugin_go"]
149+
compilers = ["@io_bazel_rules_go//proto:go_proto", "@envoy_api//bazel:pgv_plugin_go", "@envoy_api//bazel:vtprotobuf_plugin_go"]
150150
if has_services:
151-
compilers = ["@io_bazel_rules_go//proto:go_grpc", "@envoy_api//bazel:pgv_plugin_go"]
151+
compilers = ["@io_bazel_rules_go//proto:go_grpc", "@envoy_api//bazel:pgv_plugin_go", "@envoy_api//bazel:vtprotobuf_plugin_go"]
152152

153153
deps = (
154154
[_go_proto_mapping(dep) for dep in deps] +
@@ -162,6 +162,13 @@ def api_proto_package(
162162
"@io_bazel_rules_go//proto/wkt:struct_go_proto",
163163
"@io_bazel_rules_go//proto/wkt:timestamp_go_proto",
164164
"@io_bazel_rules_go//proto/wkt:wrappers_go_proto",
165+
"@com_github_planetscale_vtprotobuf//types/known/anypb",
166+
"@com_github_planetscale_vtprotobuf//types/known/durationpb",
167+
"@com_github_planetscale_vtprotobuf//types/known/emptypb",
168+
"@com_github_planetscale_vtprotobuf//types/known/fieldmaskpb",
169+
"@com_github_planetscale_vtprotobuf//types/known/structpb",
170+
"@com_github_planetscale_vtprotobuf//types/known/timestamppb",
171+
"@com_github_planetscale_vtprotobuf//types/known/wrapperspb",
165172
]
166173
)
167174
go_proto_library(

bazel/dependency_imports.bzl

+7
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, y
146146
# use_category = ["api"],
147147
# source = "https://github.com/bufbuild/protoc-gen-validate/blob/v0.6.1/dependencies.bzl#L23-L28"
148148
)
149+
go_repository(
150+
name = "com_github_planetscale_vtprotobuf",
151+
importpath = "github.com/planetscale/vtprotobuf",
152+
sum = "h1:nve54OLsoKDQhb8ZnnHHUyvAK3vjBiwTEJeC3UsqzJ8=",
153+
version = "v0.5.1-0.20231205081218-d930d8ac92f8",
154+
build_external = "external",
155+
)
149156

150157
protoc_gen_jsonschema_go_dependencies()
151158

ci/do_ci.sh

+5
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ case $CI_TARGET in
308308
if [[ "$GO_FILE" = *.validate.go ]]; then
309309
sed -i '1s;^;//go:build !disable_pgv\n;' "$OUTPUT_DIR/$(basename "$GO_FILE")"
310310
fi
311+
# TODO(https://github.com/planetscale/vtprotobuf/pull/122) do this directly in the generator.
312+
# Make vtprotobuf opt-in as it has some impact on binary sizes
313+
if [[ "$GO_FILE" = *.vtproto.pb.go ]]; then
314+
sed -i '1s;^;//go:build vtprotobuf\n;' "$OUTPUT_DIR/$(basename "$GO_FILE")"
315+
fi
311316
done <<< "$(find "$INPUT_DIR" -name "*.go")"
312317
done
313318
;;

0 commit comments

Comments
 (0)