BUILD 34 KB

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