BUILD 38 KB

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