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