BUILD 37 KB

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