Debian Codegraph @

third_party/upb/benchmarks/BUILD

raw
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("//tools/build_defs/proto/cpp:cc_proto_library.bzl", "cc_proto_library")
28 # end:google_only
29
30 load(
31 "//bazel:upb_proto_library.bzl",
32 "upb_proto_library",
33 "upb_proto_reflection_library",
34 )
35 load(
36 ":build_defs.bzl",
37 "cc_optimizefor_proto_library",
38 "expand_suffixes",
39 "proto_library",
40 "tmpl_cc_binary",
41 )
42
43 licenses(["notice"])
44
45 proto_library(
46 name = "descriptor_proto",
47 srcs = ["descriptor.proto"],
48 )
49
50 upb_proto_library(
51 name = "benchmark_descriptor_upb_proto",
52 deps = [":descriptor_proto"],
53 )
54
55 upb_proto_reflection_library(
56 name = "benchmark_descriptor_upb_proto_reflection",
57 deps = [":descriptor_proto"],
58 )
59
60 upb_proto_reflection_library(
61 name = "ads_upb_proto_reflection",
62 deps = ["@com_google_googleapis//:ads_proto"],
63 )
64
65 cc_proto_library(
66 name = "benchmark_descriptor_cc_proto",
67 deps = [":descriptor_proto"],
68 )
69
70 proto_library(
71 name = "benchmark_descriptor_sv_proto",
72 srcs = ["descriptor_sv.proto"],
73 )
74
75 cc_proto_library(
76 name = "benchmark_descriptor_sv_cc_proto",
77 deps = [":benchmark_descriptor_sv_proto"],
78 )
79
80 cc_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 "//:descriptor_upb_proto",
91 "//:reflection",
92 "@com_github_google_benchmark//:benchmark_main",
93 "@com_google_absl//absl/container:flat_hash_set",
94 "@com_google_protobuf//:protobuf",
95 ],
96 )
97
98 # Size benchmarks.
99
100 SIZE_BENCHMARKS = {
101 "empty": "Empty",
102 "descriptor": "FileDescriptorSet",
103 "100_msgs": "Message100",
104 "200_msgs": "Message200",
105 "100_fields": "Message",
106 "200_fields": "Message",
107 }
108
109 py_binary(
110 name = "gen_synthetic_protos",
111 srcs = ["gen_synthetic_protos.py"],
112 python_version = "PY3",
113 )
114
115 py_binary(
116 name = "gen_upb_binary_c",
117 srcs = ["gen_upb_binary_c.py"],
118 python_version = "PY3",
119 )
120
121 py_binary(
122 name = "gen_protobuf_binary_cc",
123 srcs = ["gen_protobuf_binary_cc.py"],
124 python_version = "PY3",
125 )
126
127 genrule(
128 name = "do_gen_synthetic_protos",
129 outs = [
130 "100_msgs.proto",
131 "200_msgs.proto",
132 "100_fields.proto",
133 "200_fields.proto",
134 ],
135 cmd = "$(execpath :gen_synthetic_protos) $(RULEDIR)",
136 tools = [":gen_synthetic_protos"],
137 )
138
139 proto_library(
140 name = "100_msgs_proto",
141 srcs = ["100_msgs.proto"],
142 )
143
144 proto_library(
145 name = "200_msgs_proto",
146 srcs = ["200_msgs.proto"],
147 )
148
149 proto_library(
150 name = "100_fields_proto",
151 srcs = ["100_fields.proto"],
152 )
153
154 proto_library(
155 name = "200_fields_proto",
156 srcs = ["200_fields.proto"],
157 )
158
159 proto_library(
160 name = "empty_proto",
161 srcs = ["empty.proto"],
162 )
163
164 [(
165 upb_proto_library(
166 name = k + "_upb_proto",
167 deps = [":" + k + "_proto"],
168 ),
169 cc_proto_library(
170 name = k + "_cc_proto",
171 deps = [":" + k + "_proto"],
172 ),
173 tmpl_cc_binary(
174 name = k + "_upb_binary",
175 testonly = 1,
176 args = [
177 package_name() + "/" + k + ".upb.h",
178 "upb_benchmark_" + v,
179 ],
180 gen = ":gen_upb_binary_c",
181 deps = [
182 ":" + k + "_upb_proto",
183 ],
184 ),
185 tmpl_cc_binary(
186 name = k + "_protobuf_binary",
187 testonly = 1,
188 args = [
189 package_name() + "/" + k + ".pb.h",
190 "upb_benchmark::" + v,
191 ],
192 gen = ":gen_protobuf_binary_cc",
193 deps = [
194 ":" + k + "_cc_proto",
195 ],
196 ),
197 cc_optimizefor_proto_library(
198 name = k + "_cc_lite_proto",
199 srcs = [k + ".proto"],
200 outs = [k + "_lite.proto"],
201 optimize_for = "LITE_RUNTIME",
202 ),
203 tmpl_cc_binary(
204 name = k + "_lite_protobuf_binary",
205 testonly = 1,
206 args = [
207 package_name() + "/" + k + "_lite.pb.h",
208 "upb_benchmark::" + v,
209 ],
210 gen = ":gen_protobuf_binary_cc",
211 deps = [
212 ":" + k + "_cc_lite_proto",
213 ],
214 ),
215 cc_optimizefor_proto_library(
216 name = k + "_cc_codesize_proto",
217 srcs = [k + ".proto"],
218 outs = [k + "_codesize.proto"],
219 optimize_for = "CODE_SIZE",
220 ),
221 tmpl_cc_binary(
222 name = k + "_codesize_protobuf_binary",
223 testonly = 1,
224 args = [
225 package_name() + "/" + k + "_codesize.pb.h",
226 "upb_benchmark::" + v,
227 ],
228 gen = ":gen_protobuf_binary_cc",
229 deps = [
230 ":" + k + "_cc_codesize_proto",
231 ],
232 ),
233 ) for k, v in SIZE_BENCHMARKS.items()]
234
235 genrule(
236 name = "size_data",
237 testonly = 1,
238 srcs = expand_suffixes(
239 SIZE_BENCHMARKS.keys(),
240 suffixes = [
241 "_upb_binary",
242 "_protobuf_binary",
243 "_lite_protobuf_binary",
244 "_codesize_protobuf_binary",
245 ],
246 ),
247 outs = ["size_data.txt"],
248 # We want --format=GNU which counts rodata with data, not text.
249 cmd = "size $$($$OSTYPE == 'linux-gnu' ? '--format=GNU -d' : '') $(SRCS) > $@",
250 # "size" sometimes isn't available remotely.
251 local = 1,
252 )