blob: a7852c776d25eeb166cf12b33ce9cb8cc724f760 [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
Protobuf Teamb8edc712022-03-16 08:24:52 -070026# begin:google_only
27# load("//tools/build_defs/proto/cpp:cc_proto_library.bzl", "cc_proto_library")
28# end:google_only
29
Joshua Habermane3f41de2020-10-17 13:15:58 -070030load(
31 "//bazel:upb_proto_library.bzl",
32 "upb_proto_library",
33 "upb_proto_reflection_library",
34)
Joshua Haberman4bd34da2020-11-04 20:16:47 -080035load(
36 ":build_defs.bzl",
Joshua Haberman9c87f112020-11-12 17:44:02 -080037 "cc_optimizefor_proto_library",
Joshua Haberman555fbbc2020-11-10 20:20:06 -080038 "expand_suffixes",
Joshua Habermand2446fd2020-11-11 18:02:42 -080039 "proto_library",
Protobuf Teamb8edc712022-03-16 08:24:52 -070040 "tmpl_cc_binary",
Joshua Haberman4bd34da2020-11-04 20:16:47 -080041)
Joshua Habermane3f41de2020-10-17 13:15:58 -070042
Joshua Haberman2c166492020-10-17 15:49:11 -070043licenses(["notice"])
Joshua Habermanb7dc7742020-10-17 15:17:36 -070044
Joshua Habermane3f41de2020-10-17 13:15:58 -070045proto_library(
Joshua Haberman555fbbc2020-11-10 20:20:06 -080046 name = "descriptor_proto",
Joshua Habermane3f41de2020-10-17 13:15:58 -070047 srcs = ["descriptor.proto"],
48)
49
50upb_proto_library(
51 name = "benchmark_descriptor_upb_proto",
Joshua Haberman555fbbc2020-11-10 20:20:06 -080052 deps = [":descriptor_proto"],
Joshua Habermane3f41de2020-10-17 13:15:58 -070053)
54
55upb_proto_reflection_library(
56 name = "benchmark_descriptor_upb_proto_reflection",
Joshua Haberman555fbbc2020-11-10 20:20:06 -080057 deps = [":descriptor_proto"],
Joshua Habermane3f41de2020-10-17 13:15:58 -070058)
59
Joshua Habermanc3b56372020-10-31 13:12:18 -070060upb_proto_reflection_library(
61 name = "ads_upb_proto_reflection",
62 deps = ["@com_google_googleapis//:ads_proto"],
63)
64
Joshua Habermane3f41de2020-10-17 13:15:58 -070065cc_proto_library(
66 name = "benchmark_descriptor_cc_proto",
Joshua Haberman555fbbc2020-11-10 20:20:06 -080067 deps = [":descriptor_proto"],
Joshua Habermane3f41de2020-10-17 13:15:58 -070068)
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
Joshua Habermanc9446382022-03-05 10:19:56 -080080cc_test(
Joshua Habermane3f41de2020-10-17 13:15:58 -070081 name = "benchmark",
82 testonly = 1,
83 srcs = ["benchmark.cc"],
84 deps = [
Joshua Haberman1eb7bd32020-11-05 10:39:38 -080085 ":ads_upb_proto_reflection",
Joshua Habermane3f41de2020-10-17 13:15:58 -070086 ":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",
Joshua Haberman1eb7bd32020-11-05 10:39:38 -080093 "@com_google_absl//absl/container:flat_hash_set",
Protobuf Teamb8edc712022-03-16 08:24:52 -070094 "@com_google_protobuf//:protobuf",
Joshua Habermane3f41de2020-10-17 13:15:58 -070095 ],
96)
Joshua Haberman8a3470c2020-10-18 10:35:39 -070097
98# Size benchmarks.
99
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800100SIZE_BENCHMARKS = {
101 "empty": "Empty",
102 "descriptor": "FileDescriptorSet",
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800103 "100_msgs": "Message100",
104 "200_msgs": "Message200",
105 "100_fields": "Message",
106 "200_fields": "Message",
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800107}
108
109py_binary(
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800110 name = "gen_synthetic_protos",
111 srcs = ["gen_synthetic_protos.py"],
Joshua Habermanda48e012020-11-11 19:00:52 -0800112 python_version = "PY3",
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800113)
114
115py_binary(
116 name = "gen_upb_binary_c",
117 srcs = ["gen_upb_binary_c.py"],
Joshua Haberman8b7dabe2020-11-10 20:44:27 -0800118 python_version = "PY3",
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800119)
120
121py_binary(
122 name = "gen_protobuf_binary_cc",
123 srcs = ["gen_protobuf_binary_cc.py"],
Joshua Haberman8b7dabe2020-11-10 20:44:27 -0800124 python_version = "PY3",
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800125)
126
127genrule(
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800128 name = "do_gen_synthetic_protos",
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800129 outs = [
130 "100_msgs.proto",
131 "200_msgs.proto",
132 "100_fields.proto",
133 "200_fields.proto",
134 ],
Joshua Habermanda48e012020-11-11 19:00:52 -0800135 cmd = "$(execpath :gen_synthetic_protos) $(RULEDIR)",
Protobuf Teamb8edc712022-03-16 08:24:52 -0700136 tools = [":gen_synthetic_protos"],
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800137)
138
139proto_library(
140 name = "100_msgs_proto",
141 srcs = ["100_msgs.proto"],
142)
143
144proto_library(
145 name = "200_msgs_proto",
146 srcs = ["200_msgs.proto"],
147)
148
149proto_library(
150 name = "100_fields_proto",
151 srcs = ["100_fields.proto"],
152)
153
154proto_library(
155 name = "200_fields_proto",
156 srcs = ["200_fields.proto"],
157)
158
159proto_library(
160 name = "empty_proto",
161 srcs = ["empty.proto"],
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800162)
163
164[(
Protobuf Teamb8edc712022-03-16 08:24:52 -0700165 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 ),
Joshua Haberman9c87f112020-11-12 17:44:02 -0800233) for k, v in SIZE_BENCHMARKS.items()]
Joshua Haberman4bd34da2020-11-04 20:16:47 -0800234
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800235genrule(
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800236 name = "size_data",
Protobuf Teamb8edc712022-03-16 08:24:52 -0700237 testonly = 1,
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800238 srcs = expand_suffixes(
239 SIZE_BENCHMARKS.keys(),
Protobuf Teamb8edc712022-03-16 08:24:52 -0700240 suffixes = [
241 "_upb_binary",
242 "_protobuf_binary",
243 "_lite_protobuf_binary",
244 "_codesize_protobuf_binary",
245 ],
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800246 ),
247 outs = ["size_data.txt"],
Joshua Haberman86f671d2020-11-11 17:13:40 -0800248 # We want --format=GNU which counts rodata with data, not text.
249 cmd = "size $$($$OSTYPE == 'linux-gnu' ? '--format=GNU -d' : '') $(SRCS) > $@",
Joshua Haberman378a27b2020-11-11 19:06:14 -0800250 # "size" sometimes isn't available remotely.
251 local = 1,
Joshua Haberman555fbbc2020-11-10 20:20:06 -0800252)