Joshua Haberman | 823eb09 | 2021-04-05 12:26:41 -0700 | [diff] [blame] | 1 | # Copyright (c) 2009-2021, Google LLC |
Joshua Haberman | e59d2c8 | 2021-04-05 10:47:53 -0700 | [diff] [blame] | 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 | |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame] | 26 | # begin:google_only |
Protobuf Team Bot | 306123e | 2022-11-04 09:25:30 -0700 | [diff] [blame] | 27 | # load("@rules_cc//cc:defs.bzl", "cc_proto_library") |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame] | 28 | # end:google_only |
| 29 | |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 30 | load( |
| 31 | "//bazel:upb_proto_library.bzl", |
| 32 | "upb_proto_library", |
| 33 | "upb_proto_reflection_library", |
| 34 | ) |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 35 | load( |
| 36 | ":build_defs.bzl", |
Joshua Haberman | 9c87f11 | 2020-11-12 17:44:02 -0800 | [diff] [blame] | 37 | "cc_optimizefor_proto_library", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 38 | "expand_suffixes", |
Joshua Haberman | d2446fd | 2020-11-11 18:02:42 -0800 | [diff] [blame] | 39 | "proto_library", |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame] | 40 | "tmpl_cc_binary", |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 41 | ) |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 42 | |
Protobuf Team Bot | 73ee41c | 2023-05-23 16:36:40 -0700 | [diff] [blame] | 43 | # begin:google_only |
| 44 | # package(default_applicable_licenses = ["//:license"]) |
| 45 | # end:google_only |
| 46 | |
Joshua Haberman | 2c16649 | 2020-10-17 15:49:11 -0700 | [diff] [blame] | 47 | licenses(["notice"]) |
Joshua Haberman | b7dc774 | 2020-10-17 15:17:36 -0700 | [diff] [blame] | 48 | |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 49 | proto_library( |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 50 | name = "descriptor_proto", |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 51 | srcs = ["descriptor.proto"], |
| 52 | ) |
| 53 | |
| 54 | upb_proto_library( |
| 55 | name = "benchmark_descriptor_upb_proto", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 56 | deps = [":descriptor_proto"], |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 57 | ) |
| 58 | |
| 59 | upb_proto_reflection_library( |
| 60 | name = "benchmark_descriptor_upb_proto_reflection", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 61 | deps = [":descriptor_proto"], |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 62 | ) |
| 63 | |
Joshua Haberman | c3b5637 | 2020-10-31 13:12:18 -0700 | [diff] [blame] | 64 | upb_proto_reflection_library( |
| 65 | name = "ads_upb_proto_reflection", |
| 66 | deps = ["@com_google_googleapis//:ads_proto"], |
| 67 | ) |
| 68 | |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 69 | cc_proto_library( |
| 70 | name = "benchmark_descriptor_cc_proto", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 71 | deps = [":descriptor_proto"], |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 72 | ) |
| 73 | |
| 74 | proto_library( |
| 75 | name = "benchmark_descriptor_sv_proto", |
| 76 | srcs = ["descriptor_sv.proto"], |
| 77 | ) |
| 78 | |
| 79 | cc_proto_library( |
| 80 | name = "benchmark_descriptor_sv_cc_proto", |
| 81 | deps = [":benchmark_descriptor_sv_proto"], |
| 82 | ) |
| 83 | |
Joshua Haberman | c944638 | 2022-03-05 10:19:56 -0800 | [diff] [blame] | 84 | cc_test( |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 85 | name = "benchmark", |
| 86 | testonly = 1, |
| 87 | srcs = ["benchmark.cc"], |
| 88 | deps = [ |
Joshua Haberman | 1eb7bd3 | 2020-11-05 10:39:38 -0800 | [diff] [blame] | 89 | ":ads_upb_proto_reflection", |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 90 | ":benchmark_descriptor_cc_proto", |
| 91 | ":benchmark_descriptor_sv_cc_proto", |
| 92 | ":benchmark_descriptor_upb_proto", |
| 93 | ":benchmark_descriptor_upb_proto_reflection", |
Joshua Haberman | d520014 | 2023-03-21 09:16:12 -0700 | [diff] [blame] | 94 | "//:base", |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 95 | "//:descriptor_upb_proto", |
Joshua Haberman | d520014 | 2023-03-21 09:16:12 -0700 | [diff] [blame] | 96 | "//:mem", |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 97 | "//:reflection", |
| 98 | "@com_github_google_benchmark//:benchmark_main", |
Joshua Haberman | 1eb7bd3 | 2020-11-05 10:39:38 -0800 | [diff] [blame] | 99 | "@com_google_absl//absl/container:flat_hash_set", |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame] | 100 | "@com_google_protobuf//:protobuf", |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 101 | ], |
| 102 | ) |
Joshua Haberman | 8a3470c | 2020-10-18 10:35:39 -0700 | [diff] [blame] | 103 | |
| 104 | # Size benchmarks. |
| 105 | |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 106 | SIZE_BENCHMARKS = { |
| 107 | "empty": "Empty", |
| 108 | "descriptor": "FileDescriptorSet", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 109 | "100_msgs": "Message100", |
| 110 | "200_msgs": "Message200", |
| 111 | "100_fields": "Message", |
| 112 | "200_fields": "Message", |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | py_binary( |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 116 | name = "gen_synthetic_protos", |
| 117 | srcs = ["gen_synthetic_protos.py"], |
Joshua Haberman | da48e01 | 2020-11-11 19:00:52 -0800 | [diff] [blame] | 118 | python_version = "PY3", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 119 | ) |
| 120 | |
| 121 | py_binary( |
| 122 | name = "gen_upb_binary_c", |
| 123 | srcs = ["gen_upb_binary_c.py"], |
Joshua Haberman | 8b7dabe | 2020-11-10 20:44:27 -0800 | [diff] [blame] | 124 | python_version = "PY3", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 125 | ) |
| 126 | |
| 127 | py_binary( |
| 128 | name = "gen_protobuf_binary_cc", |
| 129 | srcs = ["gen_protobuf_binary_cc.py"], |
Joshua Haberman | 8b7dabe | 2020-11-10 20:44:27 -0800 | [diff] [blame] | 130 | python_version = "PY3", |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 131 | ) |
| 132 | |
| 133 | genrule( |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 134 | name = "do_gen_synthetic_protos", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 135 | outs = [ |
| 136 | "100_msgs.proto", |
| 137 | "200_msgs.proto", |
| 138 | "100_fields.proto", |
| 139 | "200_fields.proto", |
| 140 | ], |
Joshua Haberman | da48e01 | 2020-11-11 19:00:52 -0800 | [diff] [blame] | 141 | cmd = "$(execpath :gen_synthetic_protos) $(RULEDIR)", |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame] | 142 | tools = [":gen_synthetic_protos"], |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 143 | ) |
| 144 | |
| 145 | proto_library( |
| 146 | name = "100_msgs_proto", |
| 147 | srcs = ["100_msgs.proto"], |
| 148 | ) |
| 149 | |
| 150 | proto_library( |
| 151 | name = "200_msgs_proto", |
| 152 | srcs = ["200_msgs.proto"], |
| 153 | ) |
| 154 | |
| 155 | proto_library( |
| 156 | name = "100_fields_proto", |
| 157 | srcs = ["100_fields.proto"], |
| 158 | ) |
| 159 | |
| 160 | proto_library( |
| 161 | name = "200_fields_proto", |
| 162 | srcs = ["200_fields.proto"], |
| 163 | ) |
| 164 | |
| 165 | proto_library( |
| 166 | name = "empty_proto", |
| 167 | srcs = ["empty.proto"], |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 168 | ) |
| 169 | |
| 170 | [( |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame] | 171 | upb_proto_library( |
| 172 | name = k + "_upb_proto", |
| 173 | deps = [":" + k + "_proto"], |
| 174 | ), |
| 175 | cc_proto_library( |
| 176 | name = k + "_cc_proto", |
| 177 | deps = [":" + k + "_proto"], |
| 178 | ), |
| 179 | tmpl_cc_binary( |
| 180 | name = k + "_upb_binary", |
| 181 | testonly = 1, |
| 182 | args = [ |
| 183 | package_name() + "/" + k + ".upb.h", |
| 184 | "upb_benchmark_" + v, |
| 185 | ], |
| 186 | gen = ":gen_upb_binary_c", |
| 187 | deps = [ |
| 188 | ":" + k + "_upb_proto", |
| 189 | ], |
| 190 | ), |
| 191 | tmpl_cc_binary( |
| 192 | name = k + "_protobuf_binary", |
| 193 | testonly = 1, |
| 194 | args = [ |
| 195 | package_name() + "/" + k + ".pb.h", |
| 196 | "upb_benchmark::" + v, |
| 197 | ], |
| 198 | gen = ":gen_protobuf_binary_cc", |
| 199 | deps = [ |
| 200 | ":" + k + "_cc_proto", |
| 201 | ], |
| 202 | ), |
| 203 | cc_optimizefor_proto_library( |
| 204 | name = k + "_cc_lite_proto", |
| 205 | srcs = [k + ".proto"], |
| 206 | outs = [k + "_lite.proto"], |
| 207 | optimize_for = "LITE_RUNTIME", |
| 208 | ), |
| 209 | tmpl_cc_binary( |
| 210 | name = k + "_lite_protobuf_binary", |
| 211 | testonly = 1, |
| 212 | args = [ |
| 213 | package_name() + "/" + k + "_lite.pb.h", |
| 214 | "upb_benchmark::" + v, |
| 215 | ], |
| 216 | gen = ":gen_protobuf_binary_cc", |
| 217 | deps = [ |
| 218 | ":" + k + "_cc_lite_proto", |
| 219 | ], |
| 220 | ), |
| 221 | cc_optimizefor_proto_library( |
| 222 | name = k + "_cc_codesize_proto", |
| 223 | srcs = [k + ".proto"], |
| 224 | outs = [k + "_codesize.proto"], |
| 225 | optimize_for = "CODE_SIZE", |
| 226 | ), |
| 227 | tmpl_cc_binary( |
| 228 | name = k + "_codesize_protobuf_binary", |
| 229 | testonly = 1, |
| 230 | args = [ |
| 231 | package_name() + "/" + k + "_codesize.pb.h", |
| 232 | "upb_benchmark::" + v, |
| 233 | ], |
| 234 | gen = ":gen_protobuf_binary_cc", |
| 235 | deps = [ |
| 236 | ":" + k + "_cc_codesize_proto", |
| 237 | ], |
| 238 | ), |
Joshua Haberman | 9c87f11 | 2020-11-12 17:44:02 -0800 | [diff] [blame] | 239 | ) for k, v in SIZE_BENCHMARKS.items()] |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 240 | |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 241 | genrule( |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 242 | name = "size_data", |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame] | 243 | testonly = 1, |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 244 | srcs = expand_suffixes( |
| 245 | SIZE_BENCHMARKS.keys(), |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame] | 246 | suffixes = [ |
| 247 | "_upb_binary", |
| 248 | "_protobuf_binary", |
| 249 | "_lite_protobuf_binary", |
| 250 | "_codesize_protobuf_binary", |
| 251 | ], |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 252 | ), |
| 253 | outs = ["size_data.txt"], |
Joshua Haberman | 86f671d | 2020-11-11 17:13:40 -0800 | [diff] [blame] | 254 | # We want --format=GNU which counts rodata with data, not text. |
| 255 | cmd = "size $$($$OSTYPE == 'linux-gnu' ? '--format=GNU -d' : '') $(SRCS) > $@", |
Joshua Haberman | 378a27b | 2020-11-11 19:06:14 -0800 | [diff] [blame] | 256 | # "size" sometimes isn't available remotely. |
| 257 | local = 1, |
Joshua Haberman | c2a0cbe | 2023-02-06 14:21:25 -0800 | [diff] [blame] | 258 | tags = ["no-remote-exec"], |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 259 | ) |