1 # Copyright (c) 2009-2021, Google LLC
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.
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.
27 "//bazel:upb_proto_library.bzl",
29 "upb_proto_reflection_library",
34 "cc_optimizefor_proto_library",
42 name = "descriptor_proto",
43 srcs = ["descriptor.proto"],
47 name = "benchmark_descriptor_upb_proto",
48 deps = [":descriptor_proto"],
51 upb_proto_reflection_library(
52 name = "benchmark_descriptor_upb_proto_reflection",
53 deps = [":descriptor_proto"],
56 upb_proto_reflection_library(
57 name = "ads_upb_proto_reflection",
58 deps = ["@com_google_googleapis//:ads_proto"],
62 name = "benchmark_descriptor_cc_proto",
63 deps = [":descriptor_proto"],
67 name = "benchmark_descriptor_sv_proto",
68 srcs = ["descriptor_sv.proto"],
72 name = "benchmark_descriptor_sv_cc_proto",
73 deps = [":benchmark_descriptor_sv_proto"],
79 srcs = ["benchmark.cc"],
81 ":ads_upb_proto_reflection",
82 ":benchmark_descriptor_cc_proto",
83 ":benchmark_descriptor_sv_cc_proto",
84 ":benchmark_descriptor_upb_proto",
85 ":benchmark_descriptor_upb_proto_reflection",
86 "//:descriptor_upb_proto",
88 "@com_github_google_benchmark//:benchmark_main",
89 "@com_google_absl//absl/container:flat_hash_set",
90 "@com_google_protobuf//:protobuf",
98 "descriptor": "FileDescriptorSet",
99 "100_msgs": "Message100",
100 "200_msgs": "Message200",
101 "100_fields": "Message",
102 "200_fields": "Message",
106 name = "gen_synthetic_protos",
107 srcs = ["gen_synthetic_protos.py"],
108 python_version = "PY3",
112 name = "gen_upb_binary_c",
113 srcs = ["gen_upb_binary_c.py"],
114 python_version = "PY3",
118 name = "gen_protobuf_binary_cc",
119 srcs = ["gen_protobuf_binary_cc.py"],
120 python_version = "PY3",
124 name = "do_gen_synthetic_protos",
125 tools = [":gen_synthetic_protos"],
132 cmd = "$(execpath :gen_synthetic_protos) $(RULEDIR)",
136 name = "100_msgs_proto",
137 srcs = ["100_msgs.proto"],
141 name = "200_msgs_proto",
142 srcs = ["200_msgs.proto"],
146 name = "100_fields_proto",
147 srcs = ["100_fields.proto"],
151 name = "200_fields_proto",
152 srcs = ["200_fields.proto"],
156 name = "empty_proto",
157 srcs = ["empty.proto"],
162 name = k + "_upb_proto",
163 deps = [":" + k + "_proto"],
166 name = k + "_cc_proto",
167 deps = [":" + k + "_proto"],
170 name = k + "_upb_binary",
172 gen = ":gen_upb_binary_c",
174 package_name() + "/" + k + ".upb.h",
175 "upb_benchmark_" + v,
178 ":" + k + "_upb_proto",
182 name = k + "_protobuf_binary",
184 gen = ":gen_protobuf_binary_cc",
186 package_name() + "/" + k + ".pb.h",
187 "upb_benchmark::" + v,
190 ":" + k + "_cc_proto",
193 cc_optimizefor_proto_library(
194 srcs = [k + ".proto"],
195 outs = [k + "_lite.proto"],
196 name = k + "_cc_lite_proto",
197 optimize_for = "LITE_RUNTIME",
200 name = k + "_lite_protobuf_binary",
202 gen = ":gen_protobuf_binary_cc",
204 package_name() + "/" + k + "_lite.pb.h",
205 "upb_benchmark::" + v,
208 ":" + k + "_cc_lite_proto",
211 cc_optimizefor_proto_library(
212 srcs = [k + ".proto"],
213 outs = [k + "_codesize.proto"],
214 name = k + "_cc_codesize_proto",
215 optimize_for = "CODE_SIZE",
218 name = k + "_codesize_protobuf_binary",
220 gen = ":gen_protobuf_binary_cc",
222 package_name() + "/" + k + "_codesize.pb.h",
223 "upb_benchmark::" + v,
226 ":" + k + "_cc_codesize_proto",
229 ) for k, v in SIZE_BENCHMARKS.items()]
234 srcs = expand_suffixes(
235 SIZE_BENCHMARKS.keys(),
236 suffixes = ["_upb_binary", "_protobuf_binary", "_lite_protobuf_binary", "_codesize_protobuf_binary"],
238 outs = ["size_data.txt"],
239 # We want --format=GNU which counts rodata with data, not text.
240 cmd = "size $$($$OSTYPE == 'linux-gnu' ? '--format=GNU -d' : '') $(SRCS) > $@",
241 # "size" sometimes isn't available remotely.