BUILD.bazel 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406
  1. ################################################################################
  2. # Protocol Buffers: C++ Runtime and common proto files
  3. ################################################################################
  4. load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test")
  5. load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
  6. load("@rules_proto//proto:defs.bzl", "proto_library")
  7. load("@upb//cmake:build_defs.bzl", "staleness_test")
  8. load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")
  9. package(
  10. default_visibility = [
  11. "//:__pkg__", # "public" targets are alias rules in //.
  12. "//json:__subpackages__",
  13. ],
  14. )
  15. proto_library(
  16. name = "any_proto",
  17. srcs = ["any.proto"],
  18. strip_import_prefix = "/src",
  19. )
  20. proto_library(
  21. name = "api_proto",
  22. srcs = ["api.proto"],
  23. strip_import_prefix = "/src",
  24. deps = [
  25. "//:source_context_proto",
  26. "//:type_proto",
  27. ],
  28. )
  29. proto_library(
  30. name = "duration_proto",
  31. srcs = ["duration.proto"],
  32. strip_import_prefix = "/src",
  33. )
  34. proto_library(
  35. name = "empty_proto",
  36. srcs = ["empty.proto"],
  37. strip_import_prefix = "/src",
  38. )
  39. proto_library(
  40. name = "field_mask_proto",
  41. srcs = ["field_mask.proto"],
  42. strip_import_prefix = "/src",
  43. )
  44. proto_library(
  45. name = "source_context_proto",
  46. srcs = ["source_context.proto"],
  47. strip_import_prefix = "/src",
  48. )
  49. proto_library(
  50. name = "struct_proto",
  51. srcs = ["struct.proto"],
  52. strip_import_prefix = "/src",
  53. )
  54. proto_library(
  55. name = "timestamp_proto",
  56. srcs = ["timestamp.proto"],
  57. strip_import_prefix = "/src",
  58. )
  59. proto_library(
  60. name = "type_proto",
  61. srcs = ["type.proto"],
  62. strip_import_prefix = "/src",
  63. deps = [
  64. "//:any_proto",
  65. "//:source_context_proto",
  66. ],
  67. )
  68. proto_library(
  69. name = "wrappers_proto",
  70. srcs = ["wrappers.proto"],
  71. strip_import_prefix = "/src",
  72. )
  73. # Generate code for the well-known types on demand.
  74. # This needs to be done in a separate genrule because we publish protoc and the
  75. # C++ runtime with the WKT code linked in. We need to use a stripped down
  76. # compiler and runtime library to generate them, and cc_proto_library doesn't
  77. # support swapping out the compiler binary (even though a custom runtime can
  78. # be passed to proto_lang_toolchain).
  79. #
  80. # TODO(b/246826624) We still check in generated pb.h and pb.cc files purely to
  81. # support CMake builds. These aren't used at all by Bazel and will be removed
  82. # in the future once CMake can generate them too.
  83. WELL_KNOWN_TYPES = [
  84. "any",
  85. "api",
  86. "duration",
  87. "empty",
  88. "field_mask",
  89. "source_context",
  90. "struct",
  91. "timestamp",
  92. "type",
  93. "wrappers",
  94. ]
  95. proto_library(
  96. name = "wkt_proto",
  97. visibility = ["//visibility:private"],
  98. deps = [wkt + "_proto" for wkt in WELL_KNOWN_TYPES],
  99. )
  100. cc_proto_library(
  101. name = "wkt_cc_proto",
  102. visibility = ["//pkg:__pkg__"],
  103. deps = ["wkt_proto"],
  104. )
  105. # When we generate code for the well-known types, we put the resulting files in
  106. # wkt/google/protobuf and add ./wkt to the include paths below. This is a
  107. # somewhat strange setup but is necessary to satisfy these two constraints:
  108. # - We need to keep the checked-in sources for now, since Cocoapods relies on
  109. # them.
  110. # - The Bazel build should always use the generated sources so that developers
  111. # don't have to worry about manually updating the checked-in sources.
  112. genrule(
  113. name = "gen_wkt_cc_sources",
  114. srcs = [wkt + ".proto" for wkt in WELL_KNOWN_TYPES],
  115. outs =
  116. ["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] +
  117. ["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
  118. cmd = """
  119. $(execpath //:protoc) \
  120. --cpp_out=dllexport_decl=PROTOBUF_EXPORT:$(RULEDIR)/wkt \
  121. --proto_path=$$(dirname $$(dirname $$(dirname $(location any.proto)))) \
  122. $(SRCS)
  123. """,
  124. exec_tools = ["//:protoc"],
  125. visibility = ["//visibility:private"],
  126. )
  127. staleness_test(
  128. name = "well_known_types_staleness_test",
  129. outs =
  130. [wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] +
  131. [wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
  132. generated_pattern = "wkt/google/protobuf/%s",
  133. tags = ["manual"],
  134. )
  135. # This is necessary for our generated cmake configs to pick up the checked in
  136. # WKT files.
  137. # TODO(b/246826624) Remove this once we generate WKT code from cmake.
  138. cc_library(
  139. name = "cmake_wkt_cc_proto",
  140. srcs = ["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
  141. hdrs = ["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES],
  142. copts = COPTS,
  143. includes = ["wkt"],
  144. linkopts = LINK_OPTS,
  145. visibility = ["//pkg:__pkg__"],
  146. deps = [":protobuf_nowkt"],
  147. )
  148. # Built-in runtime types
  149. proto_library(
  150. name = "descriptor_proto",
  151. srcs = ["descriptor.proto"],
  152. strip_import_prefix = "/src",
  153. visibility = [
  154. "//:__pkg__",
  155. "//pkg:__pkg__",
  156. ],
  157. )
  158. ################################################################################
  159. # C++ Runtime Library
  160. ################################################################################
  161. cc_library(
  162. name = "port_def",
  163. hdrs = [
  164. "port.h",
  165. "port_def.inc",
  166. "port_undef.inc",
  167. ],
  168. include_prefix = "google/protobuf",
  169. visibility = [
  170. "//:__subpackages__",
  171. "//src/google/protobuf:__subpackages__",
  172. ],
  173. deps = [
  174. "@com_google_absl//absl/meta:type_traits",
  175. ],
  176. )
  177. cc_library(
  178. name = "arena_align",
  179. srcs = ["arena_align.cc"],
  180. hdrs = ["arena_align.h"],
  181. include_prefix = "google/protobuf",
  182. visibility = [
  183. "//:__subpackages__",
  184. "//src/google/protobuf:__subpackages__",
  185. ],
  186. deps = [
  187. "//src/google/protobuf/stubs:lite",
  188. "@com_google_absl//absl/log:absl_check",
  189. "@com_google_absl//absl/log:absl_log",
  190. "@com_google_absl//absl/numeric:bits",
  191. ],
  192. )
  193. cc_library(
  194. name = "arena_cleanup",
  195. hdrs = ["arena_cleanup.h"],
  196. include_prefix = "google/protobuf",
  197. visibility = [
  198. "//:__subpackages__",
  199. "//src/google/protobuf:__subpackages__",
  200. ],
  201. deps = [
  202. "@com_google_absl//absl/base:core_headers",
  203. "@com_google_absl//absl/log:absl_log",
  204. ],
  205. )
  206. cc_library(
  207. name = "arena_config",
  208. srcs = ["arena_config.cc"],
  209. hdrs = ["arena_config.h"],
  210. include_prefix = "google/protobuf",
  211. visibility = [
  212. "//:__subpackages__",
  213. "//src/google/protobuf:__subpackages__",
  214. ],
  215. deps = [
  216. "//src/google/protobuf/stubs:lite",
  217. ],
  218. )
  219. cc_library(
  220. name = "arena_allocation_policy",
  221. hdrs = ["arena_allocation_policy.h"],
  222. include_prefix = "google/protobuf",
  223. visibility = [
  224. "//:__subpackages__",
  225. "//src/google/protobuf:__subpackages__",
  226. ],
  227. deps = [
  228. ":arena_config",
  229. "//src/google/protobuf/stubs:lite",
  230. ],
  231. )
  232. cc_library(
  233. name = "string_block",
  234. hdrs = ["string_block.h"],
  235. include_prefix = "google/protobuf",
  236. deps = [
  237. ":arena_align",
  238. "@com_google_absl//absl/base:core_headers",
  239. "@com_google_absl//absl/log:absl_check",
  240. ],
  241. )
  242. cc_test(
  243. name = "string_block_test",
  244. srcs = ["string_block_test.cc"],
  245. deps = [
  246. ":string_block",
  247. "@com_google_googletest//:gtest",
  248. "@com_google_googletest//:gtest_main",
  249. ],
  250. )
  251. cc_library(
  252. name = "arena",
  253. srcs = [
  254. "arena.cc",
  255. ],
  256. hdrs = [
  257. "arena.h",
  258. "arena_config.h",
  259. "arenaz_sampler.h",
  260. "serial_arena.h",
  261. "thread_safe_arena.h",
  262. ],
  263. include_prefix = "google/protobuf",
  264. visibility = [
  265. "//:__subpackages__",
  266. "//src/google/protobuf:__subpackages__",
  267. ],
  268. deps = [
  269. ":arena_align",
  270. ":arena_allocation_policy",
  271. ":arena_cleanup",
  272. ":arena_config",
  273. ":string_block",
  274. "//src/google/protobuf/stubs:lite",
  275. "@com_google_absl//absl/log:absl_check",
  276. "@com_google_absl//absl/log:absl_log",
  277. "@com_google_absl//absl/synchronization",
  278. ],
  279. )
  280. cc_library(
  281. name = "protobuf_lite",
  282. srcs = [
  283. "any_lite.cc",
  284. "arenastring.cc",
  285. "arenaz_sampler.cc",
  286. "extension_set.cc",
  287. "generated_enum_util.cc",
  288. "generated_message_tctable_lite.cc",
  289. "generated_message_util.cc",
  290. "implicit_weak_message.cc",
  291. "inlined_string_field.cc",
  292. "map.cc",
  293. "message_lite.cc",
  294. "parse_context.cc",
  295. "repeated_field.cc",
  296. "repeated_ptr_field.cc",
  297. "wire_format_lite.cc",
  298. ],
  299. hdrs = [
  300. "any.h",
  301. "arena.h",
  302. "arenastring.h",
  303. "arenaz_sampler.h",
  304. "endian.h",
  305. "explicitly_constructed.h",
  306. "extension_set.h",
  307. "extension_set_inl.h",
  308. "generated_enum_util.h",
  309. "generated_message_tctable_decl.h",
  310. "generated_message_tctable_impl.h",
  311. "generated_message_util.h",
  312. "has_bits.h",
  313. "implicit_weak_message.h",
  314. "inlined_string_field.h",
  315. "map.h",
  316. "map_entry_lite.h",
  317. "map_field_lite.h",
  318. "map_type_handler.h",
  319. "message_lite.h",
  320. "metadata_lite.h",
  321. "parse_context.h",
  322. "port.h",
  323. "repeated_field.h",
  324. "repeated_ptr_field.h",
  325. "serial_arena.h",
  326. "thread_safe_arena.h",
  327. "wire_format_lite.h",
  328. ],
  329. copts = COPTS + select({
  330. "//build_defs:config_msvc": [],
  331. "//conditions:default": [
  332. "-Wno-error",
  333. ],
  334. }),
  335. include_prefix = "google/protobuf",
  336. linkopts = LINK_OPTS,
  337. visibility = [
  338. "//:__pkg__",
  339. "//pkg:__pkg__",
  340. "//src/google/protobuf:__subpackages__",
  341. ],
  342. # In Bazel 6.0+, these will be `interface_deps`:
  343. deps = [
  344. ":arena",
  345. ":arena_align",
  346. ":arena_config",
  347. ":string_block",
  348. "//src/google/protobuf/io",
  349. "//src/google/protobuf/stubs:lite",
  350. "@com_google_absl//absl/container:btree",
  351. "@com_google_absl//absl/container:flat_hash_set",
  352. "@com_google_absl//absl/hash",
  353. "@com_google_absl//absl/log:absl_check",
  354. "@com_google_absl//absl/log:absl_log",
  355. "@com_google_absl//absl/meta:type_traits",
  356. "@com_google_absl//absl/numeric:bits",
  357. "@com_google_absl//absl/strings:internal",
  358. "@com_google_absl//absl/synchronization",
  359. "@com_google_absl//absl/time",
  360. "@utf8_range//:utf8_validity",
  361. ],
  362. )
  363. cc_library(
  364. name = "protobuf_nowkt",
  365. srcs = [
  366. "any.cc",
  367. "descriptor.cc",
  368. "descriptor.pb.cc",
  369. "descriptor_database.cc",
  370. "dynamic_message.cc",
  371. "extension_set_heavy.cc",
  372. "generated_message_bases.cc",
  373. "generated_message_reflection.cc",
  374. "generated_message_tctable_full.cc",
  375. "generated_message_tctable_gen.cc",
  376. "map_field.cc",
  377. "message.cc",
  378. "reflection_ops.cc",
  379. "service.cc",
  380. "text_format.cc",
  381. "unknown_field_set.cc",
  382. "wire_format.cc",
  383. ],
  384. hdrs = [
  385. "descriptor.h",
  386. "descriptor.pb.h",
  387. "descriptor_database.h",
  388. "dynamic_message.h",
  389. "field_access_listener.h",
  390. "generated_enum_reflection.h",
  391. "generated_message_bases.h",
  392. "generated_message_reflection.h",
  393. "generated_message_tctable_gen.h",
  394. "map_entry.h",
  395. "map_field.h",
  396. "map_field_inl.h",
  397. "message.h",
  398. "metadata.h",
  399. "reflection.h",
  400. "reflection_internal.h",
  401. "reflection_ops.h",
  402. "service.h",
  403. "text_format.h",
  404. "unknown_field_set.h",
  405. "wire_format.h",
  406. ],
  407. copts = COPTS,
  408. include_prefix = "google/protobuf",
  409. linkopts = LINK_OPTS,
  410. visibility = [
  411. "//:__pkg__",
  412. "//pkg:__pkg__",
  413. "//src/google/protobuf:__subpackages__",
  414. ],
  415. deps = [
  416. ":protobuf_lite",
  417. "//src/google/protobuf/io",
  418. "//src/google/protobuf/io:gzip_stream",
  419. "//src/google/protobuf/io:printer",
  420. "//src/google/protobuf/io:tokenizer",
  421. "//src/google/protobuf/stubs",
  422. "@com_google_absl//absl/base",
  423. "@com_google_absl//absl/base:dynamic_annotations",
  424. "@com_google_absl//absl/container:btree",
  425. "@com_google_absl//absl/container:flat_hash_map",
  426. "@com_google_absl//absl/container:flat_hash_set",
  427. "@com_google_absl//absl/hash",
  428. "@com_google_absl//absl/log:absl_check",
  429. "@com_google_absl//absl/log:absl_log",
  430. "@com_google_absl//absl/strings:internal",
  431. "@com_google_absl//absl/synchronization",
  432. "@com_google_absl//absl/time",
  433. "@utf8_range//:utf8_validity",
  434. ],
  435. )
  436. cc_library(
  437. name = "protobuf",
  438. copts = COPTS,
  439. include_prefix = "google/protobuf",
  440. linkopts = LINK_OPTS,
  441. visibility = [
  442. "//:__pkg__",
  443. "//pkg:__pkg__",
  444. "//src/google/protobuf:__subpackages__",
  445. ],
  446. deps = [
  447. ":protobuf_nowkt",
  448. ":wkt_cc_proto",
  449. ],
  450. )
  451. # This provides just the header files for use in projects that need to build
  452. # shared libraries for dynamic loading. This target is available until Bazel
  453. # adds native support for such use cases.
  454. # TODO(keveman): Remove this target once the support gets added to Bazel.
  455. cc_library(
  456. name = "protobuf_headers",
  457. hdrs = glob([
  458. "**/*.h",
  459. "**/*.inc",
  460. ]),
  461. )
  462. filegroup(
  463. name = "well_known_type_protos",
  464. srcs = [
  465. "any.proto",
  466. "api.proto",
  467. "duration.proto",
  468. "empty.proto",
  469. "field_mask.proto",
  470. "source_context.proto",
  471. "struct.proto",
  472. "timestamp.proto",
  473. "type.proto",
  474. "wrappers.proto",
  475. ],
  476. visibility = ["//:__subpackages__"],
  477. )
  478. filegroup(
  479. name = "descriptor_proto_srcs",
  480. srcs = ["descriptor.proto"],
  481. visibility = ["//:__subpackages__"],
  482. )
  483. filegroup(
  484. name = "testdata",
  485. srcs = glob(["testdata/**/*"]) + [
  486. "descriptor.cc",
  487. ],
  488. visibility = [
  489. "//:__subpackages__",
  490. "@upb//:__subpackages__",
  491. ],
  492. )
  493. filegroup(
  494. name = "lite_test_proto_srcs",
  495. srcs = [
  496. "map_lite_unittest.proto",
  497. "unittest_import_lite.proto",
  498. "unittest_import_public_lite.proto",
  499. "unittest_lite.proto",
  500. ],
  501. visibility = ["//:__subpackages__"],
  502. )
  503. proto_library(
  504. name = "lite_test_protos",
  505. srcs = [":lite_test_proto_srcs"],
  506. strip_import_prefix = "/src",
  507. visibility = ["//:__subpackages__"],
  508. deps = [
  509. ":any_proto",
  510. ":api_proto",
  511. ":descriptor_proto",
  512. ":duration_proto",
  513. ":empty_proto",
  514. ":field_mask_proto",
  515. ":source_context_proto",
  516. ":struct_proto",
  517. ":timestamp_proto",
  518. ":type_proto",
  519. ":wrappers_proto",
  520. ],
  521. )
  522. filegroup(
  523. name = "test_proto_srcs",
  524. srcs = [
  525. "any_test.proto",
  526. "map_proto2_unittest.proto",
  527. "map_unittest.proto",
  528. "unittest.proto",
  529. "unittest_arena.proto",
  530. "unittest_custom_options.proto",
  531. "unittest_drop_unknown_fields.proto",
  532. "unittest_embed_optimize_for.proto",
  533. "unittest_empty.proto",
  534. "unittest_enormous_descriptor.proto",
  535. "unittest_import.proto",
  536. "unittest_import_public.proto",
  537. "unittest_lazy_dependencies.proto",
  538. "unittest_lazy_dependencies_custom_option.proto",
  539. "unittest_lazy_dependencies_enum.proto",
  540. "unittest_lite_imports_nonlite.proto",
  541. "unittest_mset.proto",
  542. "unittest_mset_wire_format.proto",
  543. "unittest_no_field_presence.proto",
  544. "unittest_no_generic_services.proto",
  545. "unittest_optimize_for.proto",
  546. "unittest_preserve_unknown_enum.proto",
  547. "unittest_preserve_unknown_enum2.proto",
  548. "unittest_proto3.proto",
  549. "unittest_proto3_arena.proto",
  550. "unittest_proto3_arena_lite.proto",
  551. "unittest_proto3_lite.proto",
  552. "unittest_proto3_optional.proto",
  553. "unittest_retention.proto",
  554. "unittest_well_known_types.proto",
  555. ],
  556. visibility = ["//:__subpackages__"],
  557. )
  558. proto_library(
  559. name = "test_protos",
  560. srcs = [":test_proto_srcs"],
  561. strip_import_prefix = "/src",
  562. visibility = ["//:__subpackages__"],
  563. deps = [
  564. ":any_proto",
  565. ":api_proto",
  566. ":descriptor_proto",
  567. ":duration_proto",
  568. ":empty_proto",
  569. ":field_mask_proto",
  570. ":source_context_proto",
  571. ":struct_proto",
  572. ":timestamp_proto",
  573. ":type_proto",
  574. ":wrappers_proto",
  575. ],
  576. )
  577. proto_library(
  578. name = "generic_test_protos",
  579. srcs = [
  580. "map_proto2_unittest.proto",
  581. "map_unittest.proto",
  582. "unittest.proto",
  583. "unittest_arena.proto",
  584. "unittest_custom_options.proto",
  585. "unittest_drop_unknown_fields.proto",
  586. "unittest_embed_optimize_for.proto",
  587. "unittest_empty.proto",
  588. "unittest_enormous_descriptor.proto",
  589. "unittest_import.proto",
  590. "unittest_import_public.proto",
  591. "unittest_lazy_dependencies.proto",
  592. "unittest_lazy_dependencies_custom_option.proto",
  593. "unittest_lazy_dependencies_enum.proto",
  594. "unittest_lite_imports_nonlite.proto",
  595. "unittest_mset.proto",
  596. "unittest_mset_wire_format.proto",
  597. "unittest_no_field_presence.proto",
  598. "unittest_no_generic_services.proto",
  599. "unittest_optimize_for.proto",
  600. "unittest_preserve_unknown_enum.proto",
  601. "unittest_preserve_unknown_enum2.proto",
  602. "unittest_proto3.proto",
  603. "unittest_proto3_arena.proto",
  604. "unittest_proto3_arena_lite.proto",
  605. "unittest_proto3_lite.proto",
  606. "unittest_proto3_optional.proto",
  607. "unittest_retention.proto",
  608. "unittest_well_known_types.proto",
  609. ],
  610. strip_import_prefix = "/src",
  611. visibility = ["//:__subpackages__"],
  612. deps = [
  613. ":any_proto",
  614. ":api_proto",
  615. ":descriptor_proto",
  616. ":duration_proto",
  617. ":empty_proto",
  618. ":field_mask_proto",
  619. ":source_context_proto",
  620. ":struct_proto",
  621. ":timestamp_proto",
  622. ":type_proto",
  623. ":wrappers_proto",
  624. ],
  625. )
  626. exports_files(
  627. [
  628. "test_messages_proto2.proto",
  629. "test_messages_proto3.proto",
  630. ],
  631. visibility = [
  632. "//:__pkg__",
  633. "//python:__pkg__",
  634. ],
  635. )
  636. proto_library(
  637. name = "test_messages_proto2_proto",
  638. srcs = ["test_messages_proto2.proto"],
  639. strip_import_prefix = "/src",
  640. visibility = [
  641. "//:__pkg__",
  642. "//conformance:__pkg__",
  643. "@upb//:__subpackages__",
  644. ],
  645. )
  646. proto_library(
  647. name = "test_messages_proto3_proto",
  648. srcs = ["test_messages_proto3.proto"],
  649. strip_import_prefix = "/src",
  650. visibility = [
  651. "//:__pkg__",
  652. "//conformance:__pkg__",
  653. "@upb//:__subpackages__",
  654. ],
  655. deps = [
  656. ":any_proto",
  657. ":duration_proto",
  658. ":field_mask_proto",
  659. ":struct_proto",
  660. ":timestamp_proto",
  661. ":wrappers_proto",
  662. ],
  663. )
  664. cc_proto_library(
  665. name = "cc_lite_test_protos",
  666. deps = [":lite_test_protos"],
  667. )
  668. cc_proto_library(
  669. name = "cc_test_protos",
  670. visibility = ["//src/google/protobuf:__subpackages__"],
  671. deps = [":test_protos"],
  672. )
  673. # Filegroup for golden comparison test:
  674. filegroup(
  675. name = "descriptor_cc_srcs",
  676. testonly = 1,
  677. data = [
  678. "descriptor.pb.cc",
  679. "descriptor.pb.h",
  680. ],
  681. visibility = ["//src/google/protobuf/compiler/cpp:__pkg__"],
  682. )
  683. cc_library(
  684. name = "lite_test_util",
  685. testonly = 1,
  686. srcs = [
  687. "arena_test_util.cc",
  688. "map_lite_test_util.cc",
  689. "test_util_lite.cc",
  690. ],
  691. hdrs = [
  692. "arena_test_util.h",
  693. "map_lite_test_util.h",
  694. "map_test_util_impl.h",
  695. "proto3_lite_unittest.inc",
  696. "test_util_lite.h",
  697. ],
  698. strip_include_prefix = "/src",
  699. visibility = ["//:__subpackages__"],
  700. deps = [
  701. ":cc_lite_test_protos",
  702. ":test_util2",
  703. "@com_google_absl//absl/log:absl_check",
  704. "@com_google_googletest//:gtest",
  705. ],
  706. )
  707. cc_library(
  708. name = "test_util",
  709. testonly = 1,
  710. srcs = [
  711. "reflection_tester.cc",
  712. "test_util.cc",
  713. ],
  714. hdrs = [
  715. "map_test.inc",
  716. "map_test_util.h",
  717. "map_test_util.inc",
  718. "message_unittest.inc",
  719. "reflection_tester.h",
  720. "test_util.h",
  721. "test_util.inc",
  722. "test_util_lite.h",
  723. "wire_format_unittest.inc",
  724. ],
  725. copts = COPTS + select({
  726. "//build_defs:config_msvc": [],
  727. "//conditions:default": [
  728. "-Wno-error=sign-compare",
  729. ],
  730. }),
  731. strip_include_prefix = "/src",
  732. visibility = ["//:__subpackages__"],
  733. deps = [
  734. ":cc_lite_test_protos",
  735. ":cc_test_protos",
  736. ":lite_test_util",
  737. "//src/google/protobuf/testing",
  738. "@com_google_absl//absl/container:flat_hash_map",
  739. "@com_google_absl//absl/log:absl_check",
  740. "@com_google_googletest//:gtest",
  741. ],
  742. )
  743. cc_library(
  744. name = "test_util2",
  745. testonly = 1,
  746. hdrs = ["test_util2.h"],
  747. strip_include_prefix = "/src",
  748. textual_hdrs = ["test_util.inc"],
  749. visibility = ["//:__subpackages__"],
  750. deps = [
  751. "//src/google/protobuf/io",
  752. "//src/google/protobuf/util:differencer",
  753. "@com_google_googletest//:gtest",
  754. ],
  755. )
  756. cc_test(
  757. name = "any_test",
  758. srcs = ["any_test.cc"],
  759. deps = [
  760. ":protobuf",
  761. ":test_util",
  762. "@com_google_absl//absl/log:absl_check",
  763. "@com_google_googletest//:gtest",
  764. "@com_google_googletest//:gtest_main",
  765. ],
  766. )
  767. cc_test(
  768. name = "arena_align_test",
  769. srcs = ["arena_align_test.cc"],
  770. copts = COPTS + select({
  771. "//build_defs:config_msvc": [],
  772. "//conditions:default": [
  773. "-Wno-error=sign-compare",
  774. ],
  775. }),
  776. deps = [
  777. ":arena_align",
  778. "@com_google_googletest//:gtest",
  779. "@com_google_googletest//:gtest_main",
  780. ],
  781. )
  782. cc_test(
  783. name = "arena_unittest",
  784. srcs = ["arena_unittest.cc"],
  785. copts = COPTS + select({
  786. "//build_defs:config_msvc": [],
  787. "//conditions:default": [
  788. "-Wno-error=sign-compare",
  789. ],
  790. }),
  791. deps = [
  792. ":cc_test_protos",
  793. ":lite_test_util",
  794. ":protobuf",
  795. ":test_util",
  796. "@com_google_googletest//:gtest",
  797. "@com_google_googletest//:gtest_main",
  798. ],
  799. )
  800. cc_test(
  801. name = "arenastring_unittest",
  802. srcs = ["arenastring_unittest.cc"],
  803. deps = [
  804. ":protobuf",
  805. "//src/google/protobuf/io",
  806. "//src/google/protobuf/stubs",
  807. "@com_google_googletest//:gtest",
  808. "@com_google_googletest//:gtest_main",
  809. ],
  810. )
  811. cc_test(
  812. name = "arenaz_sampler_test",
  813. srcs = ["arenaz_sampler_test.cc"],
  814. deps = [
  815. ":protobuf",
  816. "//src/google/protobuf/stubs",
  817. "@com_google_googletest//:gtest",
  818. "@com_google_googletest//:gtest_main",
  819. ],
  820. )
  821. cc_test(
  822. name = "descriptor_database_unittest",
  823. srcs = ["descriptor_database_unittest.cc"],
  824. deps = [
  825. ":protobuf",
  826. "//src/google/protobuf/testing",
  827. "@com_google_googletest//:gtest",
  828. "@com_google_googletest//:gtest_main",
  829. ],
  830. )
  831. cc_test(
  832. name = "descriptor_unittest",
  833. srcs = ["descriptor_unittest.cc"],
  834. copts = COPTS + select({
  835. "//build_defs:config_msvc": [],
  836. "//conditions:default": [
  837. "-Wno-error=sign-compare",
  838. ],
  839. }),
  840. deps = [
  841. ":cc_test_protos",
  842. ":protobuf",
  843. "//src/google/protobuf/compiler:importer",
  844. "//src/google/protobuf/testing",
  845. "@com_google_absl//absl/log:die_if_null",
  846. "@com_google_absl//absl/log:scoped_mock_log",
  847. "@com_google_absl//absl/strings:str_format",
  848. "@com_google_googletest//:gtest",
  849. "@com_google_googletest//:gtest_main",
  850. ],
  851. )
  852. cc_test(
  853. name = "drop_unknown_fields_test",
  854. srcs = ["drop_unknown_fields_test.cc"],
  855. deps = [
  856. ":cc_test_protos",
  857. ":protobuf",
  858. "@com_google_googletest//:gtest",
  859. "@com_google_googletest//:gtest_main",
  860. ],
  861. )
  862. cc_test(
  863. name = "dynamic_message_unittest",
  864. srcs = ["dynamic_message_unittest.cc"],
  865. copts = COPTS + select({
  866. "//build_defs:config_msvc": [],
  867. "//conditions:default": [
  868. "-Wno-error=sign-compare",
  869. ],
  870. }),
  871. deps = [
  872. ":cc_test_protos",
  873. ":protobuf",
  874. ":test_util",
  875. "//src/google/protobuf/stubs",
  876. "//src/google/protobuf/testing",
  877. "@com_google_googletest//:gtest",
  878. "@com_google_googletest//:gtest_main",
  879. ],
  880. )
  881. cc_test(
  882. name = "extension_set_unittest",
  883. srcs = ["extension_set_unittest.cc"],
  884. copts = COPTS + select({
  885. "//build_defs:config_msvc": [],
  886. "//conditions:default": [
  887. "-Wno-error=sign-compare",
  888. ],
  889. }),
  890. deps = [
  891. ":cc_test_protos",
  892. ":protobuf",
  893. ":test_util",
  894. ":test_util2",
  895. "//src/google/protobuf/io",
  896. "//src/google/protobuf/stubs",
  897. "//src/google/protobuf/testing",
  898. "//src/google/protobuf/util:differencer",
  899. "@com_google_googletest//:gtest",
  900. "@com_google_googletest//:gtest_main",
  901. ],
  902. )
  903. cc_test(
  904. name = "generated_message_reflection_unittest",
  905. srcs = ["generated_message_reflection_unittest.cc"],
  906. copts = COPTS + select({
  907. "//build_defs:config_msvc": [],
  908. "//conditions:default": [
  909. "-Wno-error=sign-compare",
  910. ],
  911. }),
  912. deps = [
  913. ":cc_test_protos",
  914. ":protobuf",
  915. ":test_util",
  916. "//src/google/protobuf/stubs",
  917. "//src/google/protobuf/testing",
  918. "@com_google_googletest//:gtest",
  919. "@com_google_googletest//:gtest_main",
  920. ],
  921. )
  922. cc_test(
  923. name = "generated_message_tctable_lite_test",
  924. srcs = ["generated_message_tctable_lite_test.cc"],
  925. copts = COPTS + select({
  926. "//build_defs:config_msvc": [],
  927. "//conditions:default": [
  928. "-Wno-error=sign-compare",
  929. ],
  930. }),
  931. deps = [
  932. ":protobuf_lite",
  933. "@com_google_googletest//:gtest",
  934. "@com_google_googletest//:gtest_main",
  935. ],
  936. )
  937. cc_test(
  938. name = "inlined_string_field_unittest",
  939. srcs = ["inlined_string_field_unittest.cc"],
  940. deps = [
  941. ":cc_test_protos",
  942. ":protobuf",
  943. "//src/google/protobuf/io",
  944. "//src/google/protobuf/stubs",
  945. "@com_google_googletest//:gtest",
  946. "@com_google_googletest//:gtest_main",
  947. ],
  948. )
  949. cc_test(
  950. name = "lite_arena_unittest",
  951. srcs = ["lite_arena_unittest.cc"],
  952. copts = COPTS + select({
  953. "//build_defs:config_msvc": [],
  954. "//conditions:default": [
  955. "-Wno-error=sign-compare",
  956. ],
  957. }),
  958. deps = [
  959. ":lite_test_util",
  960. ":protobuf",
  961. ":test_util",
  962. "@com_google_googletest//:gtest",
  963. "@com_google_googletest//:gtest_main",
  964. ],
  965. )
  966. cc_test(
  967. name = "lite_unittest",
  968. srcs = ["lite_unittest.cc"],
  969. deps = [
  970. ":cc_lite_test_protos",
  971. ":lite_test_util",
  972. ":protobuf",
  973. "//src/google/protobuf/io",
  974. "//src/google/protobuf/stubs",
  975. "@com_google_googletest//:gtest",
  976. "@com_google_googletest//:gtest_main",
  977. ],
  978. )
  979. cc_test(
  980. name = "map_field_test",
  981. srcs = ["map_field_test.cc"],
  982. deps = [
  983. ":cc_test_protos",
  984. ":protobuf",
  985. ":test_util",
  986. "//src/google/protobuf/stubs",
  987. "@com_google_absl//absl/container:flat_hash_map",
  988. "@com_google_absl//absl/strings:str_format",
  989. "@com_google_googletest//:gtest",
  990. "@com_google_googletest//:gtest_main",
  991. ],
  992. )
  993. cc_test(
  994. name = "map_test",
  995. timeout = "long",
  996. srcs = [
  997. "map_test.cc",
  998. "map_test.inc",
  999. ],
  1000. copts = COPTS + select({
  1001. "//build_defs:config_msvc": [],
  1002. "//conditions:default": [
  1003. "-Wno-deprecated-declarations",
  1004. ],
  1005. }),
  1006. data = [":testdata"],
  1007. deps = [
  1008. ":cc_test_protos",
  1009. ":protobuf",
  1010. ":test_util",
  1011. ":test_util2",
  1012. "//src/google/protobuf/util:differencer",
  1013. "//src/google/protobuf/util:time_util",
  1014. "@com_google_absl//absl/container:flat_hash_map",
  1015. "@com_google_absl//absl/container:flat_hash_set",
  1016. "@com_google_googletest//:gtest",
  1017. "@com_google_googletest//:gtest_main",
  1018. ],
  1019. )
  1020. cc_test(
  1021. name = "message_unittest",
  1022. srcs = [
  1023. "message_unittest.cc",
  1024. "message_unittest.inc",
  1025. ],
  1026. data = [":testdata"],
  1027. deps = [
  1028. ":cc_test_protos",
  1029. ":protobuf",
  1030. ":test_util",
  1031. "//src/google/protobuf/io",
  1032. "//src/google/protobuf/stubs",
  1033. "//src/google/protobuf/testing",
  1034. "//src/google/protobuf/util:differencer",
  1035. "@com_google_absl//absl/log:scoped_mock_log",
  1036. "@com_google_googletest//:gtest",
  1037. "@com_google_googletest//:gtest_main",
  1038. ],
  1039. )
  1040. cc_test(
  1041. name = "no_field_presence_test",
  1042. srcs = ["no_field_presence_test.cc"],
  1043. deps = [
  1044. ":cc_test_protos",
  1045. ":protobuf",
  1046. "@com_google_googletest//:gtest",
  1047. "@com_google_googletest//:gtest_main",
  1048. ],
  1049. )
  1050. cc_test(
  1051. name = "preserve_unknown_enum_test",
  1052. srcs = ["preserve_unknown_enum_test.cc"],
  1053. deps = [
  1054. ":cc_test_protos",
  1055. ":protobuf",
  1056. "@com_google_googletest//:gtest",
  1057. "@com_google_googletest//:gtest_main",
  1058. ],
  1059. )
  1060. cc_test(
  1061. name = "proto3_arena_lite_unittest",
  1062. srcs = ["proto3_arena_lite_unittest.cc"],
  1063. deps = [
  1064. ":cc_test_protos",
  1065. ":protobuf",
  1066. "//src/google/protobuf/testing",
  1067. "@com_google_googletest//:gtest",
  1068. "@com_google_googletest//:gtest_main",
  1069. ],
  1070. )
  1071. cc_test(
  1072. name = "proto3_arena_unittest",
  1073. srcs = ["proto3_arena_unittest.cc"],
  1074. copts = COPTS + select({
  1075. "//build_defs:config_msvc": [],
  1076. "//conditions:default": [
  1077. "-Wno-error=sign-compare",
  1078. ],
  1079. }),
  1080. deps = [
  1081. ":cc_test_protos",
  1082. ":protobuf",
  1083. ":test_util",
  1084. "//src/google/protobuf/stubs",
  1085. "//src/google/protobuf/testing",
  1086. "@com_google_googletest//:gtest",
  1087. "@com_google_googletest//:gtest_main",
  1088. ],
  1089. )
  1090. cc_test(
  1091. name = "proto3_lite_unittest",
  1092. srcs = [
  1093. "proto3_lite_unittest.cc",
  1094. "proto3_lite_unittest.inc",
  1095. ],
  1096. copts = COPTS + select({
  1097. "//build_defs:config_msvc": [],
  1098. "//conditions:default": [
  1099. "-Wno-deprecated-declarations",
  1100. ],
  1101. }),
  1102. deps = [
  1103. ":cc_test_protos",
  1104. ":lite_test_util",
  1105. ":protobuf",
  1106. "//src/google/protobuf/testing",
  1107. "@com_google_googletest//:gtest",
  1108. "@com_google_googletest//:gtest_main",
  1109. ],
  1110. )
  1111. cc_test(
  1112. name = "reflection_ops_unittest",
  1113. srcs = ["reflection_ops_unittest.cc"],
  1114. copts = COPTS + select({
  1115. "//build_defs:config_msvc": [],
  1116. "//conditions:default": [
  1117. "-Wno-error=sign-compare",
  1118. ],
  1119. }),
  1120. deps = [
  1121. ":cc_test_protos",
  1122. ":protobuf",
  1123. ":test_util",
  1124. "//src/google/protobuf/stubs",
  1125. "//src/google/protobuf/testing",
  1126. "@com_google_googletest//:gtest",
  1127. "@com_google_googletest//:gtest_main",
  1128. ],
  1129. )
  1130. cc_test(
  1131. name = "repeated_field_reflection_unittest",
  1132. srcs = ["repeated_field_reflection_unittest.cc"],
  1133. copts = COPTS + select({
  1134. "//build_defs:config_msvc": [],
  1135. "//conditions:default": [
  1136. "-Wno-deprecated-declarations",
  1137. ],
  1138. }),
  1139. deps = [
  1140. ":cc_test_protos",
  1141. ":protobuf",
  1142. ":test_util",
  1143. "//src/google/protobuf/stubs",
  1144. "@com_google_googletest//:gtest",
  1145. "@com_google_googletest//:gtest_main",
  1146. ],
  1147. )
  1148. cc_test(
  1149. name = "repeated_field_unittest",
  1150. srcs = ["repeated_field_unittest.cc"],
  1151. copts = COPTS + select({
  1152. "//build_defs:config_msvc": [],
  1153. "//conditions:default": [
  1154. "-Wno-deprecated-declarations",
  1155. ],
  1156. }),
  1157. deps = [
  1158. ":cc_test_protos",
  1159. ":protobuf",
  1160. "//src/google/protobuf/stubs",
  1161. "//src/google/protobuf/testing",
  1162. "@com_google_googletest//:gtest",
  1163. "@com_google_googletest//:gtest_main",
  1164. ],
  1165. )
  1166. cc_test(
  1167. name = "text_format_unittest",
  1168. srcs = ["text_format_unittest.cc"],
  1169. copts = COPTS + select({
  1170. "//build_defs:config_msvc": [],
  1171. "//conditions:default": [
  1172. "-Wno-deprecated-declarations",
  1173. ],
  1174. }),
  1175. data = [":testdata"],
  1176. deps = [
  1177. ":cc_test_protos",
  1178. ":protobuf",
  1179. ":test_util",
  1180. "//src/google/protobuf/io",
  1181. "//src/google/protobuf/stubs",
  1182. "//src/google/protobuf/testing",
  1183. "@com_google_absl//absl/log:die_if_null",
  1184. "@com_google_absl//absl/log:scoped_mock_log",
  1185. "@com_google_googletest//:gtest",
  1186. "@com_google_googletest//:gtest_main",
  1187. ],
  1188. )
  1189. cc_test(
  1190. name = "unknown_field_set_unittest",
  1191. srcs = ["unknown_field_set_unittest.cc"],
  1192. copts = COPTS + select({
  1193. "//build_defs:config_msvc": [],
  1194. "//conditions:default": [
  1195. "-Wno-error=sign-compare",
  1196. ],
  1197. }),
  1198. deps = [
  1199. ":cc_lite_test_protos",
  1200. ":protobuf",
  1201. ":test_util",
  1202. "//src/google/protobuf/io",
  1203. "//src/google/protobuf/stubs",
  1204. "//src/google/protobuf/testing",
  1205. "@com_google_absl//absl/synchronization",
  1206. "@com_google_googletest//:gtest",
  1207. "@com_google_googletest//:gtest_main",
  1208. ],
  1209. )
  1210. cc_test(
  1211. name = "well_known_types_unittest",
  1212. srcs = ["well_known_types_unittest.cc"],
  1213. copts = COPTS + select({
  1214. "//build_defs:config_msvc": [],
  1215. "//conditions:default": [
  1216. "-Wno-deprecated-declarations",
  1217. ],
  1218. }),
  1219. deps = [
  1220. ":cc_test_protos",
  1221. ":protobuf",
  1222. "//src/google/protobuf/stubs",
  1223. "//src/google/protobuf/testing",
  1224. "@com_google_googletest//:gtest",
  1225. "@com_google_googletest//:gtest_main",
  1226. ],
  1227. )
  1228. cc_test(
  1229. name = "wire_format_unittest",
  1230. srcs = [
  1231. "wire_format_unittest.cc",
  1232. "wire_format_unittest.inc",
  1233. ],
  1234. deps = [
  1235. ":cc_test_protos",
  1236. ":protobuf",
  1237. ":test_util",
  1238. ":test_util2",
  1239. "//src/google/protobuf/io",
  1240. "//src/google/protobuf/stubs",
  1241. "//src/google/protobuf/testing",
  1242. "//src/google/protobuf/util:differencer",
  1243. "@com_google_absl//absl/log:scoped_mock_log",
  1244. "@com_google_googletest//:gtest",
  1245. "@com_google_googletest//:gtest_main",
  1246. ],
  1247. )
  1248. cc_test(
  1249. name = "retention_test",
  1250. srcs = ["retention_test.cc"],
  1251. deps = [
  1252. ":cc_test_protos",
  1253. ":protobuf",
  1254. "//src/google/protobuf/compiler:importer",
  1255. "//src/google/protobuf/compiler:retention",
  1256. "//src/google/protobuf/util:differencer",
  1257. "@com_google_googletest//:gtest_main",
  1258. ],
  1259. )
  1260. ################################################################################
  1261. # Helper targets for Kotlin tests
  1262. ################################################################################
  1263. proto_library(
  1264. name = "kt_unittest_protos",
  1265. srcs = [
  1266. "map_proto2_unittest.proto",
  1267. "unittest.proto",
  1268. "unittest_import.proto",
  1269. "unittest_import_public.proto",
  1270. ],
  1271. strip_import_prefix = "/src",
  1272. visibility = ["//java/kotlin:__pkg__"],
  1273. )
  1274. proto_library(
  1275. name = "kt_proto3_unittest_protos",
  1276. srcs = [
  1277. "unittest_import.proto",
  1278. "unittest_import_public.proto",
  1279. "unittest_proto3.proto",
  1280. ],
  1281. strip_import_prefix = "/src",
  1282. visibility = [
  1283. "//java/kotlin:__pkg__",
  1284. "//java/kotlin-lite:__pkg__",
  1285. ],
  1286. )
  1287. ################################################################################
  1288. # Packaging rules
  1289. ################################################################################
  1290. pkg_files(
  1291. name = "dist_files",
  1292. srcs = glob(["**"]),
  1293. strip_prefix = strip_prefix.from_root(""),
  1294. visibility = ["//src:__pkg__"],
  1295. )
  1296. filegroup(
  1297. name = "full_test_srcs",
  1298. srcs = glob(
  1299. include = [
  1300. "*_test.cc",
  1301. "*unittest.cc",
  1302. ],
  1303. exclude = [
  1304. "lite_unittest.cc",
  1305. "lite_arena_unittest.cc",
  1306. ],
  1307. ),
  1308. visibility = ["//pkg:__pkg__"],
  1309. )
  1310. filegroup(
  1311. name = "lite_test_srcs",
  1312. srcs = [
  1313. "lite_arena_unittest.cc",
  1314. "lite_unittest.cc",
  1315. ],
  1316. visibility = ["//pkg:__pkg__"],
  1317. )