BUILD 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. # Bazel (https://bazel.build/) BUILD file for Protobuf.
  2. load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
  3. load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library")
  4. load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
  5. load("@rules_python//python:defs.bzl", "py_library")
  6. load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test")
  7. licenses(["notice"])
  8. exports_files(["LICENSE"])
  9. ################################################################################
  10. # build configuration
  11. ################################################################################
  12. ################################################################################
  13. # ZLIB configuration
  14. ################################################################################
  15. ZLIB_DEPS = ["@zlib//:zlib"]
  16. ################################################################################
  17. # Protobuf Runtime Library
  18. ################################################################################
  19. MSVC_COPTS = [
  20. "/DHAVE_PTHREAD",
  21. "/wd4018", # -Wno-sign-compare
  22. "/wd4065", # switch statement contains 'default' but no 'case' labels
  23. "/wd4146", # unary minus operator applied to unsigned type, result still unsigned
  24. "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data
  25. "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
  26. "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data
  27. "/wd4305", # 'identifier' : truncation from 'type1' to 'type2'
  28. "/wd4307", # 'operator' : integral constant overflow
  29. "/wd4309", # 'conversion' : truncation of constant value
  30. "/wd4334", # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
  31. "/wd4355", # 'this' : used in base member initializer list
  32. "/wd4506", # no definition for inline function 'function'
  33. "/wd4514", # -Wno-unused-function
  34. "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning)
  35. "/wd4996", # The compiler encountered a deprecated declaration.
  36. ]
  37. COPTS = select({
  38. ":msvc": MSVC_COPTS,
  39. "//conditions:default": [
  40. "-DHAVE_PTHREAD",
  41. "-DHAVE_ZLIB",
  42. "-Woverloaded-virtual",
  43. "-Wno-sign-compare",
  44. "-Wno-unused-function",
  45. # Prevents ISO C++ const string assignment warnings for pyext sources.
  46. "-Wno-write-strings",
  47. "-Wno-deprecated-declarations",
  48. ],
  49. })
  50. load(":compiler_config_setting.bzl", "create_compiler_config_setting")
  51. create_compiler_config_setting(
  52. name = "msvc",
  53. value = "msvc-cl",
  54. visibility = [
  55. # Public, but Protobuf only visibility.
  56. "//:__subpackages__",
  57. ],
  58. )
  59. config_setting(
  60. name = "android",
  61. values = {
  62. "crosstool_top": "//external:android/crosstool",
  63. },
  64. visibility = [
  65. # Public, but Protobuf only visibility.
  66. "//:__subpackages__",
  67. ],
  68. )
  69. config_setting(
  70. name = "android-libcpp",
  71. values = {
  72. "crosstool_top": "@androidndk//:toolchain-libcpp",
  73. },
  74. visibility = [
  75. # Public, but Protobuf only visibility.
  76. "//:__subpackages__",
  77. ],
  78. )
  79. config_setting(
  80. name = "android-gnu-libstdcpp",
  81. values = {
  82. "crosstool_top": "@androidndk//:toolchain-gnu-libstdcpp",
  83. },
  84. visibility = [
  85. # Public, but Protobuf only visibility.
  86. "//:__subpackages__",
  87. ],
  88. )
  89. # Android and MSVC builds do not need to link in a separate pthread library.
  90. LINK_OPTS = select({
  91. ":android": [],
  92. ":android-libcpp": [],
  93. ":android-gnu-libstdcpp": [],
  94. ":msvc": [
  95. # Suppress linker warnings about files with no symbols defined.
  96. "-ignore:4221",
  97. ],
  98. "//conditions:default": [
  99. "-lpthread",
  100. "-lm",
  101. ],
  102. })
  103. load(
  104. ":protobuf.bzl",
  105. "adapt_proto_library",
  106. "cc_proto_library",
  107. "internal_copied_filegroup",
  108. "internal_gen_well_known_protos_java",
  109. "internal_protobuf_py_tests",
  110. "py_proto_library",
  111. )
  112. cc_library(
  113. name = "protobuf_lite",
  114. srcs = [
  115. # AUTOGEN(protobuf_lite_srcs)
  116. "src/google/protobuf/any_lite.cc",
  117. "src/google/protobuf/arena.cc",
  118. "src/google/protobuf/arenastring.cc",
  119. "src/google/protobuf/extension_set.cc",
  120. "src/google/protobuf/generated_enum_util.cc",
  121. "src/google/protobuf/generated_message_table_driven_lite.cc",
  122. "src/google/protobuf/generated_message_util.cc",
  123. "src/google/protobuf/implicit_weak_message.cc",
  124. "src/google/protobuf/io/coded_stream.cc",
  125. "src/google/protobuf/io/io_win32.cc",
  126. "src/google/protobuf/io/strtod.cc",
  127. "src/google/protobuf/io/zero_copy_stream.cc",
  128. "src/google/protobuf/io/zero_copy_stream_impl.cc",
  129. "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
  130. "src/google/protobuf/map.cc",
  131. "src/google/protobuf/message_lite.cc",
  132. "src/google/protobuf/parse_context.cc",
  133. "src/google/protobuf/repeated_field.cc",
  134. "src/google/protobuf/stubs/bytestream.cc",
  135. "src/google/protobuf/stubs/common.cc",
  136. "src/google/protobuf/stubs/int128.cc",
  137. "src/google/protobuf/stubs/status.cc",
  138. "src/google/protobuf/stubs/statusor.cc",
  139. "src/google/protobuf/stubs/stringpiece.cc",
  140. "src/google/protobuf/stubs/stringprintf.cc",
  141. "src/google/protobuf/stubs/structurally_valid.cc",
  142. "src/google/protobuf/stubs/strutil.cc",
  143. "src/google/protobuf/stubs/time.cc",
  144. "src/google/protobuf/wire_format_lite.cc",
  145. ],
  146. hdrs = glob([
  147. "src/google/protobuf/**/*.h",
  148. "src/google/protobuf/**/*.inc",
  149. ]),
  150. copts = COPTS,
  151. includes = ["src/"],
  152. linkopts = LINK_OPTS,
  153. visibility = ["//visibility:public"],
  154. )
  155. PROTOBUF_DEPS = select({
  156. ":msvc": [],
  157. "//conditions:default": ZLIB_DEPS,
  158. })
  159. cc_library(
  160. name = "protobuf",
  161. srcs = [
  162. # AUTOGEN(protobuf_srcs)
  163. "src/google/protobuf/any.cc",
  164. "src/google/protobuf/any.pb.cc",
  165. "src/google/protobuf/api.pb.cc",
  166. "src/google/protobuf/compiler/importer.cc",
  167. "src/google/protobuf/compiler/parser.cc",
  168. "src/google/protobuf/descriptor.cc",
  169. "src/google/protobuf/descriptor.pb.cc",
  170. "src/google/protobuf/descriptor_database.cc",
  171. "src/google/protobuf/duration.pb.cc",
  172. "src/google/protobuf/dynamic_message.cc",
  173. "src/google/protobuf/empty.pb.cc",
  174. "src/google/protobuf/extension_set_heavy.cc",
  175. "src/google/protobuf/field_mask.pb.cc",
  176. "src/google/protobuf/generated_message_reflection.cc",
  177. "src/google/protobuf/generated_message_table_driven.cc",
  178. "src/google/protobuf/io/gzip_stream.cc",
  179. "src/google/protobuf/io/printer.cc",
  180. "src/google/protobuf/io/tokenizer.cc",
  181. "src/google/protobuf/map_field.cc",
  182. "src/google/protobuf/message.cc",
  183. "src/google/protobuf/reflection_ops.cc",
  184. "src/google/protobuf/service.cc",
  185. "src/google/protobuf/source_context.pb.cc",
  186. "src/google/protobuf/struct.pb.cc",
  187. "src/google/protobuf/stubs/substitute.cc",
  188. "src/google/protobuf/text_format.cc",
  189. "src/google/protobuf/timestamp.pb.cc",
  190. "src/google/protobuf/type.pb.cc",
  191. "src/google/protobuf/unknown_field_set.cc",
  192. "src/google/protobuf/util/delimited_message_util.cc",
  193. "src/google/protobuf/util/field_comparator.cc",
  194. "src/google/protobuf/util/field_mask_util.cc",
  195. "src/google/protobuf/util/internal/datapiece.cc",
  196. "src/google/protobuf/util/internal/default_value_objectwriter.cc",
  197. "src/google/protobuf/util/internal/error_listener.cc",
  198. "src/google/protobuf/util/internal/field_mask_utility.cc",
  199. "src/google/protobuf/util/internal/json_escaping.cc",
  200. "src/google/protobuf/util/internal/json_objectwriter.cc",
  201. "src/google/protobuf/util/internal/json_stream_parser.cc",
  202. "src/google/protobuf/util/internal/object_writer.cc",
  203. "src/google/protobuf/util/internal/proto_writer.cc",
  204. "src/google/protobuf/util/internal/protostream_objectsource.cc",
  205. "src/google/protobuf/util/internal/protostream_objectwriter.cc",
  206. "src/google/protobuf/util/internal/type_info.cc",
  207. "src/google/protobuf/util/internal/type_info_test_helper.cc",
  208. "src/google/protobuf/util/internal/utility.cc",
  209. "src/google/protobuf/util/json_util.cc",
  210. "src/google/protobuf/util/message_differencer.cc",
  211. "src/google/protobuf/util/time_util.cc",
  212. "src/google/protobuf/util/type_resolver_util.cc",
  213. "src/google/protobuf/wire_format.cc",
  214. "src/google/protobuf/wrappers.pb.cc",
  215. ],
  216. hdrs = glob([
  217. "src/**/*.h",
  218. "src/**/*.inc",
  219. ]),
  220. copts = COPTS,
  221. includes = ["src/"],
  222. linkopts = LINK_OPTS,
  223. visibility = ["//visibility:public"],
  224. deps = [":protobuf_lite"] + PROTOBUF_DEPS,
  225. )
  226. # This provides just the header files for use in projects that need to build
  227. # shared libraries for dynamic loading. This target is available until Bazel
  228. # adds native support for such use cases.
  229. # TODO(keveman): Remove this target once the support gets added to Bazel.
  230. cc_library(
  231. name = "protobuf_headers",
  232. hdrs = glob([
  233. "src/**/*.h",
  234. "src/**/*.inc",
  235. ]),
  236. includes = ["src/"],
  237. visibility = ["//visibility:public"],
  238. )
  239. # Map of all well known protos.
  240. # name => (include path, imports)
  241. WELL_KNOWN_PROTO_MAP = {
  242. "any": ("src/google/protobuf/any.proto", []),
  243. "api": (
  244. "src/google/protobuf/api.proto",
  245. [
  246. "source_context",
  247. "type",
  248. ],
  249. ),
  250. "compiler_plugin": (
  251. "src/google/protobuf/compiler/plugin.proto",
  252. ["descriptor"],
  253. ),
  254. "descriptor": ("src/google/protobuf/descriptor.proto", []),
  255. "duration": ("src/google/protobuf/duration.proto", []),
  256. "empty": ("src/google/protobuf/empty.proto", []),
  257. "field_mask": ("src/google/protobuf/field_mask.proto", []),
  258. "source_context": ("src/google/protobuf/source_context.proto", []),
  259. "struct": ("src/google/protobuf/struct.proto", []),
  260. "timestamp": ("src/google/protobuf/timestamp.proto", []),
  261. "type": (
  262. "src/google/protobuf/type.proto",
  263. [
  264. "any",
  265. "source_context",
  266. ],
  267. ),
  268. "wrappers": ("src/google/protobuf/wrappers.proto", []),
  269. }
  270. WELL_KNOWN_PROTOS = [value[0] for value in WELL_KNOWN_PROTO_MAP.values()]
  271. filegroup(
  272. name = "well_known_protos",
  273. srcs = WELL_KNOWN_PROTOS,
  274. visibility = ["//visibility:public"],
  275. )
  276. adapt_proto_library(
  277. name = "cc_wkt_protos_genproto",
  278. deps = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
  279. visibility = ["//visibility:public"],
  280. )
  281. cc_library(
  282. name = "cc_wkt_protos",
  283. deprecation = "Only for backward compatibility. Do not use.",
  284. visibility = ["//visibility:public"],
  285. )
  286. ################################################################################
  287. # Well Known Types Proto Library Rules
  288. #
  289. # These proto_library rules can be used with one of the language specific proto
  290. # library rules i.e. java_proto_library:
  291. #
  292. # java_proto_library(
  293. # name = "any_java_proto",
  294. # deps = ["@com_google_protobuf//:any_proto],
  295. # )
  296. ################################################################################
  297. [proto_library(
  298. name = proto[0] + "_proto",
  299. srcs = [proto[1][0]],
  300. strip_import_prefix = "src",
  301. visibility = ["//visibility:public"],
  302. deps = [dep + "_proto" for dep in proto[1][1]],
  303. ) for proto in WELL_KNOWN_PROTO_MAP.items()]
  304. [native_cc_proto_library(
  305. name = proto + "_cc_proto",
  306. deps = [proto + "_proto"],
  307. visibility = ["//visibility:private"],
  308. ) for proto in WELL_KNOWN_PROTO_MAP.keys()]
  309. cc_proto_blacklist_test(
  310. name = "cc_proto_blacklist_test",
  311. deps = [proto + "_cc_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
  312. tags = [
  313. # Exclude this target from wildcard expansion (//...). Due to
  314. # https://github.com/bazelbuild/bazel/issues/10590, this test has to
  315. # be nominated using the `@com_google_protobuf//` prefix. We do that,
  316. # e.g., in kokoro/linux/bazel/build.sh.
  317. # See also https://github.com/protocolbuffers/protobuf/pull/7096.
  318. "manual",
  319. ],
  320. )
  321. ################################################################################
  322. # Protocol Buffers Compiler
  323. ################################################################################
  324. cc_library(
  325. name = "protoc_lib",
  326. srcs = [
  327. # AUTOGEN(protoc_lib_srcs)
  328. "src/google/protobuf/compiler/code_generator.cc",
  329. "src/google/protobuf/compiler/command_line_interface.cc",
  330. "src/google/protobuf/compiler/cpp/cpp_enum.cc",
  331. "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
  332. "src/google/protobuf/compiler/cpp/cpp_extension.cc",
  333. "src/google/protobuf/compiler/cpp/cpp_field.cc",
  334. "src/google/protobuf/compiler/cpp/cpp_file.cc",
  335. "src/google/protobuf/compiler/cpp/cpp_generator.cc",
  336. "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
  337. "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
  338. "src/google/protobuf/compiler/cpp/cpp_message.cc",
  339. "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
  340. "src/google/protobuf/compiler/cpp/cpp_padding_optimizer.cc",
  341. "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
  342. "src/google/protobuf/compiler/cpp/cpp_service.cc",
  343. "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
  344. "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
  345. "src/google/protobuf/compiler/csharp/csharp_enum.cc",
  346. "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
  347. "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
  348. "src/google/protobuf/compiler/csharp/csharp_generator.cc",
  349. "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
  350. "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
  351. "src/google/protobuf/compiler/csharp/csharp_message.cc",
  352. "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
  353. "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
  354. "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
  355. "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
  356. "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
  357. "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
  358. "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
  359. "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
  360. "src/google/protobuf/compiler/java/java_context.cc",
  361. "src/google/protobuf/compiler/java/java_doc_comment.cc",
  362. "src/google/protobuf/compiler/java/java_enum.cc",
  363. "src/google/protobuf/compiler/java/java_enum_field.cc",
  364. "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
  365. "src/google/protobuf/compiler/java/java_enum_lite.cc",
  366. "src/google/protobuf/compiler/java/java_extension.cc",
  367. "src/google/protobuf/compiler/java/java_extension_lite.cc",
  368. "src/google/protobuf/compiler/java/java_field.cc",
  369. "src/google/protobuf/compiler/java/java_file.cc",
  370. "src/google/protobuf/compiler/java/java_generator.cc",
  371. "src/google/protobuf/compiler/java/java_generator_factory.cc",
  372. "src/google/protobuf/compiler/java/java_helpers.cc",
  373. "src/google/protobuf/compiler/java/java_map_field.cc",
  374. "src/google/protobuf/compiler/java/java_map_field_lite.cc",
  375. "src/google/protobuf/compiler/java/java_message.cc",
  376. "src/google/protobuf/compiler/java/java_message_builder.cc",
  377. "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
  378. "src/google/protobuf/compiler/java/java_message_field.cc",
  379. "src/google/protobuf/compiler/java/java_message_field_lite.cc",
  380. "src/google/protobuf/compiler/java/java_message_lite.cc",
  381. "src/google/protobuf/compiler/java/java_name_resolver.cc",
  382. "src/google/protobuf/compiler/java/java_primitive_field.cc",
  383. "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
  384. "src/google/protobuf/compiler/java/java_service.cc",
  385. "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
  386. "src/google/protobuf/compiler/java/java_string_field.cc",
  387. "src/google/protobuf/compiler/java/java_string_field_lite.cc",
  388. "src/google/protobuf/compiler/js/js_generator.cc",
  389. "src/google/protobuf/compiler/js/well_known_types_embed.cc",
  390. "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
  391. "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
  392. "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
  393. "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
  394. "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
  395. "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
  396. "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
  397. "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
  398. "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
  399. "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
  400. "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
  401. "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
  402. "src/google/protobuf/compiler/php/php_generator.cc",
  403. "src/google/protobuf/compiler/plugin.cc",
  404. "src/google/protobuf/compiler/plugin.pb.cc",
  405. "src/google/protobuf/compiler/python/python_generator.cc",
  406. "src/google/protobuf/compiler/ruby/ruby_generator.cc",
  407. "src/google/protobuf/compiler/subprocess.cc",
  408. "src/google/protobuf/compiler/zip_writer.cc",
  409. ],
  410. copts = COPTS,
  411. includes = ["src/"],
  412. linkopts = LINK_OPTS,
  413. visibility = ["//visibility:public"],
  414. deps = [":protobuf"],
  415. )
  416. cc_binary(
  417. name = "protoc",
  418. srcs = ["src/google/protobuf/compiler/main.cc"],
  419. linkopts = LINK_OPTS,
  420. visibility = ["//visibility:public"],
  421. deps = [":protoc_lib"],
  422. )
  423. ################################################################################
  424. # Tests
  425. ################################################################################
  426. RELATIVE_LITE_TEST_PROTOS = [
  427. # AUTOGEN(lite_test_protos)
  428. "google/protobuf/map_lite_unittest.proto",
  429. "google/protobuf/unittest_import_lite.proto",
  430. "google/protobuf/unittest_import_public_lite.proto",
  431. "google/protobuf/unittest_lite.proto",
  432. ]
  433. LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
  434. RELATIVE_TEST_PROTOS = [
  435. # AUTOGEN(test_protos)
  436. "google/protobuf/any_test.proto",
  437. "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
  438. "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
  439. "google/protobuf/map_proto2_unittest.proto",
  440. "google/protobuf/map_unittest.proto",
  441. "google/protobuf/unittest.proto",
  442. "google/protobuf/unittest_arena.proto",
  443. "google/protobuf/unittest_custom_options.proto",
  444. "google/protobuf/unittest_drop_unknown_fields.proto",
  445. "google/protobuf/unittest_embed_optimize_for.proto",
  446. "google/protobuf/unittest_empty.proto",
  447. "google/protobuf/unittest_enormous_descriptor.proto",
  448. "google/protobuf/unittest_import.proto",
  449. "google/protobuf/unittest_import_public.proto",
  450. "google/protobuf/unittest_lazy_dependencies.proto",
  451. "google/protobuf/unittest_lazy_dependencies_custom_option.proto",
  452. "google/protobuf/unittest_lazy_dependencies_enum.proto",
  453. "google/protobuf/unittest_lite_imports_nonlite.proto",
  454. "google/protobuf/unittest_mset.proto",
  455. "google/protobuf/unittest_mset_wire_format.proto",
  456. "google/protobuf/unittest_no_field_presence.proto",
  457. "google/protobuf/unittest_no_generic_services.proto",
  458. "google/protobuf/unittest_optimize_for.proto",
  459. "google/protobuf/unittest_preserve_unknown_enum.proto",
  460. "google/protobuf/unittest_preserve_unknown_enum2.proto",
  461. "google/protobuf/unittest_proto3.proto",
  462. "google/protobuf/unittest_proto3_arena.proto",
  463. "google/protobuf/unittest_proto3_arena_lite.proto",
  464. "google/protobuf/unittest_proto3_lite.proto",
  465. "google/protobuf/unittest_proto3_optional.proto",
  466. "google/protobuf/unittest_well_known_types.proto",
  467. "google/protobuf/util/internal/testdata/anys.proto",
  468. "google/protobuf/util/internal/testdata/books.proto",
  469. "google/protobuf/util/internal/testdata/default_value.proto",
  470. "google/protobuf/util/internal/testdata/default_value_test.proto",
  471. "google/protobuf/util/internal/testdata/field_mask.proto",
  472. "google/protobuf/util/internal/testdata/maps.proto",
  473. "google/protobuf/util/internal/testdata/oneofs.proto",
  474. "google/protobuf/util/internal/testdata/proto3.proto",
  475. "google/protobuf/util/internal/testdata/struct.proto",
  476. "google/protobuf/util/internal/testdata/timestamp_duration.proto",
  477. "google/protobuf/util/internal/testdata/wrappers.proto",
  478. "google/protobuf/util/json_format.proto",
  479. "google/protobuf/util/json_format_proto3.proto",
  480. "google/protobuf/util/message_differencer_unittest.proto",
  481. ]
  482. TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
  483. cc_proto_library(
  484. name = "cc_test_protos",
  485. srcs = LITE_TEST_PROTOS + TEST_PROTOS,
  486. include = "src",
  487. default_runtime = ":protobuf",
  488. protoc = ":protoc",
  489. deps = [":cc_wkt_protos"],
  490. )
  491. COMMON_TEST_SRCS = [
  492. # AUTOGEN(common_test_srcs)
  493. "src/google/protobuf/arena_test_util.cc",
  494. "src/google/protobuf/map_test_util.inc",
  495. "src/google/protobuf/test_util.cc",
  496. "src/google/protobuf/test_util.inc",
  497. "src/google/protobuf/testing/file.cc",
  498. "src/google/protobuf/testing/googletest.cc",
  499. ]
  500. cc_binary(
  501. name = "test_plugin",
  502. testonly = True,
  503. srcs = [
  504. # AUTOGEN(test_plugin_srcs)
  505. "src/google/protobuf/compiler/mock_code_generator.cc",
  506. "src/google/protobuf/compiler/test_plugin.cc",
  507. "src/google/protobuf/testing/file.cc",
  508. ],
  509. deps = [
  510. ":protobuf",
  511. ":protoc_lib",
  512. "@com_google_googletest//:gtest",
  513. ],
  514. )
  515. cc_test(
  516. name = "win32_test",
  517. srcs = ["src/google/protobuf/io/io_win32_unittest.cc"],
  518. tags = [
  519. "manual",
  520. "windows",
  521. ],
  522. deps = [
  523. ":protobuf_lite",
  524. "@com_google_googletest//:gtest",
  525. "@com_google_googletest//:gtest_main",
  526. ],
  527. )
  528. cc_test(
  529. name = "protobuf_test",
  530. srcs = COMMON_TEST_SRCS + [
  531. # AUTOGEN(test_srcs)
  532. "src/google/protobuf/any_test.cc",
  533. "src/google/protobuf/arena_unittest.cc",
  534. "src/google/protobuf/arenastring_unittest.cc",
  535. "src/google/protobuf/compiler/annotation_test_util.cc",
  536. "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
  537. "src/google/protobuf/compiler/cpp/cpp_move_unittest.cc",
  538. "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
  539. "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
  540. "src/google/protobuf/compiler/cpp/cpp_unittest.inc",
  541. "src/google/protobuf/compiler/cpp/metadata_test.cc",
  542. "src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc",
  543. "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
  544. "src/google/protobuf/compiler/importer_unittest.cc",
  545. "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
  546. "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
  547. "src/google/protobuf/compiler/mock_code_generator.cc",
  548. "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
  549. "src/google/protobuf/compiler/parser_unittest.cc",
  550. "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
  551. "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
  552. "src/google/protobuf/descriptor_database_unittest.cc",
  553. "src/google/protobuf/descriptor_unittest.cc",
  554. "src/google/protobuf/drop_unknown_fields_test.cc",
  555. "src/google/protobuf/dynamic_message_unittest.cc",
  556. "src/google/protobuf/extension_set_unittest.cc",
  557. "src/google/protobuf/generated_message_reflection_unittest.cc",
  558. "src/google/protobuf/io/coded_stream_unittest.cc",
  559. "src/google/protobuf/io/io_win32_unittest.cc",
  560. "src/google/protobuf/io/printer_unittest.cc",
  561. "src/google/protobuf/io/tokenizer_unittest.cc",
  562. "src/google/protobuf/io/zero_copy_stream_unittest.cc",
  563. "src/google/protobuf/map_field_test.cc",
  564. "src/google/protobuf/map_test.cc",
  565. "src/google/protobuf/message_unittest.cc",
  566. "src/google/protobuf/message_unittest.inc",
  567. "src/google/protobuf/no_field_presence_test.cc",
  568. "src/google/protobuf/preserve_unknown_enum_test.cc",
  569. "src/google/protobuf/proto3_arena_lite_unittest.cc",
  570. "src/google/protobuf/proto3_arena_unittest.cc",
  571. "src/google/protobuf/proto3_lite_unittest.cc",
  572. "src/google/protobuf/proto3_lite_unittest.inc",
  573. "src/google/protobuf/reflection_ops_unittest.cc",
  574. "src/google/protobuf/repeated_field_reflection_unittest.cc",
  575. "src/google/protobuf/repeated_field_unittest.cc",
  576. "src/google/protobuf/stubs/bytestream_unittest.cc",
  577. "src/google/protobuf/stubs/common_unittest.cc",
  578. "src/google/protobuf/stubs/int128_unittest.cc",
  579. "src/google/protobuf/stubs/status_test.cc",
  580. "src/google/protobuf/stubs/statusor_test.cc",
  581. "src/google/protobuf/stubs/stringpiece_unittest.cc",
  582. "src/google/protobuf/stubs/stringprintf_unittest.cc",
  583. "src/google/protobuf/stubs/structurally_valid_unittest.cc",
  584. "src/google/protobuf/stubs/strutil_unittest.cc",
  585. "src/google/protobuf/stubs/template_util_unittest.cc",
  586. "src/google/protobuf/stubs/time_test.cc",
  587. "src/google/protobuf/text_format_unittest.cc",
  588. "src/google/protobuf/unknown_field_set_unittest.cc",
  589. "src/google/protobuf/util/delimited_message_util_test.cc",
  590. "src/google/protobuf/util/field_comparator_test.cc",
  591. "src/google/protobuf/util/field_mask_util_test.cc",
  592. "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
  593. "src/google/protobuf/util/internal/json_objectwriter_test.cc",
  594. "src/google/protobuf/util/internal/json_stream_parser_test.cc",
  595. "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
  596. "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
  597. "src/google/protobuf/util/internal/type_info_test_helper.cc",
  598. "src/google/protobuf/util/json_util_test.cc",
  599. "src/google/protobuf/util/message_differencer_unittest.cc",
  600. "src/google/protobuf/util/time_util_test.cc",
  601. "src/google/protobuf/util/type_resolver_util_test.cc",
  602. "src/google/protobuf/well_known_types_unittest.cc",
  603. "src/google/protobuf/wire_format_unittest.cc",
  604. ] + select({
  605. "//conditions:default": [
  606. # AUTOGEN(non_msvc_test_srcs)
  607. "src/google/protobuf/compiler/command_line_interface_unittest.cc",
  608. ],
  609. ":msvc": [],
  610. }),
  611. copts = COPTS,
  612. data = [
  613. ":test_plugin",
  614. ] + glob([
  615. "src/google/protobuf/**/*",
  616. # Files for csharp_bootstrap_unittest.cc.
  617. "conformance/**/*",
  618. "csharp/src/**/*",
  619. ]),
  620. includes = [
  621. "src/",
  622. ],
  623. linkopts = LINK_OPTS,
  624. deps = [
  625. ":cc_test_protos",
  626. ":protobuf",
  627. ":protoc_lib",
  628. "@com_google_googletest//:gtest",
  629. "@com_google_googletest//:gtest_main",
  630. ] + PROTOBUF_DEPS,
  631. )
  632. ################################################################################
  633. # Java support
  634. ################################################################################
  635. internal_gen_well_known_protos_java(
  636. name = "gen_well_known_protos_java",
  637. deps = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
  638. visibility = [
  639. "//java:__subpackages__",
  640. ],
  641. )
  642. alias(
  643. name = "protobuf_java",
  644. actual = "//java/core",
  645. visibility = ["//visibility:public"],
  646. )
  647. alias(
  648. name = "protobuf_javalite",
  649. actual = "//java/lite",
  650. visibility = ["//visibility:public"],
  651. )
  652. alias(
  653. name = "protobuf_java_util",
  654. actual = "//java/util",
  655. visibility = ["//visibility:public"],
  656. )
  657. alias(
  658. name = "java_toolchain",
  659. actual = "//java/core:toolchain",
  660. visibility = ["//visibility:public"],
  661. )
  662. alias(
  663. name = "javalite_toolchain",
  664. actual = "//java/lite:toolchain",
  665. visibility = ["//visibility:public"],
  666. )
  667. ################################################################################
  668. # Python support
  669. ################################################################################
  670. py_library(
  671. name = "python_srcs",
  672. srcs = glob(
  673. [
  674. "python/google/protobuf/**/*.py",
  675. ],
  676. exclude = [
  677. "python/google/protobuf/internal/*_test.py",
  678. "python/google/protobuf/internal/test_util.py",
  679. ],
  680. ),
  681. imports = ["python"],
  682. srcs_version = "PY2AND3",
  683. )
  684. cc_binary(
  685. name = "python/google/protobuf/internal/_api_implementation.so",
  686. srcs = ["python/google/protobuf/internal/api_implementation.cc"],
  687. copts = COPTS + [
  688. "-DPYTHON_PROTO2_CPP_IMPL_V2",
  689. ],
  690. tags = [
  691. # Exclude this target from wildcard expansion (//...) because it may
  692. # not even be buildable. It will be built if it is needed according
  693. # to :use_fast_cpp_protos.
  694. # https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes
  695. "manual",
  696. ],
  697. linkshared = 1,
  698. linkstatic = 1,
  699. deps = select({
  700. "//conditions:default": [],
  701. ":use_fast_cpp_protos": ["//external:python_headers"],
  702. }),
  703. )
  704. cc_binary(
  705. name = "python/google/protobuf/pyext/_message.so",
  706. srcs = glob([
  707. "python/google/protobuf/pyext/*.cc",
  708. "python/google/protobuf/pyext/*.h",
  709. ]),
  710. copts = COPTS + [
  711. "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
  712. ] + select({
  713. "//conditions:default": [],
  714. ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
  715. }),
  716. includes = [
  717. "python/",
  718. "src/",
  719. ],
  720. tags = [
  721. # Exclude this target from wildcard expansion (//...) because it may
  722. # not even be buildable. It will be built if it is needed according
  723. # to :use_fast_cpp_protos.
  724. # https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes
  725. "manual",
  726. ],
  727. linkshared = 1,
  728. linkstatic = 1,
  729. deps = [
  730. ":protobuf",
  731. ":proto_api",
  732. ] + select({
  733. "//conditions:default": [],
  734. ":use_fast_cpp_protos": ["//external:python_headers"],
  735. }),
  736. )
  737. config_setting(
  738. name = "use_fast_cpp_protos",
  739. values = {
  740. "define": "use_fast_cpp_protos=true",
  741. },
  742. visibility = [
  743. # Public, but Protobuf only visibility.
  744. "//:__subpackages__",
  745. ],
  746. )
  747. config_setting(
  748. name = "allow_oversize_protos",
  749. values = {
  750. "define": "allow_oversize_protos=true",
  751. },
  752. visibility = [
  753. # Public, but Protobuf only visibility.
  754. "//:__subpackages__",
  755. ],
  756. )
  757. # Copy the builtin proto files from src/google/protobuf to
  758. # python/google/protobuf. This way, the generated Python sources will be in the
  759. # same directory as the Python runtime sources. This is necessary for the
  760. # modules to be imported correctly since they are all part of the same Python
  761. # package.
  762. internal_copied_filegroup(
  763. name = "protos_python",
  764. srcs = WELL_KNOWN_PROTOS,
  765. dest = "python",
  766. strip_prefix = "src",
  767. )
  768. # TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
  769. # which case we can simply add :protos_python in srcs.
  770. COPIED_WELL_KNOWN_PROTOS = ["python/" + s[4:] for s in WELL_KNOWN_PROTOS]
  771. py_proto_library(
  772. name = "protobuf_python",
  773. srcs = COPIED_WELL_KNOWN_PROTOS,
  774. include = "python",
  775. data = select({
  776. "//conditions:default": [],
  777. ":use_fast_cpp_protos": [
  778. ":python/google/protobuf/internal/_api_implementation.so",
  779. ":python/google/protobuf/pyext/_message.so",
  780. ],
  781. }),
  782. default_runtime = "",
  783. protoc = ":protoc",
  784. py_libs = [
  785. ":python_srcs",
  786. "@six//:six",
  787. ],
  788. srcs_version = "PY2AND3",
  789. visibility = ["//visibility:public"],
  790. )
  791. # Copy the test proto files from src/google/protobuf to
  792. # python/google/protobuf. This way, the generated Python sources will be in the
  793. # same directory as the Python runtime sources. This is necessary for the
  794. # modules to be imported correctly by the tests since they are all part of the
  795. # same Python package.
  796. internal_copied_filegroup(
  797. name = "protos_python_test",
  798. srcs = LITE_TEST_PROTOS + TEST_PROTOS,
  799. dest = "python",
  800. strip_prefix = "src",
  801. )
  802. # TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
  803. # which case we can simply add :protos_python_test in srcs.
  804. COPIED_LITE_TEST_PROTOS = ["python/" + s for s in RELATIVE_LITE_TEST_PROTOS]
  805. COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]
  806. py_proto_library(
  807. name = "python_common_test_protos",
  808. srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
  809. include = "python",
  810. default_runtime = "",
  811. protoc = ":protoc",
  812. srcs_version = "PY2AND3",
  813. deps = [":protobuf_python"],
  814. )
  815. py_proto_library(
  816. name = "python_specific_test_protos",
  817. srcs = glob([
  818. "python/google/protobuf/internal/*.proto",
  819. "python/google/protobuf/internal/import_test_package/*.proto",
  820. ]),
  821. include = "python",
  822. default_runtime = ":protobuf_python",
  823. protoc = ":protoc",
  824. srcs_version = "PY2AND3",
  825. deps = [":python_common_test_protos"],
  826. )
  827. py_library(
  828. name = "python_tests",
  829. srcs = glob(
  830. [
  831. "python/google/protobuf/internal/*_test.py",
  832. "python/google/protobuf/internal/test_util.py",
  833. "python/google/protobuf/internal/import_test_package/__init__.py",
  834. ],
  835. ),
  836. imports = ["python"],
  837. srcs_version = "PY2AND3",
  838. deps = [
  839. ":protobuf_python",
  840. ":python_common_test_protos",
  841. ":python_specific_test_protos",
  842. ],
  843. )
  844. internal_protobuf_py_tests(
  845. name = "python_tests_batch",
  846. data = glob([
  847. "src/google/protobuf/**/*",
  848. ]),
  849. modules = [
  850. "descriptor_database_test",
  851. "descriptor_pool_test",
  852. "descriptor_test",
  853. "generator_test",
  854. "json_format_test",
  855. "message_factory_test",
  856. "message_test",
  857. "proto_builder_test",
  858. "reflection_test",
  859. "service_reflection_test",
  860. "symbol_database_test",
  861. "text_encoding_test",
  862. "text_format_test",
  863. "unknown_fields_test",
  864. "wire_format_test",
  865. ],
  866. deps = [":python_tests"],
  867. )
  868. cc_library(
  869. name = "proto_api",
  870. hdrs = ["python/google/protobuf/proto_api.h"],
  871. visibility = ["//visibility:public"],
  872. deps = [
  873. "//external:python_headers",
  874. ],
  875. )
  876. proto_lang_toolchain(
  877. name = "cc_toolchain",
  878. blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
  879. command_line = "--cpp_out=$(OUT)",
  880. runtime = ":protobuf",
  881. visibility = ["//visibility:public"],
  882. )
  883. alias(
  884. name = "objectivec",
  885. actual = "//objectivec",
  886. visibility = ["//visibility:public"],
  887. )
  888. alias(
  889. name = "protobuf_objc",
  890. actual = "//objectivec",
  891. visibility = ["//visibility:public"],
  892. )
  893. ################################################################################
  894. # Test generated proto support
  895. ################################################################################
  896. genrule(
  897. name = "generated_protos",
  898. srcs = ["src/google/protobuf/unittest_import.proto"],
  899. outs = ["unittest_gen.proto"],
  900. cmd = "cat $(SRCS) | sed 's|google/|src/google/|' > $(OUTS)",
  901. )
  902. proto_library(
  903. name = "generated_protos_proto",
  904. srcs = [
  905. "src/google/protobuf/unittest_import_public.proto",
  906. "unittest_gen.proto",
  907. ],
  908. )
  909. py_proto_library(
  910. name = "generated_protos_py",
  911. srcs = [
  912. "src/google/protobuf/unittest_import_public.proto",
  913. "unittest_gen.proto",
  914. ],
  915. default_runtime = "",
  916. protoc = ":protoc",
  917. )
  918. ################################################################################
  919. # Conformance tests
  920. ################################################################################
  921. proto_library(
  922. name = "test_messages_proto2_proto",
  923. srcs = ["src/google/protobuf/test_messages_proto2.proto"],
  924. visibility = ["//visibility:public"],
  925. )
  926. proto_library(
  927. name = "test_messages_proto3_proto",
  928. srcs = ["src/google/protobuf/test_messages_proto3.proto"],
  929. visibility = ["//visibility:public"],
  930. deps = [
  931. ":any_proto",
  932. ":duration_proto",
  933. ":field_mask_proto",
  934. ":struct_proto",
  935. ":timestamp_proto",
  936. ":wrappers_proto",
  937. ],
  938. )
  939. cc_proto_library(
  940. name = "test_messages_proto2_proto_cc",
  941. srcs = ["src/google/protobuf/test_messages_proto2.proto"],
  942. )
  943. cc_proto_library(
  944. name = "test_messages_proto3_proto_cc",
  945. srcs = ["src/google/protobuf/test_messages_proto3.proto"],
  946. deps = [
  947. ":cc_wkt_protos",
  948. ],
  949. )
  950. proto_library(
  951. name = "conformance_proto",
  952. srcs = ["conformance/conformance.proto"],
  953. visibility = ["//visibility:public"],
  954. )
  955. cc_proto_library(
  956. name = "conformance_proto_cc",
  957. srcs = ["conformance/conformance.proto"],
  958. )
  959. cc_library(
  960. name = "jsoncpp",
  961. srcs = ["conformance/third_party/jsoncpp/jsoncpp.cpp"],
  962. hdrs = ["conformance/third_party/jsoncpp/json.h"],
  963. includes = ["conformance"],
  964. )
  965. cc_library(
  966. name = "conformance_test",
  967. srcs = [
  968. "conformance/conformance_test.cc",
  969. "conformance/conformance_test_runner.cc",
  970. ],
  971. hdrs = [
  972. "conformance/conformance_test.h",
  973. ],
  974. includes = [
  975. "conformance",
  976. "src",
  977. ],
  978. deps = [":conformance_proto_cc"],
  979. )
  980. cc_library(
  981. name = "binary_json_conformance_suite",
  982. srcs = ["conformance/binary_json_conformance_suite.cc"],
  983. hdrs = ["conformance/binary_json_conformance_suite.h"],
  984. deps = [
  985. ":conformance_test",
  986. ":jsoncpp",
  987. ":test_messages_proto2_proto_cc",
  988. ":test_messages_proto3_proto_cc",
  989. ],
  990. )
  991. cc_library(
  992. name = "text_format_conformance_suite",
  993. srcs = ["conformance/text_format_conformance_suite.cc"],
  994. hdrs = ["conformance/text_format_conformance_suite.h"],
  995. deps = [
  996. ":conformance_test",
  997. ":test_messages_proto2_proto_cc",
  998. ":test_messages_proto3_proto_cc",
  999. ],
  1000. )
  1001. cc_binary(
  1002. name = "conformance_test_runner",
  1003. srcs = ["conformance/conformance_test_main.cc"],
  1004. visibility = ["//visibility:public"],
  1005. deps = [
  1006. ":binary_json_conformance_suite",
  1007. ":conformance_test",
  1008. ":text_format_conformance_suite",
  1009. ],
  1010. )
  1011. sh_test(
  1012. name = "build_files_updated_unittest",
  1013. srcs = [
  1014. "build_files_updated_unittest.sh",
  1015. ],
  1016. data = [
  1017. "BUILD",
  1018. "cmake/extract_includes.bat.in",
  1019. "cmake/libprotobuf.cmake",
  1020. "cmake/libprotobuf-lite.cmake",
  1021. "cmake/libprotoc.cmake",
  1022. "cmake/tests.cmake",
  1023. "src/Makefile.am",
  1024. "update_file_lists.sh",
  1025. ],
  1026. )