BUILD 34 KB

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