BUILD 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. load(
  26. "//bazel:upb_proto_library.bzl",
  27. "upb_proto_library",
  28. "upb_proto_reflection_library",
  29. )
  30. load(
  31. ":build_defs.bzl",
  32. "tmpl_cc_binary",
  33. "cc_optimizefor_proto_library",
  34. "expand_suffixes",
  35. "proto_library",
  36. )
  37. licenses(["notice"])
  38. proto_library(
  39. name = "descriptor_proto",
  40. srcs = ["descriptor.proto"],
  41. )
  42. upb_proto_library(
  43. name = "benchmark_descriptor_upb_proto",
  44. deps = [":descriptor_proto"],
  45. )
  46. upb_proto_reflection_library(
  47. name = "benchmark_descriptor_upb_proto_reflection",
  48. deps = [":descriptor_proto"],
  49. )
  50. upb_proto_reflection_library(
  51. name = "ads_upb_proto_reflection",
  52. deps = ["@com_google_googleapis//:ads_proto"],
  53. )
  54. cc_proto_library(
  55. name = "benchmark_descriptor_cc_proto",
  56. deps = [":descriptor_proto"],
  57. )
  58. proto_library(
  59. name = "benchmark_descriptor_sv_proto",
  60. srcs = ["descriptor_sv.proto"],
  61. )
  62. cc_proto_library(
  63. name = "benchmark_descriptor_sv_cc_proto",
  64. deps = [":benchmark_descriptor_sv_proto"],
  65. )
  66. cc_binary(
  67. name = "benchmark",
  68. testonly = 1,
  69. srcs = ["benchmark.cc"],
  70. deps = [
  71. ":ads_upb_proto_reflection",
  72. ":benchmark_descriptor_cc_proto",
  73. ":benchmark_descriptor_sv_cc_proto",
  74. ":benchmark_descriptor_upb_proto",
  75. ":benchmark_descriptor_upb_proto_reflection",
  76. "//:descriptor_upb_proto",
  77. "//:reflection",
  78. "@com_github_google_benchmark//:benchmark_main",
  79. "@com_google_absl//absl/container:flat_hash_set",
  80. ],
  81. )
  82. # Size benchmarks.
  83. SIZE_BENCHMARKS = {
  84. "empty": "Empty",
  85. "descriptor": "FileDescriptorSet",
  86. "100_msgs": "Message100",
  87. "200_msgs": "Message200",
  88. "100_fields": "Message",
  89. "200_fields": "Message",
  90. }
  91. py_binary(
  92. name = "gen_synthetic_protos",
  93. srcs = ["gen_synthetic_protos.py"],
  94. python_version = "PY3",
  95. )
  96. py_binary(
  97. name = "gen_upb_binary_c",
  98. srcs = ["gen_upb_binary_c.py"],
  99. python_version = "PY3",
  100. )
  101. py_binary(
  102. name = "gen_protobuf_binary_cc",
  103. srcs = ["gen_protobuf_binary_cc.py"],
  104. python_version = "PY3",
  105. )
  106. genrule(
  107. name = "do_gen_synthetic_protos",
  108. tools = [":gen_synthetic_protos"],
  109. outs = [
  110. "100_msgs.proto",
  111. "200_msgs.proto",
  112. "100_fields.proto",
  113. "200_fields.proto",
  114. ],
  115. cmd = "$(execpath :gen_synthetic_protos) $(RULEDIR)",
  116. )
  117. proto_library(
  118. name = "100_msgs_proto",
  119. srcs = ["100_msgs.proto"],
  120. )
  121. proto_library(
  122. name = "200_msgs_proto",
  123. srcs = ["200_msgs.proto"],
  124. )
  125. proto_library(
  126. name = "100_fields_proto",
  127. srcs = ["100_fields.proto"],
  128. )
  129. proto_library(
  130. name = "200_fields_proto",
  131. srcs = ["200_fields.proto"],
  132. )
  133. proto_library(
  134. name = "empty_proto",
  135. srcs = ["empty.proto"],
  136. )
  137. [(
  138. upb_proto_library(
  139. name = k + "_upb_proto",
  140. deps = [":" + k + "_proto"],
  141. ),
  142. cc_proto_library(
  143. name = k + "_cc_proto",
  144. deps = [":" + k + "_proto"],
  145. ),
  146. tmpl_cc_binary(
  147. name = k + "_upb_binary",
  148. testonly = 1,
  149. gen = ":gen_upb_binary_c",
  150. args = [
  151. package_name() + "/" + k + ".upb.h",
  152. "upb_benchmark_" + v,
  153. ],
  154. deps = [
  155. ":" + k + "_upb_proto",
  156. ],
  157. ),
  158. tmpl_cc_binary(
  159. name = k + "_protobuf_binary",
  160. testonly = 1,
  161. gen = ":gen_protobuf_binary_cc",
  162. args = [
  163. package_name() + "/" + k + ".pb.h",
  164. "upb_benchmark::" + v,
  165. ],
  166. deps = [
  167. ":" + k + "_cc_proto",
  168. ],
  169. ),
  170. cc_optimizefor_proto_library(
  171. srcs = [k + ".proto"],
  172. outs = [k + "_lite.proto"],
  173. name = k + "_cc_lite_proto",
  174. optimize_for = "LITE_RUNTIME",
  175. ),
  176. tmpl_cc_binary(
  177. name = k + "_lite_protobuf_binary",
  178. testonly = 1,
  179. gen = ":gen_protobuf_binary_cc",
  180. args = [
  181. package_name() + "/" + k + "_lite.pb.h",
  182. "upb_benchmark::" + v,
  183. ],
  184. deps = [
  185. ":" + k + "_cc_lite_proto",
  186. ],
  187. ),
  188. cc_optimizefor_proto_library(
  189. srcs = [k + ".proto"],
  190. outs = [k + "_codesize.proto"],
  191. name = k + "_cc_codesize_proto",
  192. optimize_for = "CODE_SIZE",
  193. ),
  194. tmpl_cc_binary(
  195. name = k + "_codesize_protobuf_binary",
  196. testonly = 1,
  197. gen = ":gen_protobuf_binary_cc",
  198. args = [
  199. package_name() + "/" + k + "_codesize.pb.h",
  200. "upb_benchmark::" + v,
  201. ],
  202. deps = [
  203. ":" + k + "_cc_codesize_proto",
  204. ],
  205. )
  206. ) for k, v in SIZE_BENCHMARKS.items()]
  207. genrule(
  208. testonly = 1,
  209. name = "size_data",
  210. srcs = expand_suffixes(
  211. SIZE_BENCHMARKS.keys(),
  212. suffixes = ["_upb_binary", "_protobuf_binary", "_lite_protobuf_binary", "_codesize_protobuf_binary"],
  213. ),
  214. outs = ["size_data.txt"],
  215. # We want --format=GNU which counts rodata with data, not text.
  216. cmd = "size $$($$OSTYPE == 'linux-gnu' ? '--format=GNU -d' : '') $(SRCS) > $@",
  217. # "size" sometimes isn't available remotely.
  218. local = 1,
  219. )