BUILD 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  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_pkg//:pkg.bzl", "pkg_zip")
  5. load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files")
  6. load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
  7. load("@rules_python//python:defs.bzl", "py_library")
  8. load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library")
  9. load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test")
  10. load(":protobuf_release.bzl", "package_naming")
  11. licenses(["notice"])
  12. exports_files(["LICENSE"])
  13. ################################################################################
  14. # build configuration
  15. ################################################################################
  16. ################################################################################
  17. # ZLIB configuration
  18. ################################################################################
  19. ZLIB_DEPS = ["@zlib//:zlib"]
  20. ################################################################################
  21. # Protobuf Runtime Library
  22. ################################################################################
  23. MSVC_COPTS = [
  24. "/wd4065", # switch statement contains 'default' but no 'case' labels
  25. "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data
  26. "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
  27. "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data
  28. "/wd4305", # 'identifier' : truncation from 'type1' to 'type2'
  29. "/wd4307", # 'operator' : integral constant overflow
  30. "/wd4309", # 'conversion' : truncation of constant value
  31. "/wd4334", # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
  32. "/wd4355", # 'this' : used in base member initializer list
  33. "/wd4506", # no definition for inline function '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_ZLIB",
  41. "-Woverloaded-virtual",
  42. "-Wno-sign-compare",
  43. ],
  44. })
  45. load(":compiler_config_setting.bzl", "create_compiler_config_setting")
  46. create_compiler_config_setting(
  47. name = "msvc",
  48. value = "msvc-cl",
  49. visibility = [
  50. # Public, but Protobuf only visibility.
  51. "//:__subpackages__",
  52. ],
  53. )
  54. # Android NDK builds can specify different crosstool_top flags to choose which
  55. # STL they use for C++. We need these multiple variants to catch all of those
  56. # versions of crosstool_top and reliably detect Android.
  57. #
  58. # For more info on the various crosstool_tops used by NDK Bazel builds, see:
  59. # https://docs.bazel.build/versions/master/android-ndk.html#configuring-the-stl
  60. config_setting(
  61. name = "android",
  62. values = {
  63. "crosstool_top": "//external:android/crosstool",
  64. },
  65. visibility = [
  66. # Public, but Protobuf only visibility.
  67. "//:__subpackages__",
  68. ],
  69. )
  70. config_setting(
  71. name = "android-stlport",
  72. values = {
  73. "crosstool_top": "@androidndk//:toolchain-stlport",
  74. },
  75. visibility = [
  76. # Public, but Protobuf only visibility.
  77. "//:__subpackages__",
  78. ],
  79. )
  80. config_setting(
  81. name = "android-libcpp",
  82. values = {
  83. "crosstool_top": "@androidndk//:toolchain-libcpp",
  84. },
  85. visibility = [
  86. # Public, but Protobuf only visibility.
  87. "//:__subpackages__",
  88. ],
  89. )
  90. config_setting(
  91. name = "android-gnu-libstdcpp",
  92. values = {
  93. "crosstool_top": "@androidndk//:toolchain-gnu-libstdcpp",
  94. },
  95. visibility = [
  96. # Public, but Protobuf only visibility.
  97. "//:__subpackages__",
  98. ],
  99. )
  100. config_setting(
  101. name = "android-default",
  102. values = {
  103. "crosstool_top": "@androidndk//:default_crosstool",
  104. },
  105. visibility = [
  106. # Public, but Protobuf only visibility.
  107. "//:__subpackages__",
  108. ],
  109. )
  110. # Android and MSVC builds do not need to link in a separate pthread library.
  111. LINK_OPTS = select({
  112. ":android": [],
  113. ":android-stlport": [],
  114. ":android-libcpp": [],
  115. ":android-gnu-libstdcpp": [],
  116. ":android-default": [],
  117. ":msvc": [
  118. # Suppress linker warnings about files with no symbols defined.
  119. "-ignore:4221",
  120. ],
  121. "//conditions:default": [
  122. "-lpthread",
  123. "-lm",
  124. ],
  125. })
  126. load(
  127. ":protobuf.bzl",
  128. "adapt_proto_library",
  129. "cc_proto_library",
  130. "internal_copied_filegroup",
  131. "internal_gen_kt_protos",
  132. "internal_gen_well_known_protos_java",
  133. "internal_protobuf_py_tests",
  134. "py_proto_library",
  135. )
  136. cc_library(
  137. name = "protobuf_lite",
  138. srcs = [
  139. # AUTOGEN(protobuf_lite_srcs)
  140. "src/google/protobuf/any_lite.cc",
  141. "src/google/protobuf/arena.cc",
  142. "src/google/protobuf/arenastring.cc",
  143. "src/google/protobuf/extension_set.cc",
  144. "src/google/protobuf/generated_enum_util.cc",
  145. "src/google/protobuf/generated_message_tctable_lite.cc",
  146. "src/google/protobuf/generated_message_util.cc",
  147. "src/google/protobuf/implicit_weak_message.cc",
  148. "src/google/protobuf/inlined_string_field.cc",
  149. "src/google/protobuf/io/coded_stream.cc",
  150. "src/google/protobuf/io/io_win32.cc",
  151. "src/google/protobuf/io/strtod.cc",
  152. "src/google/protobuf/io/zero_copy_stream.cc",
  153. "src/google/protobuf/io/zero_copy_stream_impl.cc",
  154. "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
  155. "src/google/protobuf/map.cc",
  156. "src/google/protobuf/message_lite.cc",
  157. "src/google/protobuf/parse_context.cc",
  158. "src/google/protobuf/repeated_field.cc",
  159. "src/google/protobuf/repeated_ptr_field.cc",
  160. "src/google/protobuf/stubs/bytestream.cc",
  161. "src/google/protobuf/stubs/common.cc",
  162. "src/google/protobuf/stubs/int128.cc",
  163. "src/google/protobuf/stubs/status.cc",
  164. "src/google/protobuf/stubs/statusor.cc",
  165. "src/google/protobuf/stubs/stringpiece.cc",
  166. "src/google/protobuf/stubs/stringprintf.cc",
  167. "src/google/protobuf/stubs/structurally_valid.cc",
  168. "src/google/protobuf/stubs/strutil.cc",
  169. "src/google/protobuf/stubs/time.cc",
  170. "src/google/protobuf/wire_format_lite.cc",
  171. ],
  172. hdrs = glob([
  173. "src/google/protobuf/**/*.h",
  174. "src/google/protobuf/**/*.inc",
  175. ]),
  176. copts = COPTS,
  177. includes = ["src/"],
  178. linkopts = LINK_OPTS,
  179. visibility = ["//visibility:public"],
  180. )
  181. PROTOBUF_DEPS = select({
  182. ":msvc": [],
  183. "//conditions:default": ZLIB_DEPS,
  184. })
  185. cc_library(
  186. name = "protobuf",
  187. srcs = [
  188. # AUTOGEN(protobuf_srcs)
  189. "src/google/protobuf/any.cc",
  190. "src/google/protobuf/any.pb.cc",
  191. "src/google/protobuf/api.pb.cc",
  192. "src/google/protobuf/compiler/importer.cc",
  193. "src/google/protobuf/compiler/parser.cc",
  194. "src/google/protobuf/descriptor.cc",
  195. "src/google/protobuf/descriptor.pb.cc",
  196. "src/google/protobuf/descriptor_database.cc",
  197. "src/google/protobuf/duration.pb.cc",
  198. "src/google/protobuf/dynamic_message.cc",
  199. "src/google/protobuf/empty.pb.cc",
  200. "src/google/protobuf/extension_set_heavy.cc",
  201. "src/google/protobuf/field_mask.pb.cc",
  202. "src/google/protobuf/generated_message_bases.cc",
  203. "src/google/protobuf/generated_message_reflection.cc",
  204. "src/google/protobuf/generated_message_tctable_full.cc",
  205. "src/google/protobuf/io/gzip_stream.cc",
  206. "src/google/protobuf/io/printer.cc",
  207. "src/google/protobuf/io/tokenizer.cc",
  208. "src/google/protobuf/map_field.cc",
  209. "src/google/protobuf/message.cc",
  210. "src/google/protobuf/reflection_ops.cc",
  211. "src/google/protobuf/service.cc",
  212. "src/google/protobuf/source_context.pb.cc",
  213. "src/google/protobuf/struct.pb.cc",
  214. "src/google/protobuf/stubs/substitute.cc",
  215. "src/google/protobuf/text_format.cc",
  216. "src/google/protobuf/timestamp.pb.cc",
  217. "src/google/protobuf/type.pb.cc",
  218. "src/google/protobuf/unknown_field_set.cc",
  219. "src/google/protobuf/util/delimited_message_util.cc",
  220. "src/google/protobuf/util/field_comparator.cc",
  221. "src/google/protobuf/util/field_mask_util.cc",
  222. "src/google/protobuf/util/internal/datapiece.cc",
  223. "src/google/protobuf/util/internal/default_value_objectwriter.cc",
  224. "src/google/protobuf/util/internal/error_listener.cc",
  225. "src/google/protobuf/util/internal/field_mask_utility.cc",
  226. "src/google/protobuf/util/internal/json_escaping.cc",
  227. "src/google/protobuf/util/internal/json_objectwriter.cc",
  228. "src/google/protobuf/util/internal/json_stream_parser.cc",
  229. "src/google/protobuf/util/internal/object_writer.cc",
  230. "src/google/protobuf/util/internal/proto_writer.cc",
  231. "src/google/protobuf/util/internal/protostream_objectsource.cc",
  232. "src/google/protobuf/util/internal/protostream_objectwriter.cc",
  233. "src/google/protobuf/util/internal/type_info.cc",
  234. "src/google/protobuf/util/internal/utility.cc",
  235. "src/google/protobuf/util/json_util.cc",
  236. "src/google/protobuf/util/message_differencer.cc",
  237. "src/google/protobuf/util/time_util.cc",
  238. "src/google/protobuf/util/type_resolver_util.cc",
  239. "src/google/protobuf/wire_format.cc",
  240. "src/google/protobuf/wrappers.pb.cc",
  241. ],
  242. hdrs = glob([
  243. "src/**/*.h",
  244. "src/**/*.inc",
  245. ]),
  246. copts = COPTS,
  247. includes = ["src/"],
  248. linkopts = LINK_OPTS,
  249. visibility = ["//visibility:public"],
  250. deps = [":protobuf_lite"] + PROTOBUF_DEPS,
  251. )
  252. # This provides just the header files for use in projects that need to build
  253. # shared libraries for dynamic loading. This target is available until Bazel
  254. # adds native support for such use cases.
  255. # TODO(keveman): Remove this target once the support gets added to Bazel.
  256. cc_library(
  257. name = "protobuf_headers",
  258. hdrs = glob([
  259. "src/**/*.h",
  260. "src/**/*.inc",
  261. ]),
  262. includes = ["src/"],
  263. visibility = ["//visibility:public"],
  264. )
  265. # Map of all well known protos.
  266. # name => (include path, imports)
  267. WELL_KNOWN_PROTO_MAP = {
  268. "any": ("src/google/protobuf/any.proto", []),
  269. "api": (
  270. "src/google/protobuf/api.proto",
  271. [
  272. "source_context",
  273. "type",
  274. ],
  275. ),
  276. "compiler_plugin": (
  277. "src/google/protobuf/compiler/plugin.proto",
  278. ["descriptor"],
  279. ),
  280. "descriptor": ("src/google/protobuf/descriptor.proto", []),
  281. "duration": ("src/google/protobuf/duration.proto", []),
  282. "empty": ("src/google/protobuf/empty.proto", []),
  283. "field_mask": ("src/google/protobuf/field_mask.proto", []),
  284. "source_context": ("src/google/protobuf/source_context.proto", []),
  285. "struct": ("src/google/protobuf/struct.proto", []),
  286. "timestamp": ("src/google/protobuf/timestamp.proto", []),
  287. "type": (
  288. "src/google/protobuf/type.proto",
  289. [
  290. "any",
  291. "source_context",
  292. ],
  293. ),
  294. "wrappers": ("src/google/protobuf/wrappers.proto", []),
  295. }
  296. WELL_KNOWN_PROTOS = [value[0] for value in WELL_KNOWN_PROTO_MAP.values()]
  297. LITE_WELL_KNOWN_PROTO_MAP = {
  298. "any": ("src/google/protobuf/any.proto", []),
  299. "api": (
  300. "src/google/protobuf/api.proto",
  301. [
  302. "source_context",
  303. "type",
  304. ],
  305. ),
  306. "duration": ("src/google/protobuf/duration.proto", []),
  307. "empty": ("src/google/protobuf/empty.proto", []),
  308. "field_mask": ("src/google/protobuf/field_mask.proto", []),
  309. "source_context": ("src/google/protobuf/source_context.proto", []),
  310. "struct": ("src/google/protobuf/struct.proto", []),
  311. "timestamp": ("src/google/protobuf/timestamp.proto", []),
  312. "type": (
  313. "src/google/protobuf/type.proto",
  314. [
  315. "any",
  316. "source_context",
  317. ],
  318. ),
  319. "wrappers": ("src/google/protobuf/wrappers.proto", []),
  320. }
  321. LITE_WELL_KNOWN_PROTOS = [value[0] for value in LITE_WELL_KNOWN_PROTO_MAP.values()]
  322. filegroup(
  323. name = "well_known_protos",
  324. srcs = WELL_KNOWN_PROTOS,
  325. visibility = ["//visibility:public"],
  326. )
  327. filegroup(
  328. name = "lite_well_known_protos",
  329. srcs = LITE_WELL_KNOWN_PROTOS,
  330. visibility = ["//visibility:public"],
  331. )
  332. adapt_proto_library(
  333. name = "cc_wkt_protos_genproto",
  334. visibility = ["//visibility:public"],
  335. deps = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
  336. )
  337. cc_library(
  338. name = "cc_wkt_protos",
  339. deprecation = "Only for backward compatibility. Do not use.",
  340. visibility = ["//visibility:public"],
  341. )
  342. ################################################################################
  343. # Well Known Types Proto Library Rules
  344. #
  345. # These proto_library rules can be used with one of the language specific proto
  346. # library rules i.e. java_proto_library:
  347. #
  348. # java_proto_library(
  349. # name = "any_java_proto",
  350. # deps = ["@com_google_protobuf//:any_proto],
  351. # )
  352. ################################################################################
  353. [proto_library(
  354. name = proto[0] + "_proto",
  355. srcs = [proto[1][0]],
  356. strip_import_prefix = "src",
  357. visibility = ["//visibility:public"],
  358. deps = [dep + "_proto" for dep in proto[1][1]],
  359. ) for proto in WELL_KNOWN_PROTO_MAP.items()]
  360. [native_cc_proto_library(
  361. name = proto + "_cc_proto",
  362. visibility = ["//visibility:private"],
  363. deps = [proto + "_proto"],
  364. ) for proto in WELL_KNOWN_PROTO_MAP.keys()]
  365. cc_proto_blacklist_test(
  366. name = "cc_proto_blacklist_test",
  367. tags = [
  368. # Exclude this target from wildcard expansion (//...). Due to
  369. # https://github.com/bazelbuild/bazel/issues/10590, this test has to
  370. # be nominated using the `@com_google_protobuf//` prefix. We do that,
  371. # e.g., in kokoro/linux/bazel/build.sh.
  372. # See also https://github.com/protocolbuffers/protobuf/pull/7096.
  373. "manual",
  374. ],
  375. deps = [proto + "_cc_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
  376. )
  377. ################################################################################
  378. # Protocol Buffers Compiler
  379. ################################################################################
  380. cc_library(
  381. name = "protoc_lib",
  382. srcs = [
  383. # AUTOGEN(protoc_lib_srcs)
  384. "src/google/protobuf/compiler/code_generator.cc",
  385. "src/google/protobuf/compiler/command_line_interface.cc",
  386. "src/google/protobuf/compiler/cpp/cpp_enum.cc",
  387. "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
  388. "src/google/protobuf/compiler/cpp/cpp_extension.cc",
  389. "src/google/protobuf/compiler/cpp/cpp_field.cc",
  390. "src/google/protobuf/compiler/cpp/cpp_file.cc",
  391. "src/google/protobuf/compiler/cpp/cpp_generator.cc",
  392. "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
  393. "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
  394. "src/google/protobuf/compiler/cpp/cpp_message.cc",
  395. "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
  396. "src/google/protobuf/compiler/cpp/cpp_padding_optimizer.cc",
  397. "src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc",
  398. "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
  399. "src/google/protobuf/compiler/cpp/cpp_service.cc",
  400. "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
  401. "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
  402. "src/google/protobuf/compiler/csharp/csharp_enum.cc",
  403. "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
  404. "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
  405. "src/google/protobuf/compiler/csharp/csharp_generator.cc",
  406. "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
  407. "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
  408. "src/google/protobuf/compiler/csharp/csharp_message.cc",
  409. "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
  410. "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
  411. "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
  412. "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
  413. "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
  414. "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
  415. "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
  416. "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
  417. "src/google/protobuf/compiler/java/java_context.cc",
  418. "src/google/protobuf/compiler/java/java_doc_comment.cc",
  419. "src/google/protobuf/compiler/java/java_enum.cc",
  420. "src/google/protobuf/compiler/java/java_enum_field.cc",
  421. "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
  422. "src/google/protobuf/compiler/java/java_enum_lite.cc",
  423. "src/google/protobuf/compiler/java/java_extension.cc",
  424. "src/google/protobuf/compiler/java/java_extension_lite.cc",
  425. "src/google/protobuf/compiler/java/java_field.cc",
  426. "src/google/protobuf/compiler/java/java_file.cc",
  427. "src/google/protobuf/compiler/java/java_generator.cc",
  428. "src/google/protobuf/compiler/java/java_generator_factory.cc",
  429. "src/google/protobuf/compiler/java/java_helpers.cc",
  430. "src/google/protobuf/compiler/java/java_kotlin_generator.cc",
  431. "src/google/protobuf/compiler/java/java_map_field.cc",
  432. "src/google/protobuf/compiler/java/java_map_field_lite.cc",
  433. "src/google/protobuf/compiler/java/java_message.cc",
  434. "src/google/protobuf/compiler/java/java_message_builder.cc",
  435. "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
  436. "src/google/protobuf/compiler/java/java_message_field.cc",
  437. "src/google/protobuf/compiler/java/java_message_field_lite.cc",
  438. "src/google/protobuf/compiler/java/java_message_lite.cc",
  439. "src/google/protobuf/compiler/java/java_name_resolver.cc",
  440. "src/google/protobuf/compiler/java/java_primitive_field.cc",
  441. "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
  442. "src/google/protobuf/compiler/java/java_service.cc",
  443. "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
  444. "src/google/protobuf/compiler/java/java_string_field.cc",
  445. "src/google/protobuf/compiler/java/java_string_field_lite.cc",
  446. "src/google/protobuf/compiler/js/js_generator.cc",
  447. "src/google/protobuf/compiler/js/well_known_types_embed.cc",
  448. "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
  449. "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
  450. "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
  451. "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
  452. "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
  453. "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
  454. "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
  455. "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
  456. "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
  457. "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
  458. "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
  459. "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
  460. "src/google/protobuf/compiler/php/php_generator.cc",
  461. "src/google/protobuf/compiler/plugin.cc",
  462. "src/google/protobuf/compiler/plugin.pb.cc",
  463. "src/google/protobuf/compiler/python/python_generator.cc",
  464. "src/google/protobuf/compiler/python/python_helpers.cc",
  465. "src/google/protobuf/compiler/python/python_pyi_generator.cc",
  466. "src/google/protobuf/compiler/ruby/ruby_generator.cc",
  467. "src/google/protobuf/compiler/subprocess.cc",
  468. "src/google/protobuf/compiler/zip_writer.cc",
  469. ],
  470. copts = COPTS,
  471. includes = ["src/"],
  472. linkopts = LINK_OPTS,
  473. visibility = ["//visibility:public"],
  474. deps = [":protobuf"],
  475. )
  476. cc_binary(
  477. name = "protoc",
  478. srcs = ["src/google/protobuf/compiler/main.cc"],
  479. linkopts = LINK_OPTS,
  480. visibility = ["//visibility:public"],
  481. deps = [":protoc_lib"],
  482. )
  483. ################################################################################
  484. # Generates protoc release artifacts.
  485. ################################################################################
  486. genrule(
  487. name = "protoc_readme",
  488. visibility = ["//visibility:private"],
  489. cmd = """
  490. echo "Protocol Buffers - Google's data interchange format
  491. Copyright 2008 Google Inc.
  492. https://developers.google.com/protocol-buffers/
  493. This package contains a precompiled binary version of the protocol buffer
  494. compiler (protoc). This binary is intended for users who want to use Protocol
  495. Buffers in languages other than C++ but do not want to compile protoc
  496. themselves. To install, simply place this binary somewhere in your PATH.
  497. If you intend to use the included well known types then don't forget to
  498. copy the contents of the 'include' directory somewhere as well, for example
  499. into '/usr/local/include/'.
  500. Please refer to our official github site for more installation instructions:
  501. https://github.com/protocolbuffers/protobuf" > $@
  502. """,
  503. outs = ["readme.txt"],
  504. )
  505. # plugin.proto is excluded from this list because it belongs in a nested folder (protobuf/compiler/plugin.proto)
  506. pkg_files(
  507. name = "wkt_protos_files",
  508. srcs = [value[0] for value in WELL_KNOWN_PROTO_MAP.values() if not value[0].endswith("plugin.proto")],
  509. visibility = ["//visibility:private"],
  510. prefix = "include/google/protobuf",
  511. )
  512. pkg_files(
  513. name = "compiler_plugin_protos_files",
  514. srcs = ["src/google/protobuf/compiler/plugin.proto"],
  515. visibility = ["//visibility:private"],
  516. prefix = "include/google/protobuf/compiler",
  517. )
  518. pkg_files(
  519. name = "protoc_files",
  520. srcs = [":protoc"],
  521. attributes = pkg_attributes(mode = "0555"),
  522. visibility = ["//visibility:private"],
  523. prefix = "bin/",
  524. )
  525. package_naming(
  526. name = "protoc_pkg_naming",
  527. )
  528. pkg_zip(
  529. name = "protoc_release",
  530. package_file_name = "protoc-{version}-{platform}.zip",
  531. package_variables = ":protoc_pkg_naming",
  532. srcs = [
  533. ":protoc_files",
  534. ":wkt_protos_files",
  535. ":compiler_plugin_protos_files",
  536. "readme.txt",
  537. ],
  538. )
  539. ################################################################################
  540. # Tests
  541. ################################################################################
  542. filegroup(
  543. name = "testdata",
  544. srcs = glob(["src/google/protobuf/testdata/**/*"]),
  545. visibility = ["//:__subpackages__"],
  546. )
  547. RELATIVE_LITE_TEST_PROTOS = [
  548. # AUTOGEN(lite_test_protos)
  549. "google/protobuf/map_lite_unittest.proto",
  550. "google/protobuf/unittest_import_lite.proto",
  551. "google/protobuf/unittest_import_public_lite.proto",
  552. "google/protobuf/unittest_lite.proto",
  553. ]
  554. LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
  555. RELATIVE_TEST_PROTOS = [
  556. # AUTOGEN(test_protos)
  557. "google/protobuf/any_test.proto",
  558. "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
  559. "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
  560. "google/protobuf/map_proto2_unittest.proto",
  561. "google/protobuf/map_unittest.proto",
  562. "google/protobuf/unittest.proto",
  563. "google/protobuf/unittest_arena.proto",
  564. "google/protobuf/unittest_custom_options.proto",
  565. "google/protobuf/unittest_drop_unknown_fields.proto",
  566. "google/protobuf/unittest_embed_optimize_for.proto",
  567. "google/protobuf/unittest_empty.proto",
  568. "google/protobuf/unittest_enormous_descriptor.proto",
  569. "google/protobuf/unittest_import.proto",
  570. "google/protobuf/unittest_import_public.proto",
  571. "google/protobuf/unittest_lazy_dependencies.proto",
  572. "google/protobuf/unittest_lazy_dependencies_custom_option.proto",
  573. "google/protobuf/unittest_lazy_dependencies_enum.proto",
  574. "google/protobuf/unittest_lite_imports_nonlite.proto",
  575. "google/protobuf/unittest_mset.proto",
  576. "google/protobuf/unittest_mset_wire_format.proto",
  577. "google/protobuf/unittest_no_field_presence.proto",
  578. "google/protobuf/unittest_no_generic_services.proto",
  579. "google/protobuf/unittest_optimize_for.proto",
  580. "google/protobuf/unittest_preserve_unknown_enum.proto",
  581. "google/protobuf/unittest_preserve_unknown_enum2.proto",
  582. "google/protobuf/unittest_proto3.proto",
  583. "google/protobuf/unittest_proto3_arena.proto",
  584. "google/protobuf/unittest_proto3_arena_lite.proto",
  585. "google/protobuf/unittest_proto3_lite.proto",
  586. "google/protobuf/unittest_proto3_optional.proto",
  587. "google/protobuf/unittest_well_known_types.proto",
  588. "google/protobuf/util/internal/testdata/anys.proto",
  589. "google/protobuf/util/internal/testdata/books.proto",
  590. "google/protobuf/util/internal/testdata/default_value.proto",
  591. "google/protobuf/util/internal/testdata/default_value_test.proto",
  592. "google/protobuf/util/internal/testdata/field_mask.proto",
  593. "google/protobuf/util/internal/testdata/maps.proto",
  594. "google/protobuf/util/internal/testdata/oneofs.proto",
  595. "google/protobuf/util/internal/testdata/proto3.proto",
  596. "google/protobuf/util/internal/testdata/struct.proto",
  597. "google/protobuf/util/internal/testdata/timestamp_duration.proto",
  598. "google/protobuf/util/internal/testdata/wrappers.proto",
  599. "google/protobuf/util/json_format.proto",
  600. "google/protobuf/util/json_format_proto3.proto",
  601. "google/protobuf/util/message_differencer_unittest.proto",
  602. ]
  603. TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
  604. GENERIC_RELATIVE_TEST_PROTOS = [
  605. "google/protobuf/map_proto2_unittest.proto",
  606. "google/protobuf/map_unittest.proto",
  607. "google/protobuf/unittest.proto",
  608. "google/protobuf/unittest_arena.proto",
  609. "google/protobuf/unittest_custom_options.proto",
  610. "google/protobuf/unittest_drop_unknown_fields.proto",
  611. "google/protobuf/unittest_embed_optimize_for.proto",
  612. "google/protobuf/unittest_empty.proto",
  613. "google/protobuf/unittest_enormous_descriptor.proto",
  614. "google/protobuf/unittest_import.proto",
  615. "google/protobuf/unittest_import_public.proto",
  616. "google/protobuf/unittest_lazy_dependencies.proto",
  617. "google/protobuf/unittest_lazy_dependencies_custom_option.proto",
  618. "google/protobuf/unittest_lazy_dependencies_enum.proto",
  619. "google/protobuf/unittest_lite_imports_nonlite.proto",
  620. "google/protobuf/unittest_mset.proto",
  621. "google/protobuf/unittest_mset_wire_format.proto",
  622. "google/protobuf/unittest_no_field_presence.proto",
  623. "google/protobuf/unittest_no_generic_services.proto",
  624. "google/protobuf/unittest_optimize_for.proto",
  625. "google/protobuf/unittest_preserve_unknown_enum.proto",
  626. "google/protobuf/unittest_preserve_unknown_enum2.proto",
  627. "google/protobuf/unittest_proto3.proto",
  628. "google/protobuf/unittest_proto3_arena.proto",
  629. "google/protobuf/unittest_proto3_arena_lite.proto",
  630. "google/protobuf/unittest_proto3_lite.proto",
  631. "google/protobuf/unittest_proto3_optional.proto",
  632. "google/protobuf/unittest_well_known_types.proto",
  633. ]
  634. GENERIC_TEST_PROTOS = ["src/" + s for s in GENERIC_RELATIVE_TEST_PROTOS]
  635. proto_library(
  636. name = "generic_test_protos",
  637. srcs = LITE_TEST_PROTOS + GENERIC_TEST_PROTOS,
  638. strip_import_prefix = "src",
  639. visibility = ["//:__subpackages__"],
  640. deps = [
  641. "//:any_proto",
  642. "//:api_proto",
  643. "//:descriptor_proto",
  644. "//:duration_proto",
  645. "//:empty_proto",
  646. "//:field_mask_proto",
  647. "//:source_context_proto",
  648. "//:struct_proto",
  649. "//:timestamp_proto",
  650. "//:type_proto",
  651. "//:wrappers_proto",
  652. ],
  653. )
  654. cc_proto_library(
  655. name = "cc_test_protos",
  656. srcs = LITE_TEST_PROTOS + TEST_PROTOS,
  657. include = "src",
  658. default_runtime = ":protobuf",
  659. protoc = ":protoc",
  660. deps = [":cc_wkt_protos"],
  661. )
  662. COMMON_TEST_SRCS = [
  663. # AUTOGEN(common_test_srcs)
  664. "src/google/protobuf/arena_test_util.cc",
  665. "src/google/protobuf/map_lite_test_util.cc",
  666. "src/google/protobuf/test_util_lite.cc",
  667. "src/google/protobuf/map_test_util.inc",
  668. "src/google/protobuf/reflection_tester.cc",
  669. "src/google/protobuf/test_util.cc",
  670. "src/google/protobuf/test_util.inc",
  671. "src/google/protobuf/testing/file.cc",
  672. "src/google/protobuf/testing/googletest.cc",
  673. ]
  674. cc_binary(
  675. name = "test_plugin",
  676. testonly = True,
  677. srcs = [
  678. # AUTOGEN(test_plugin_srcs)
  679. "src/google/protobuf/compiler/mock_code_generator.cc",
  680. "src/google/protobuf/compiler/test_plugin.cc",
  681. "src/google/protobuf/testing/file.cc",
  682. ],
  683. deps = [
  684. ":protobuf",
  685. ":protoc_lib",
  686. "@com_google_googletest//:gtest",
  687. ],
  688. )
  689. cc_test(
  690. name = "win32_test",
  691. srcs = ["src/google/protobuf/io/io_win32_unittest.cc"],
  692. tags = [
  693. "manual",
  694. "windows",
  695. ],
  696. deps = [
  697. ":protobuf_lite",
  698. "@com_google_googletest//:gtest",
  699. "@com_google_googletest//:gtest_main",
  700. ],
  701. )
  702. cc_test(
  703. name = "protobuf_test",
  704. srcs = COMMON_TEST_SRCS + [
  705. # AUTOGEN(test_srcs)
  706. "src/google/protobuf/any_test.cc",
  707. "src/google/protobuf/arena_unittest.cc",
  708. "src/google/protobuf/arenastring_unittest.cc",
  709. "src/google/protobuf/compiler/annotation_test_util.cc",
  710. "src/google/protobuf/compiler/command_line_interface_unittest.cc",
  711. "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
  712. "src/google/protobuf/compiler/cpp/cpp_move_unittest.cc",
  713. "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
  714. "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
  715. "src/google/protobuf/compiler/cpp/cpp_unittest.inc",
  716. "src/google/protobuf/compiler/cpp/metadata_test.cc",
  717. "src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc",
  718. "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
  719. "src/google/protobuf/compiler/importer_unittest.cc",
  720. "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
  721. "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
  722. "src/google/protobuf/compiler/mock_code_generator.cc",
  723. "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
  724. "src/google/protobuf/compiler/parser_unittest.cc",
  725. "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
  726. "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
  727. "src/google/protobuf/descriptor_database_unittest.cc",
  728. "src/google/protobuf/descriptor_unittest.cc",
  729. "src/google/protobuf/drop_unknown_fields_test.cc",
  730. "src/google/protobuf/dynamic_message_unittest.cc",
  731. "src/google/protobuf/extension_set_unittest.cc",
  732. "src/google/protobuf/generated_message_reflection_unittest.cc",
  733. "src/google/protobuf/inlined_string_field_unittest.cc",
  734. "src/google/protobuf/io/coded_stream_unittest.cc",
  735. "src/google/protobuf/io/io_win32_unittest.cc",
  736. "src/google/protobuf/io/printer_unittest.cc",
  737. "src/google/protobuf/io/tokenizer_unittest.cc",
  738. "src/google/protobuf/io/zero_copy_stream_unittest.cc",
  739. "src/google/protobuf/map_field_test.cc",
  740. "src/google/protobuf/map_test.cc",
  741. "src/google/protobuf/map_test.inc",
  742. "src/google/protobuf/message_unittest.cc",
  743. "src/google/protobuf/message_unittest.inc",
  744. "src/google/protobuf/no_field_presence_test.cc",
  745. "src/google/protobuf/preserve_unknown_enum_test.cc",
  746. "src/google/protobuf/proto3_arena_lite_unittest.cc",
  747. "src/google/protobuf/proto3_arena_unittest.cc",
  748. "src/google/protobuf/proto3_lite_unittest.cc",
  749. "src/google/protobuf/proto3_lite_unittest.inc",
  750. "src/google/protobuf/reflection_ops_unittest.cc",
  751. "src/google/protobuf/repeated_field_reflection_unittest.cc",
  752. "src/google/protobuf/repeated_field_unittest.cc",
  753. "src/google/protobuf/stubs/bytestream_unittest.cc",
  754. "src/google/protobuf/stubs/common_unittest.cc",
  755. "src/google/protobuf/stubs/int128_unittest.cc",
  756. "src/google/protobuf/stubs/status_test.cc",
  757. "src/google/protobuf/stubs/statusor_test.cc",
  758. "src/google/protobuf/stubs/stringpiece_unittest.cc",
  759. "src/google/protobuf/stubs/stringprintf_unittest.cc",
  760. "src/google/protobuf/stubs/structurally_valid_unittest.cc",
  761. "src/google/protobuf/stubs/strutil_unittest.cc",
  762. "src/google/protobuf/stubs/template_util_unittest.cc",
  763. "src/google/protobuf/stubs/time_test.cc",
  764. "src/google/protobuf/text_format_unittest.cc",
  765. "src/google/protobuf/unknown_field_set_unittest.cc",
  766. "src/google/protobuf/util/delimited_message_util_test.cc",
  767. "src/google/protobuf/util/field_comparator_test.cc",
  768. "src/google/protobuf/util/field_mask_util_test.cc",
  769. "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
  770. "src/google/protobuf/util/internal/json_objectwriter_test.cc",
  771. "src/google/protobuf/util/internal/json_stream_parser_test.cc",
  772. "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
  773. "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
  774. "src/google/protobuf/util/internal/type_info_test_helper.cc",
  775. "src/google/protobuf/util/json_util_test.cc",
  776. "src/google/protobuf/util/message_differencer_unittest.cc",
  777. "src/google/protobuf/util/time_util_test.cc",
  778. "src/google/protobuf/util/type_resolver_util_test.cc",
  779. "src/google/protobuf/well_known_types_unittest.cc",
  780. "src/google/protobuf/wire_format_unittest.cc",
  781. "src/google/protobuf/wire_format_unittest.inc",
  782. ] + select({
  783. "//conditions:default": [
  784. # AUTOGEN(non_msvc_test_srcs)
  785. ],
  786. ":msvc": [],
  787. }),
  788. copts = COPTS + select({
  789. ":msvc": [],
  790. "//conditions:default": [
  791. "-Wno-deprecated-declarations",
  792. ],
  793. }),
  794. data = [
  795. ":test_plugin",
  796. ] + glob([
  797. "src/google/protobuf/**/*",
  798. # Files for csharp_bootstrap_unittest.cc.
  799. "conformance/**/*",
  800. "csharp/src/**/*",
  801. ]),
  802. includes = [
  803. "src/",
  804. ],
  805. linkopts = LINK_OPTS,
  806. deps = [
  807. ":cc_test_protos",
  808. ":protobuf",
  809. ":protoc_lib",
  810. "@com_google_googletest//:gtest",
  811. "@com_google_googletest//:gtest_main",
  812. ] + PROTOBUF_DEPS,
  813. )
  814. ################################################################################
  815. # Java support
  816. ################################################################################
  817. internal_gen_well_known_protos_java(
  818. name = "gen_well_known_protos_java",
  819. visibility = [
  820. "//java:__subpackages__",
  821. ],
  822. deps = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
  823. )
  824. internal_gen_well_known_protos_java(
  825. name = "gen_well_known_protos_javalite",
  826. javalite = True,
  827. visibility = [
  828. "//java:__subpackages__",
  829. ],
  830. deps = [proto + "_proto" for proto in LITE_WELL_KNOWN_PROTO_MAP.keys()],
  831. )
  832. internal_gen_kt_protos(
  833. name = "gen_well_known_protos_kotlin",
  834. visibility = [
  835. "//java:__subpackages__",
  836. ],
  837. deps = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
  838. )
  839. internal_gen_kt_protos(
  840. name = "gen_well_known_protos_kotlinlite",
  841. visibility = [
  842. "//java:__subpackages__",
  843. ],
  844. lite = True,
  845. deps = [proto + "_proto" for proto in LITE_WELL_KNOWN_PROTO_MAP.keys()],
  846. )
  847. alias(
  848. name = "protobuf_java",
  849. actual = "//java/core",
  850. visibility = ["//visibility:public"],
  851. )
  852. alias(
  853. name = "protobuf_javalite",
  854. actual = "//java/lite",
  855. visibility = ["//visibility:public"],
  856. )
  857. alias(
  858. name = "protobuf_java_util",
  859. actual = "//java/util",
  860. visibility = ["//visibility:public"],
  861. )
  862. alias(
  863. name = "java_toolchain",
  864. actual = "//java/core:toolchain",
  865. visibility = ["//visibility:public"],
  866. )
  867. alias(
  868. name = "javalite_toolchain",
  869. actual = "//java/lite:toolchain",
  870. visibility = ["//visibility:public"],
  871. )
  872. ################################################################################
  873. # Python support
  874. ################################################################################
  875. py_library(
  876. name = "python_srcs",
  877. srcs = glob(
  878. [
  879. "python/google/protobuf/**/*.py",
  880. ],
  881. exclude = [
  882. "python/google/protobuf/internal/*_test.py",
  883. "python/google/protobuf/internal/test_util.py",
  884. ],
  885. ),
  886. imports = ["python"],
  887. srcs_version = "PY2AND3",
  888. )
  889. cc_binary(
  890. name = "python/google/protobuf/internal/_api_implementation.so",
  891. srcs = ["python/google/protobuf/internal/api_implementation.cc"],
  892. copts = COPTS + [
  893. "-DPYTHON_PROTO2_CPP_IMPL_V2",
  894. ],
  895. linkshared = 1,
  896. linkstatic = 1,
  897. tags = [
  898. # Exclude this target from wildcard expansion (//...) because it may
  899. # not even be buildable. It will be built if it is needed according
  900. # to :use_fast_cpp_protos.
  901. # https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes
  902. "manual",
  903. ],
  904. deps = select({
  905. "//conditions:default": [],
  906. ":use_fast_cpp_protos": ["//external:python_headers"],
  907. }),
  908. )
  909. cc_binary(
  910. name = "python/google/protobuf/pyext/_message.so",
  911. srcs = glob([
  912. "python/google/protobuf/pyext/*.cc",
  913. "python/google/protobuf/pyext/*.h",
  914. ]),
  915. copts = COPTS + [
  916. "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
  917. ] + select({
  918. "//conditions:default": [],
  919. ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
  920. }),
  921. includes = [
  922. "python/",
  923. "src/",
  924. ],
  925. linkshared = 1,
  926. linkstatic = 1,
  927. tags = [
  928. # Exclude this target from wildcard expansion (//...) because it may
  929. # not even be buildable. It will be built if it is needed according
  930. # to :use_fast_cpp_protos.
  931. # https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes
  932. "manual",
  933. ],
  934. deps = [
  935. ":protobuf",
  936. ":proto_api",
  937. ] + select({
  938. "//conditions:default": [],
  939. ":use_fast_cpp_protos": ["//external:python_headers"],
  940. }),
  941. )
  942. config_setting(
  943. name = "use_fast_cpp_protos",
  944. values = {
  945. "define": "use_fast_cpp_protos=true",
  946. },
  947. visibility = [
  948. # Public, but Protobuf only visibility.
  949. "//:__subpackages__",
  950. ],
  951. )
  952. config_setting(
  953. name = "allow_oversize_protos",
  954. values = {
  955. "define": "allow_oversize_protos=true",
  956. },
  957. visibility = [
  958. # Public, but Protobuf only visibility.
  959. "//:__subpackages__",
  960. ],
  961. )
  962. # Copy the builtin proto files from src/google/protobuf to
  963. # python/google/protobuf. This way, the generated Python sources will be in the
  964. # same directory as the Python runtime sources. This is necessary for the
  965. # modules to be imported correctly since they are all part of the same Python
  966. # package.
  967. internal_copied_filegroup(
  968. name = "protos_python",
  969. srcs = WELL_KNOWN_PROTOS,
  970. dest = "python",
  971. strip_prefix = "src",
  972. )
  973. # TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
  974. # which case we can simply add :protos_python in srcs.
  975. COPIED_WELL_KNOWN_PROTOS = ["python/" + s[4:] for s in WELL_KNOWN_PROTOS]
  976. py_proto_library(
  977. name = "protobuf_python",
  978. srcs = COPIED_WELL_KNOWN_PROTOS,
  979. include = "python",
  980. data = select({
  981. "//conditions:default": [],
  982. ":use_fast_cpp_protos": [
  983. ":python/google/protobuf/internal/_api_implementation.so",
  984. ":python/google/protobuf/pyext/_message.so",
  985. ],
  986. }),
  987. default_runtime = "",
  988. protoc = ":protoc",
  989. py_libs = [
  990. ":python_srcs",
  991. ],
  992. srcs_version = "PY2AND3",
  993. visibility = ["//visibility:public"],
  994. )
  995. # Copy the test proto files from src/google/protobuf to
  996. # python/google/protobuf. This way, the generated Python sources will be in the
  997. # same directory as the Python runtime sources. This is necessary for the
  998. # modules to be imported correctly by the tests since they are all part of the
  999. # same Python package.
  1000. internal_copied_filegroup(
  1001. name = "protos_python_test",
  1002. srcs = LITE_TEST_PROTOS + TEST_PROTOS,
  1003. dest = "python",
  1004. strip_prefix = "src",
  1005. )
  1006. # TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
  1007. # which case we can simply add :protos_python_test in srcs.
  1008. COPIED_LITE_TEST_PROTOS = ["python/" + s for s in RELATIVE_LITE_TEST_PROTOS]
  1009. COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]
  1010. py_proto_library(
  1011. name = "python_common_test_protos",
  1012. srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
  1013. include = "python",
  1014. default_runtime = "",
  1015. protoc = ":protoc",
  1016. srcs_version = "PY2AND3",
  1017. deps = [":protobuf_python"],
  1018. )
  1019. py_proto_library(
  1020. name = "python_specific_test_protos",
  1021. srcs = glob([
  1022. "python/google/protobuf/internal/*.proto",
  1023. "python/google/protobuf/internal/import_test_package/*.proto",
  1024. ]),
  1025. include = "python",
  1026. default_runtime = ":protobuf_python",
  1027. protoc = ":protoc",
  1028. srcs_version = "PY2AND3",
  1029. deps = [":python_common_test_protos"],
  1030. )
  1031. py_library(
  1032. name = "python_tests",
  1033. srcs = glob(
  1034. [
  1035. "python/google/protobuf/internal/*_test.py",
  1036. "python/google/protobuf/internal/test_util.py",
  1037. "python/google/protobuf/internal/import_test_package/__init__.py",
  1038. ],
  1039. ),
  1040. imports = ["python"],
  1041. srcs_version = "PY2AND3",
  1042. deps = [
  1043. ":protobuf_python",
  1044. ":python_common_test_protos",
  1045. ":python_specific_test_protos",
  1046. ],
  1047. )
  1048. internal_protobuf_py_tests(
  1049. name = "python_tests_batch",
  1050. data = glob([
  1051. "src/google/protobuf/**/*",
  1052. ]),
  1053. modules = [
  1054. "descriptor_database_test",
  1055. "descriptor_pool_test",
  1056. "descriptor_test",
  1057. "generator_test",
  1058. "json_format_test",
  1059. "message_factory_test",
  1060. "message_test",
  1061. "proto_builder_test",
  1062. "reflection_test",
  1063. "service_reflection_test",
  1064. "symbol_database_test",
  1065. "text_encoding_test",
  1066. "text_format_test",
  1067. "unknown_fields_test",
  1068. "wire_format_test",
  1069. ],
  1070. deps = [":python_tests"],
  1071. )
  1072. cc_library(
  1073. name = "proto_api",
  1074. hdrs = ["python/google/protobuf/proto_api.h"],
  1075. visibility = ["//visibility:public"],
  1076. deps = [
  1077. "//external:python_headers",
  1078. ],
  1079. )
  1080. proto_lang_toolchain(
  1081. name = "cc_toolchain",
  1082. blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
  1083. command_line = "--cpp_out=$(OUT)",
  1084. runtime = ":protobuf",
  1085. visibility = ["//visibility:public"],
  1086. )
  1087. alias(
  1088. name = "objectivec",
  1089. actual = "//objectivec",
  1090. visibility = ["//visibility:public"],
  1091. )
  1092. alias(
  1093. name = "protobuf_objc",
  1094. actual = "//objectivec",
  1095. visibility = ["//visibility:public"],
  1096. )
  1097. ################################################################################
  1098. # Test generated proto support
  1099. ################################################################################
  1100. genrule(
  1101. name = "generated_protos",
  1102. srcs = ["src/google/protobuf/unittest_import.proto"],
  1103. outs = ["unittest_gen.proto"],
  1104. cmd = "cat $(SRCS) | sed 's|google/|src/google/|' > $(OUTS)",
  1105. )
  1106. proto_library(
  1107. name = "generated_protos_proto",
  1108. srcs = [
  1109. "src/google/protobuf/unittest_import_public.proto",
  1110. "unittest_gen_import.proto",
  1111. ],
  1112. )
  1113. py_proto_library(
  1114. name = "generated_protos_py",
  1115. srcs = [
  1116. "src/google/protobuf/unittest_import_public.proto",
  1117. "unittest_gen_import.proto",
  1118. ],
  1119. default_runtime = "",
  1120. protoc = ":protoc",
  1121. )
  1122. ################################################################################
  1123. # Conformance tests
  1124. ################################################################################
  1125. proto_library(
  1126. name = "test_messages_proto2_proto",
  1127. srcs = ["src/google/protobuf/test_messages_proto2.proto"],
  1128. visibility = ["//visibility:public"],
  1129. )
  1130. proto_library(
  1131. name = "test_messages_proto3_proto",
  1132. srcs = ["src/google/protobuf/test_messages_proto3.proto"],
  1133. visibility = ["//visibility:public"],
  1134. deps = [
  1135. ":any_proto",
  1136. ":duration_proto",
  1137. ":field_mask_proto",
  1138. ":struct_proto",
  1139. ":timestamp_proto",
  1140. ":wrappers_proto",
  1141. ],
  1142. )
  1143. cc_proto_library(
  1144. name = "test_messages_proto2_proto_cc",
  1145. srcs = ["src/google/protobuf/test_messages_proto2.proto"],
  1146. )
  1147. cc_proto_library(
  1148. name = "test_messages_proto3_proto_cc",
  1149. srcs = ["src/google/protobuf/test_messages_proto3.proto"],
  1150. deps = [
  1151. ":cc_wkt_protos",
  1152. ],
  1153. )
  1154. proto_library(
  1155. name = "conformance_proto",
  1156. srcs = ["conformance/conformance.proto"],
  1157. visibility = ["//visibility:public"],
  1158. )
  1159. cc_proto_library(
  1160. name = "conformance_proto_cc",
  1161. srcs = ["conformance/conformance.proto"],
  1162. )
  1163. cc_library(
  1164. name = "jsoncpp",
  1165. srcs = ["conformance/third_party/jsoncpp/jsoncpp.cpp"],
  1166. hdrs = ["conformance/third_party/jsoncpp/json.h"],
  1167. includes = ["conformance"],
  1168. )
  1169. cc_library(
  1170. name = "conformance_test",
  1171. srcs = [
  1172. "conformance/conformance_test.cc",
  1173. "conformance/conformance_test_runner.cc",
  1174. ],
  1175. hdrs = [
  1176. "conformance/conformance_test.h",
  1177. ],
  1178. includes = [
  1179. "conformance",
  1180. "src",
  1181. ],
  1182. deps = [":conformance_proto_cc"],
  1183. )
  1184. cc_library(
  1185. name = "binary_json_conformance_suite",
  1186. srcs = ["conformance/binary_json_conformance_suite.cc"],
  1187. hdrs = ["conformance/binary_json_conformance_suite.h"],
  1188. deps = [
  1189. ":conformance_test",
  1190. ":jsoncpp",
  1191. ":test_messages_proto2_proto_cc",
  1192. ":test_messages_proto3_proto_cc",
  1193. ],
  1194. )
  1195. cc_library(
  1196. name = "text_format_conformance_suite",
  1197. srcs = ["conformance/text_format_conformance_suite.cc"],
  1198. hdrs = ["conformance/text_format_conformance_suite.h"],
  1199. deps = [
  1200. ":conformance_test",
  1201. ":test_messages_proto2_proto_cc",
  1202. ":test_messages_proto3_proto_cc",
  1203. ],
  1204. )
  1205. cc_binary(
  1206. name = "conformance_test_runner",
  1207. srcs = ["conformance/conformance_test_main.cc"],
  1208. visibility = ["//visibility:public"],
  1209. deps = [
  1210. ":binary_json_conformance_suite",
  1211. ":conformance_test",
  1212. ":text_format_conformance_suite",
  1213. ],
  1214. )
  1215. # TODO: re-enable this test if appropriate, or replace with something that
  1216. # uses the new setup.
  1217. # sh_test(
  1218. # name = "build_files_updated_unittest",
  1219. # srcs = [
  1220. # "build_files_updated_unittest.sh",
  1221. # ],
  1222. # data = [
  1223. # "BUILD",
  1224. # "cmake/extract_includes.bat.in",
  1225. # "cmake/libprotobuf.cmake",
  1226. # "cmake/libprotobuf-lite.cmake",
  1227. # "cmake/libprotoc.cmake",
  1228. # "cmake/tests.cmake",
  1229. # "src/Makefile.am",
  1230. # "update_file_lists.sh",
  1231. # ],
  1232. # )
  1233. java_proto_library(
  1234. name = "java_test_protos",
  1235. deps = [":generic_test_protos"],
  1236. visibility = ["//java:__subpackages__"],
  1237. )
  1238. java_lite_proto_library(
  1239. name = "java_lite_test_protos",
  1240. deps = [":generic_test_protos"],
  1241. visibility = ["//java:__subpackages__"],
  1242. )
  1243. java_proto_library(
  1244. name = "test_messages_proto2_java_proto",
  1245. visibility = [
  1246. "//java:__subpackages__",
  1247. ],
  1248. deps = [":test_messages_proto2_proto"],
  1249. )
  1250. java_proto_library(
  1251. name = "test_messages_proto3_java_proto",
  1252. visibility = [
  1253. "//java:__subpackages__",
  1254. ],
  1255. deps = [":test_messages_proto3_proto"],
  1256. )
  1257. java_proto_library(
  1258. name = "conformance_java_proto",
  1259. visibility = [
  1260. "//java:__subpackages__",
  1261. ],
  1262. deps = [":conformance_proto"],
  1263. )
  1264. java_lite_proto_library(
  1265. name = "test_messages_proto2_java_proto_lite",
  1266. visibility = [
  1267. "//java:__subpackages__",
  1268. ],
  1269. deps = [":test_messages_proto2_proto"],
  1270. )
  1271. java_lite_proto_library(
  1272. name = "conformance_java_proto_lite",
  1273. visibility = [
  1274. "//java:__subpackages__",
  1275. ],
  1276. deps = [":conformance_proto"],
  1277. )
  1278. java_lite_proto_library(
  1279. name = "test_messages_proto3_java_proto_lite",
  1280. visibility = [
  1281. "//java:__subpackages__",
  1282. ],
  1283. deps = [":test_messages_proto3_proto"],
  1284. )
  1285. java_binary(
  1286. name = "conformance_java",
  1287. srcs = ["conformance/ConformanceJava.java"],
  1288. main_class = "ConformanceJava",
  1289. visibility = [
  1290. "//java:__subpackages__",
  1291. ],
  1292. deps = [
  1293. ":conformance_java_proto",
  1294. ":test_messages_proto2_java_proto",
  1295. ":test_messages_proto3_java_proto",
  1296. "//:protobuf_java",
  1297. "//:protobuf_java_util",
  1298. ],
  1299. )
  1300. java_binary(
  1301. name = "conformance_java_lite",
  1302. srcs = ["conformance/ConformanceJavaLite.java"],
  1303. main_class = "ConformanceJavaLite",
  1304. visibility = [
  1305. "//java:__subpackages__",
  1306. ],
  1307. deps = [
  1308. ":conformance_java_proto_lite",
  1309. ":test_messages_proto2_java_proto_lite",
  1310. ":test_messages_proto3_java_proto_lite",
  1311. "//:protobuf_java_util",
  1312. "//:protobuf_javalite",
  1313. ],
  1314. )
  1315. exports_files([
  1316. "conformance/conformance_test_runner.sh",
  1317. "conformance/failure_list_java.txt",
  1318. "conformance/failure_list_java_lite.txt",
  1319. "conformance/text_format_failure_list_java.txt",
  1320. "conformance/text_format_failure_list_java_lite.txt",
  1321. ])
  1322. filegroup(
  1323. name = "bzl_srcs",
  1324. srcs = glob(["**/*.bzl"]),
  1325. visibility = ["//visibility:public"],
  1326. )
  1327. # Kotlin proto rules
  1328. proto_library(
  1329. name = "kt_unittest_lite",
  1330. srcs = [
  1331. "src/google/protobuf/unittest_lite.proto",
  1332. "src/google/protobuf/unittest_import_lite.proto",
  1333. "src/google/protobuf/unittest_import_public_lite.proto",
  1334. "src/google/protobuf/map_lite_unittest.proto",
  1335. ],
  1336. strip_import_prefix = "src",
  1337. )
  1338. internal_gen_kt_protos(
  1339. name = "gen_kotlin_unittest_lite",
  1340. deps = [":kt_unittest_lite"],
  1341. lite = True,
  1342. visibility = ["//java:__subpackages__"],
  1343. )
  1344. proto_library(
  1345. name = "kt_unittest",
  1346. srcs = [
  1347. "src/google/protobuf/unittest.proto",
  1348. "src/google/protobuf/unittest_import.proto",
  1349. "src/google/protobuf/unittest_import_public.proto",
  1350. "src/google/protobuf/map_proto2_unittest.proto",
  1351. ],
  1352. strip_import_prefix = "src",
  1353. )
  1354. internal_gen_kt_protos(
  1355. name = "gen_kotlin_unittest",
  1356. deps = [":kt_unittest"],
  1357. visibility = ["//java:__subpackages__"],
  1358. )
  1359. proto_library(
  1360. name = "kt_proto3_unittest",
  1361. srcs = [
  1362. "src/google/protobuf/unittest_proto3.proto",
  1363. "src/google/protobuf/unittest_import.proto",
  1364. "src/google/protobuf/unittest_import_public.proto",
  1365. ],
  1366. strip_import_prefix = "src",
  1367. )
  1368. internal_gen_kt_protos(
  1369. name = "gen_kotlin_proto3_unittest_lite",
  1370. deps = [":kt_proto3_unittest"],
  1371. lite = True,
  1372. visibility = ["//java:__subpackages__"],
  1373. )
  1374. internal_gen_kt_protos(
  1375. name = "gen_kotlin_proto3_unittest",
  1376. deps = [":kt_proto3_unittest"],
  1377. visibility = ["//java:__subpackages__"],
  1378. )