blob: ae4b1995b29c16a3d8b04a056a16519af0235e36 [file] [log] [blame]
Joshua Haberman823eb092021-04-05 12:26:41 -07001# Copyright (c) 2009-2021, Google LLC
Joshua Habermane59d2c82021-04-05 10:47:53 -07002# 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
Joshua Habermane3f41de2020-10-17 13:15:58 -070026load(
27 "//bazel:upb_proto_library.bzl",
28 "upb_proto_library",
29 "upb_proto_reflection_library",
30)
Joshua Haberman4bd34da2020-11-04 20:16:47 -080031load(
32 ":build_defs.bzl",
33 "tmpl_cc_binary",
Joshua Haberman9c87f112020-11-12 17:44:02 -080034 "cc_optimizefor_proto_library",
Joshua Haberman555fbbc2020-11-10 20:20:06 -080035 "expand_suffixes",
Joshua Habermand2446fd2020-11-11 18:02:42 -080036 "proto_library",
Joshua Haberman4bd34da2020-11-04 20:16:47 -080037)
Joshua Habermane3f41de2020-10-17 13:15:58 -070038
Joshua Haberman2c166492020-10-17 15:49:11 -070039licenses(["notice"])
Joshua Habermanb7dc7742020-10-17 15:17:36 -070040
Joshua Habermane3f41de2020-10-17 13:15:58 -070041proto_library(
Joshua Haberman555fbbc2020-11-10 20:20:06 -080042 name = "descriptor_proto",
Joshua Habermane3f41de2020-10-17 13:15:58 -070043 srcs = ["descriptor.proto"],
44)
45
46upb_proto_library(
47 name = "benchmark_descriptor_upb_proto",
Joshua Haberman555fbbc2020-11-10 20:20:06 -080048 deps = [":descriptor_proto"],
Joshua Habermane3f41de2020-10-17 13:15:58 -070049)
50
51upb_proto_reflection_library(
52 name = "benchmark_descriptor_upb_proto_reflection",
Joshua Haberman555fbbc2020-11-10 20:20:06 -080053 deps = [":descriptor_proto"],
Joshua Habermane3f41de2020-10-17 13:15:58 -070054)
55
Joshua Habermanc3b56372020-10-31 13:12:18 -070056upb_proto_reflection_library(
57 name = "ads_upb_proto_reflection",
58 deps = ["@com_google_googleapis//:ads_proto"],
59)
60
Joshua Habermane3f41de2020-10-17 13:15:58 -070061cc_proto_library(
62 name = "benchmark_descriptor_cc_proto",
Joshua Haberman555fbbc2020-11-10 20:20:06 -080063 deps = [":descriptor_proto"],
Joshua Habermane3f41de2020-10-17 13:15:58 -070064)
65
66proto_library(
67 name = "benchmark_descriptor_sv_proto",
68 srcs = ["descriptor_sv.proto"],
69)
70
71cc_proto_library(
72 name = "benchmark_descriptor_sv_cc_proto",
73 deps = [":benchmark_descriptor_sv_proto"],
74)
75
Joshua Habermanc9446382022-03-05 10:19:56 -080076cc_test(
Joshua Habermane3f41de2020-10-17 13:15:58 -070077 name = "benchmark",
78 testonly = 1,
79 srcs = ["benchmark.cc"],
80 deps = [
Joshua Haberman1eb7bd32020-11-05 10:39:38 -080081 ":ads_upb_proto_reflection",
Joshua Habermane3f41de2020-10-17 13:15:58 -070082 ":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",
Joshua Haberman1eb7bd32020-11-05 10:39:38 -080089 "@com_google_absl//absl/container:flat_hash_set",
Joshua Habermane3f41de2020-10-17 13:15:58 -070090 ],
91)
Joshua Haberman8a3470c2020-10-18 10:35:39 -070092
93# Size benchmarks.
94
Joshua Haberman4bd34da2020-11-04 20:16:47 -080095SIZE_BENCHMARKS = {
96 "empty": "Empty",
97 "descriptor": "FileDescriptorSet",
Joshua Haberman555fbbc2020-11-10 20:20:06 -080098 "100_msgs": "Message100",
99 "200_msgs": "Message200",
100 "100_fields": "Message",
101 "200_fields": "Message",
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800102}
103
104py_binary(
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800105 name = "gen_synthetic_protos",
106 srcs = ["gen_synthetic_protos.py"],
Joshua Habermanda48e012020-11-11 19:00:52 -0800107 python_version = "PY3",
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800108)
109
110py_binary(
111 name = "gen_upb_binary_c",
112 srcs = ["gen_upb_binary_c.py"],
Joshua Haberman8b7dabe2020-11-10 20:44:27 -0800113 python_version = "PY3",
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800114)
115
116py_binary(
117 name = "gen_protobuf_binary_cc",
118 srcs = ["gen_protobuf_binary_cc.py"],
Joshua Haberman8b7dabe2020-11-10 20:44:27 -0800119 python_version = "PY3",
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800120)
121
122genrule(
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800123 name = "do_gen_synthetic_protos",
124 tools = [":gen_synthetic_protos"],
125 outs = [
126 "100_msgs.proto",
127 "200_msgs.proto",
128 "100_fields.proto",
129 "200_fields.proto",
130 ],
Joshua Habermanda48e012020-11-11 19:00:52 -0800131 cmd = "$(execpath :gen_synthetic_protos) $(RULEDIR)",
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800132)
133
134proto_library(
135 name = "100_msgs_proto",
136 srcs = ["100_msgs.proto"],
137)
138
139proto_library(
140 name = "200_msgs_proto",
141 srcs = ["200_msgs.proto"],
142)
143
144proto_library(
145 name = "100_fields_proto",
146 srcs = ["100_fields.proto"],
147)
148
149proto_library(
150 name = "200_fields_proto",
151 srcs = ["200_fields.proto"],
152)
153
154proto_library(
155 name = "empty_proto",
156 srcs = ["empty.proto"],
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800157)
158
159[(
Joshua Haberman8a3470c2020-10-18 10:35:39 -0700160upb_proto_library(
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800161 name = k + "_upb_proto",
162 deps = [":" + k + "_proto"],
163),
Joshua Haberman8a3470c2020-10-18 10:35:39 -0700164cc_proto_library(
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800165 name = k + "_cc_proto",
166 deps = [":" + k + "_proto"],
167),
168tmpl_cc_binary(
169 name = k + "_upb_binary",
Joshua Haberman8a3470c2020-10-18 10:35:39 -0700170 testonly = 1,
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800171 gen = ":gen_upb_binary_c",
172 args = [
Joshua Habermanda48e012020-11-11 19:00:52 -0800173 package_name() + "/" + k + ".upb.h",
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800174 "upb_benchmark_" + v,
175 ],
Joshua Haberman8a3470c2020-10-18 10:35:39 -0700176 deps = [
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800177 ":" + k + "_upb_proto",
Joshua Haberman8a3470c2020-10-18 10:35:39 -0700178 ],
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800179),
180tmpl_cc_binary(
181 name = k + "_protobuf_binary",
Joshua Haberman8a3470c2020-10-18 10:35:39 -0700182 testonly = 1,
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800183 gen = ":gen_protobuf_binary_cc",
184 args = [
Joshua Habermanda48e012020-11-11 19:00:52 -0800185 package_name() + "/" + k + ".pb.h",
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800186 "upb_benchmark::" + v,
187 ],
Joshua Haberman8a3470c2020-10-18 10:35:39 -0700188 deps = [
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800189 ":" + k + "_cc_proto",
Joshua Haberman8a3470c2020-10-18 10:35:39 -0700190 ],
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800191),
Joshua Haberman9c87f112020-11-12 17:44:02 -0800192cc_optimizefor_proto_library(
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800193 srcs = [k + ".proto"],
194 outs = [k + "_lite.proto"],
195 name = k + "_cc_lite_proto",
Joshua Haberman9c87f112020-11-12 17:44:02 -0800196 optimize_for = "LITE_RUNTIME",
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800197),
198tmpl_cc_binary(
199 name = k + "_lite_protobuf_binary",
200 testonly = 1,
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800201 gen = ":gen_protobuf_binary_cc",
202 args = [
Joshua Habermanda48e012020-11-11 19:00:52 -0800203 package_name() + "/" + k + "_lite.pb.h",
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800204 "upb_benchmark::" + v,
205 ],
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800206 deps = [
207 ":" + k + "_cc_lite_proto",
208 ],
Joshua Haberman9c87f112020-11-12 17:44:02 -0800209),
210cc_optimizefor_proto_library(
211 srcs = [k + ".proto"],
212 outs = [k + "_codesize.proto"],
213 name = k + "_cc_codesize_proto",
214 optimize_for = "CODE_SIZE",
215),
216tmpl_cc_binary(
217 name = k + "_codesize_protobuf_binary",
218 testonly = 1,
219 gen = ":gen_protobuf_binary_cc",
220 args = [
221 package_name() + "/" + k + "_codesize.pb.h",
222 "upb_benchmark::" + v,
223 ],
224 deps = [
225 ":" + k + "_cc_codesize_proto",
226 ],
227)
228) for k, v in SIZE_BENCHMARKS.items()]
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800229
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800230genrule(
231 testonly = 1,
232 name = "size_data",
233 srcs = expand_suffixes(
234 SIZE_BENCHMARKS.keys(),
Joshua Haberman9c87f112020-11-12 17:44:02 -0800235 suffixes = ["_upb_binary", "_protobuf_binary", "_lite_protobuf_binary", "_codesize_protobuf_binary"],
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800236 ),
237 outs = ["size_data.txt"],
Joshua Haberman86f671d2020-11-11 17:13:40 -0800238 # We want --format=GNU which counts rodata with data, not text.
239 cmd = "size $$($$OSTYPE == 'linux-gnu' ? '--format=GNU -d' : '') $(SRCS) > $@",
Joshua Haberman378a27b2020-11-11 19:06:14 -0800240 # "size" sometimes isn't available remotely.
241 local = 1,
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800242)