• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2009-2021, Google LLC
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are met:
6#     * Redistributions of source code must retain the above copyright
7#       notice, this list of conditions and the following disclaimer.
8#     * Redistributions in binary form must reproduce the above copyright
9#       notice, this list of conditions and the following disclaimer in the
10#       documentation and/or other materials provided with the distribution.
11#     * Neither the name of Google LLC nor the
12#       names of its contributors may be used to endorse or promote products
13#       derived from this software without specific prior written permission.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY
19# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26# begin:google_only
27# load("@rules_cc//cc:defs.bzl", "cc_proto_library")
28# end:google_only
29
30load(
31    "//bazel:upb_proto_library.bzl",
32    "upb_proto_library",
33    "upb_proto_reflection_library",
34)
35load(
36    ":build_defs.bzl",
37    "cc_optimizefor_proto_library",
38    "expand_suffixes",
39    "proto_library",
40    "tmpl_cc_binary",
41)
42
43licenses(["notice"])
44
45proto_library(
46    name = "descriptor_proto",
47    srcs = ["descriptor.proto"],
48)
49
50upb_proto_library(
51    name = "benchmark_descriptor_upb_proto",
52    deps = [":descriptor_proto"],
53)
54
55upb_proto_reflection_library(
56    name = "benchmark_descriptor_upb_proto_reflection",
57    deps = [":descriptor_proto"],
58)
59
60upb_proto_reflection_library(
61    name = "ads_upb_proto_reflection",
62    deps = ["@com_google_googleapis//:ads_proto"],
63)
64
65cc_proto_library(
66    name = "benchmark_descriptor_cc_proto",
67    deps = [":descriptor_proto"],
68)
69
70proto_library(
71    name = "benchmark_descriptor_sv_proto",
72    srcs = ["descriptor_sv.proto"],
73)
74
75cc_proto_library(
76    name = "benchmark_descriptor_sv_cc_proto",
77    deps = [":benchmark_descriptor_sv_proto"],
78)
79
80cc_test(
81    name = "benchmark",
82    testonly = 1,
83    srcs = ["benchmark.cc"],
84    deps = [
85        ":ads_upb_proto_reflection",
86        ":benchmark_descriptor_cc_proto",
87        ":benchmark_descriptor_sv_cc_proto",
88        ":benchmark_descriptor_upb_proto",
89        ":benchmark_descriptor_upb_proto_reflection",
90        "//:base",
91        "//:descriptor_upb_proto",
92        "//:mem",
93        "//:reflection",
94        "@com_github_google_benchmark//:benchmark_main",
95        "@com_google_absl//absl/container:flat_hash_set",
96        "@com_google_protobuf//:protobuf",
97    ],
98)
99
100# Size benchmarks.
101
102SIZE_BENCHMARKS = {
103    "empty": "Empty",
104    "descriptor": "FileDescriptorSet",
105    "100_msgs": "Message100",
106    "200_msgs": "Message200",
107    "100_fields": "Message",
108    "200_fields": "Message",
109}
110
111py_binary(
112    name = "gen_synthetic_protos",
113    srcs = ["gen_synthetic_protos.py"],
114    python_version = "PY3",
115)
116
117py_binary(
118    name = "gen_upb_binary_c",
119    srcs = ["gen_upb_binary_c.py"],
120    python_version = "PY3",
121)
122
123py_binary(
124    name = "gen_protobuf_binary_cc",
125    srcs = ["gen_protobuf_binary_cc.py"],
126    python_version = "PY3",
127)
128
129genrule(
130    name = "do_gen_synthetic_protos",
131    outs = [
132        "100_msgs.proto",
133        "200_msgs.proto",
134        "100_fields.proto",
135        "200_fields.proto",
136    ],
137    cmd = "$(execpath :gen_synthetic_protos) $(RULEDIR)",
138    tools = [":gen_synthetic_protos"],
139)
140
141proto_library(
142    name = "100_msgs_proto",
143    srcs = ["100_msgs.proto"],
144)
145
146proto_library(
147    name = "200_msgs_proto",
148    srcs = ["200_msgs.proto"],
149)
150
151proto_library(
152    name = "100_fields_proto",
153    srcs = ["100_fields.proto"],
154)
155
156proto_library(
157    name = "200_fields_proto",
158    srcs = ["200_fields.proto"],
159)
160
161proto_library(
162    name = "empty_proto",
163    srcs = ["empty.proto"],
164)
165
166[(
167    upb_proto_library(
168        name = k + "_upb_proto",
169        deps = [":" + k + "_proto"],
170    ),
171    cc_proto_library(
172        name = k + "_cc_proto",
173        deps = [":" + k + "_proto"],
174    ),
175    tmpl_cc_binary(
176        name = k + "_upb_binary",
177        testonly = 1,
178        args = [
179            package_name() + "/" + k + ".upb.h",
180            "upb_benchmark_" + v,
181        ],
182        gen = ":gen_upb_binary_c",
183        deps = [
184            ":" + k + "_upb_proto",
185        ],
186    ),
187    tmpl_cc_binary(
188        name = k + "_protobuf_binary",
189        testonly = 1,
190        args = [
191            package_name() + "/" + k + ".pb.h",
192            "upb_benchmark::" + v,
193        ],
194        gen = ":gen_protobuf_binary_cc",
195        deps = [
196            ":" + k + "_cc_proto",
197        ],
198    ),
199    cc_optimizefor_proto_library(
200        name = k + "_cc_lite_proto",
201        srcs = [k + ".proto"],
202        outs = [k + "_lite.proto"],
203        optimize_for = "LITE_RUNTIME",
204    ),
205    tmpl_cc_binary(
206        name = k + "_lite_protobuf_binary",
207        testonly = 1,
208        args = [
209            package_name() + "/" + k + "_lite.pb.h",
210            "upb_benchmark::" + v,
211        ],
212        gen = ":gen_protobuf_binary_cc",
213        deps = [
214            ":" + k + "_cc_lite_proto",
215        ],
216    ),
217    cc_optimizefor_proto_library(
218        name = k + "_cc_codesize_proto",
219        srcs = [k + ".proto"],
220        outs = [k + "_codesize.proto"],
221        optimize_for = "CODE_SIZE",
222    ),
223    tmpl_cc_binary(
224        name = k + "_codesize_protobuf_binary",
225        testonly = 1,
226        args = [
227            package_name() + "/" + k + "_codesize.pb.h",
228            "upb_benchmark::" + v,
229        ],
230        gen = ":gen_protobuf_binary_cc",
231        deps = [
232            ":" + k + "_cc_codesize_proto",
233        ],
234    ),
235) for k, v in SIZE_BENCHMARKS.items()]
236
237genrule(
238    name = "size_data",
239    testonly = 1,
240    srcs = expand_suffixes(
241        SIZE_BENCHMARKS.keys(),
242        suffixes = [
243            "_upb_binary",
244            "_protobuf_binary",
245            "_lite_protobuf_binary",
246            "_codesize_protobuf_binary",
247        ],
248    ),
249    outs = ["size_data.txt"],
250    # We want --format=GNU which counts rodata with data, not text.
251    cmd = "size $$($$OSTYPE == 'linux-gnu' ? '--format=GNU -d' : '') $(SRCS) > $@",
252    # "size" sometimes isn't available remotely.
253    local = 1,
254    tags = ["no-remote-exec"],
255)
256