BUILD 34 KB

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