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 |
| 27 | # load("//tools/build_defs/proto/cpp:cc_proto_library.bzl", "cc_proto_library") |
| 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 | |
Joshua Haberman | 2c16649 | 2020-10-17 15:49:11 -0700 | [diff] [blame] | 43 | licenses(["notice"]) |
Joshua Haberman | b7dc774 | 2020-10-17 15:17:36 -0700 | [diff] [blame] | 44 | |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 45 | proto_library( |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 46 | name = "descriptor_proto", |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 47 | srcs = ["descriptor.proto"], |
| 48 | ) |
| 49 | |
| 50 | upb_proto_library( |
| 51 | name = "benchmark_descriptor_upb_proto", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 52 | deps = [":descriptor_proto"], |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 53 | ) |
| 54 | |
| 55 | upb_proto_reflection_library( |
| 56 | name = "benchmark_descriptor_upb_proto_reflection", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 57 | deps = [":descriptor_proto"], |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 58 | ) |
| 59 | |
Joshua Haberman | c3b5637 | 2020-10-31 13:12:18 -0700 | [diff] [blame] | 60 | upb_proto_reflection_library( |
| 61 | name = "ads_upb_proto_reflection", |
| 62 | deps = ["@com_google_googleapis//:ads_proto"], |
| 63 | ) |
| 64 | |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 65 | cc_proto_library( |
| 66 | name = "benchmark_descriptor_cc_proto", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 67 | deps = [":descriptor_proto"], |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 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 | |
Joshua Haberman | c944638 | 2022-03-05 10:19:56 -0800 | [diff] [blame] | 80 | cc_test( |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 81 | name = "benchmark", |
| 82 | testonly = 1, |
| 83 | srcs = ["benchmark.cc"], |
| 84 | deps = [ |
Joshua Haberman | 1eb7bd3 | 2020-11-05 10:39:38 -0800 | [diff] [blame] | 85 | ":ads_upb_proto_reflection", |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 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", |
Joshua Haberman | 1eb7bd3 | 2020-11-05 10:39:38 -0800 | [diff] [blame] | 93 | "@com_google_absl//absl/container:flat_hash_set", |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame^] | 94 | "@com_google_protobuf//:protobuf", |
Joshua Haberman | e3f41de | 2020-10-17 13:15:58 -0700 | [diff] [blame] | 95 | ], |
| 96 | ) |
Joshua Haberman | 8a3470c | 2020-10-18 10:35:39 -0700 | [diff] [blame] | 97 | |
| 98 | # Size benchmarks. |
| 99 | |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 100 | SIZE_BENCHMARKS = { |
| 101 | "empty": "Empty", |
| 102 | "descriptor": "FileDescriptorSet", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 103 | "100_msgs": "Message100", |
| 104 | "200_msgs": "Message200", |
| 105 | "100_fields": "Message", |
| 106 | "200_fields": "Message", |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | py_binary( |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 110 | name = "gen_synthetic_protos", |
| 111 | srcs = ["gen_synthetic_protos.py"], |
Joshua Haberman | da48e01 | 2020-11-11 19:00:52 -0800 | [diff] [blame] | 112 | python_version = "PY3", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 113 | ) |
| 114 | |
| 115 | py_binary( |
| 116 | name = "gen_upb_binary_c", |
| 117 | srcs = ["gen_upb_binary_c.py"], |
Joshua Haberman | 8b7dabe | 2020-11-10 20:44:27 -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_protobuf_binary_cc", |
| 123 | srcs = ["gen_protobuf_binary_cc.py"], |
Joshua Haberman | 8b7dabe | 2020-11-10 20:44:27 -0800 | [diff] [blame] | 124 | python_version = "PY3", |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 125 | ) |
| 126 | |
| 127 | genrule( |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 128 | name = "do_gen_synthetic_protos", |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 129 | outs = [ |
| 130 | "100_msgs.proto", |
| 131 | "200_msgs.proto", |
| 132 | "100_fields.proto", |
| 133 | "200_fields.proto", |
| 134 | ], |
Joshua Haberman | da48e01 | 2020-11-11 19:00:52 -0800 | [diff] [blame] | 135 | cmd = "$(execpath :gen_synthetic_protos) $(RULEDIR)", |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame^] | 136 | tools = [":gen_synthetic_protos"], |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 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"], |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 162 | ) |
| 163 | |
| 164 | [( |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame^] | 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 | ), |
Joshua Haberman | 9c87f11 | 2020-11-12 17:44:02 -0800 | [diff] [blame] | 233 | ) for k, v in SIZE_BENCHMARKS.items()] |
Joshua Haberman | 4bd34da | 2020-11-04 20:16:47 -0800 | [diff] [blame] | 234 | |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 235 | genrule( |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 236 | name = "size_data", |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame^] | 237 | testonly = 1, |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 238 | srcs = expand_suffixes( |
| 239 | SIZE_BENCHMARKS.keys(), |
Protobuf Team | b8edc71 | 2022-03-16 08:24:52 -0700 | [diff] [blame^] | 240 | suffixes = [ |
| 241 | "_upb_binary", |
| 242 | "_protobuf_binary", |
| 243 | "_lite_protobuf_binary", |
| 244 | "_codesize_protobuf_binary", |
| 245 | ], |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 246 | ), |
| 247 | outs = ["size_data.txt"], |
Joshua Haberman | 86f671d | 2020-11-11 17:13:40 -0800 | [diff] [blame] | 248 | # We want --format=GNU which counts rodata with data, not text. |
| 249 | cmd = "size $$($$OSTYPE == 'linux-gnu' ? '--format=GNU -d' : '') $(SRCS) > $@", |
Joshua Haberman | 378a27b | 2020-11-11 19:06:14 -0800 | [diff] [blame] | 250 | # "size" sometimes isn't available remotely. |
| 251 | local = 1, |
Joshua Haberman | 555fbbc | 2020-11-10 20:20:06 -0800 | [diff] [blame] | 252 | ) |