BUILD 37 KB

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