blob: 1f1a047467cb29c382921fe9c0f0cfe81e578a7a [file] [log] [blame]
Laszlo Csomor55171682017-12-01 12:05:32 +01001# Bazel (https://bazel.build/) BUILD file for Protobuf.
Jisi Liud19604f2015-06-17 17:37:58 -07002
3licenses(["notice"])
4
Piotr Sikorafaea19c2016-08-04 15:32:14 -07005exports_files(["LICENSE"])
6
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -07007################################################################################
David Ostrovsky85b488f2018-01-31 09:01:27 +01008# Java 9 configuration
9################################################################################
10
11config_setting(
12 name = "jdk9",
13 values = {
14 "java_toolchain": "@bazel_tools//tools/jdk:toolchain_jdk9",
15 },
16)
17
18################################################################################
Cody Schroeder802d5432018-12-11 11:58:26 -080019# ZLIB configuration
20################################################################################
21
Nic McDonaldf313b9c2019-04-12 15:41:08 -070022ZLIB_DEPS = ["@zlib//:zlib"]
Cody Schroeder802d5432018-12-11 11:58:26 -080023
24################################################################################
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -070025# Protobuf Runtime Library
26################################################################################
27
Pascal Muetscharda6957f22018-03-22 13:14:10 -070028MSVC_COPTS = [
Yun Peng0b059a32017-05-31 14:01:23 +020029 "/DHAVE_PTHREAD",
30 "/wd4018", # -Wno-sign-compare
Loo Rong Jie0456e262018-06-06 10:03:25 +080031 "/wd4065", # switch statement contains 'default' but no 'case' labels
32 "/wd4146", # unary minus operator applied to unsigned type, result still unsigned
33 "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data
34 "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
35 "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data
36 "/wd4305", # 'identifier' : truncation from 'type1' to 'type2'
37 "/wd4307", # 'operator' : integral constant overflow
38 "/wd4309", # 'conversion' : truncation of constant value
39 "/wd4334", # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
40 "/wd4355", # 'this' : used in base member initializer list
41 "/wd4506", # no definition for inline function 'function'
Yun Peng0b059a32017-05-31 14:01:23 +020042 "/wd4514", # -Wno-unused-function
Loo Rong Jie0456e262018-06-06 10:03:25 +080043 "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning)
44 "/wd4996", # The compiler encountered a deprecated declaration.
Jisi Liud19604f2015-06-17 17:37:58 -070045]
46
Yun Peng0b059a32017-05-31 14:01:23 +020047COPTS = select({
Pascal Muetscharda6957f22018-03-22 13:14:10 -070048 ":msvc" : MSVC_COPTS,
Yun Peng0b059a32017-05-31 14:01:23 +020049 "//conditions:default": [
50 "-DHAVE_PTHREAD",
Cody Schroeder802d5432018-12-11 11:58:26 -080051 "-DHAVE_ZLIB",
Yun Peng0b059a32017-05-31 14:01:23 +020052 "-Woverloaded-virtual",
53 "-Wno-sign-compare",
54 "-Wno-unused-function",
Justine Tunneyac5371d2017-11-17 18:27:39 -080055 # Prevents ISO C++ const string assignment warnings for pyext sources.
depristo2506cf52018-06-28 22:54:43 +000056 "-Wno-write-strings",
Yun Peng0b059a32017-05-31 14:01:23 +020057 ],
58})
59
scentinib30ddee2018-08-28 14:07:55 +020060load(":compiler_config_setting.bzl", "create_compiler_config_setting")
61
62create_compiler_config_setting(name = "msvc", value = "msvc-cl")
Yun Peng0b059a32017-05-31 14:01:23 +020063
Andrew Harpb56b4612016-04-04 15:13:30 -040064config_setting(
65 name = "android",
66 values = {
67 "crosstool_top": "//external:android/crosstool",
68 },
69)
70
yejianwudf4ec8a2019-04-02 20:08:37 +080071config_setting(
72 name = "android-libcpp",
73 values = {
74 "crosstool_top": "@androidndk//:toolchain-libcpp",
75 },
76)
77
78config_setting(
79 name = "android-gnu-libstdcpp",
80 values = {
81 "crosstool_top": "@androidndk//:toolchain-gnu-libstdcpp",
82 },
83)
84
Pascal Muetscharda6957f22018-03-22 13:14:10 -070085# Android and MSVC builds do not need to link in a separate pthread library.
Andrew Harpb56b4612016-04-04 15:13:30 -040086LINK_OPTS = select({
Andrew Harp3b4e7dc2016-04-04 16:13:31 -040087 ":android": [],
yejianwudf4ec8a2019-04-02 20:08:37 +080088 ":android-libcpp": [],
89 ":android-gnu-libstdcpp": [],
Jan Tattermuschccc56a32018-05-24 09:51:53 -070090 ":msvc": [
Loo Rong Jie0456e262018-06-06 10:03:25 +080091 # Suppress linker warnings about files with no symbols defined.
92 "-ignore:4221",
Laszlo Csomor55171682017-12-01 12:05:32 +010093 ],
Daniel Ylitalo32fa55e2017-01-25 22:04:11 +010094 "//conditions:default": ["-lpthread", "-lm"],
Andrew Harpb56b4612016-04-04 15:13:30 -040095})
Jisi Liud19604f2015-06-17 17:37:58 -070096
Jisi Liu04658a32015-10-20 15:00:13 -070097load(
cgrushko65a4d202017-02-08 15:23:57 -050098 ":protobuf.bzl",
Jisi Liu04658a32015-10-20 15:00:13 -070099 "cc_proto_library",
100 "py_proto_library",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700101 "internal_copied_filegroup",
Steven Parkesea188662016-02-25 07:53:19 -0800102 "internal_gen_well_known_protos_java",
Jisi Liu04658a32015-10-20 15:00:13 -0700103 "internal_protobuf_py_tests",
104)
Jisi Liu39362b32015-10-14 17:12:11 -0700105
Jisi Liud19604f2015-06-17 17:37:58 -0700106cc_library(
107 name = "protobuf_lite",
108 srcs = [
109 # AUTOGEN(protobuf_lite_srcs)
Phillipp Schoppmann8e5b2f12019-03-14 10:35:05 +0000110 "src/google/protobuf/any_lite.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700111 "src/google/protobuf/arena.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700112 "src/google/protobuf/extension_set.cc",
Hao Nguyen4cebf972019-05-03 15:08:01 -0700113 "src/google/protobuf/generated_enum_util.cc",
Jisi Liu12c186f2017-07-25 14:38:00 -0700114 "src/google/protobuf/generated_message_table_driven_lite.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700115 "src/google/protobuf/generated_message_util.cc",
Adam Cozzette609d7522017-12-07 14:16:50 -0800116 "src/google/protobuf/implicit_weak_message.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700117 "src/google/protobuf/io/coded_stream.cc",
Hao Nguyenef1e8e72019-04-09 06:48:01 -0700118 "src/google/protobuf/io/io_win32.cc",
John W. Bruce21e4b1c2019-06-05 18:28:16 -0700119 "src/google/protobuf/io/strtod.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700120 "src/google/protobuf/io/zero_copy_stream.cc",
Hao Nguyen4cebf972019-05-03 15:08:01 -0700121 "src/google/protobuf/io/zero_copy_stream_impl.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700122 "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
123 "src/google/protobuf/message_lite.cc",
Phillipp Schoppmann8e5b2f12019-03-14 10:35:05 +0000124 "src/google/protobuf/parse_context.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700125 "src/google/protobuf/repeated_field.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700126 "src/google/protobuf/stubs/bytestream.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700127 "src/google/protobuf/stubs/common.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700128 "src/google/protobuf/stubs/int128.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700129 "src/google/protobuf/stubs/status.cc",
130 "src/google/protobuf/stubs/statusor.cc",
131 "src/google/protobuf/stubs/stringpiece.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700132 "src/google/protobuf/stubs/stringprintf.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700133 "src/google/protobuf/stubs/structurally_valid.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700134 "src/google/protobuf/stubs/strutil.cc",
135 "src/google/protobuf/stubs/time.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700136 "src/google/protobuf/wire_format_lite.cc",
137 ],
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700138 hdrs = glob(["src/google/protobuf/**/*.h", "src/google/protobuf/**/*.inc"]),
Param Reddy16792c62017-10-15 13:06:58 -0700139 copts = COPTS,
Jisi Liud19604f2015-06-17 17:37:58 -0700140 includes = ["src/"],
141 linkopts = LINK_OPTS,
142 visibility = ["//visibility:public"],
143)
144
Cody Schroeder802d5432018-12-11 11:58:26 -0800145PROTOBUF_DEPS = select({
146 ":msvc": [],
147 "//conditions:default": ZLIB_DEPS,
148})
149
Jisi Liud19604f2015-06-17 17:37:58 -0700150cc_library(
151 name = "protobuf",
152 srcs = [
153 # AUTOGEN(protobuf_srcs)
154 "src/google/protobuf/any.cc",
155 "src/google/protobuf/any.pb.cc",
156 "src/google/protobuf/api.pb.cc",
157 "src/google/protobuf/compiler/importer.cc",
158 "src/google/protobuf/compiler/parser.cc",
159 "src/google/protobuf/descriptor.cc",
160 "src/google/protobuf/descriptor.pb.cc",
161 "src/google/protobuf/descriptor_database.cc",
162 "src/google/protobuf/duration.pb.cc",
163 "src/google/protobuf/dynamic_message.cc",
164 "src/google/protobuf/empty.pb.cc",
165 "src/google/protobuf/extension_set_heavy.cc",
166 "src/google/protobuf/field_mask.pb.cc",
167 "src/google/protobuf/generated_message_reflection.cc",
Jisi Liu759245a2017-07-25 11:52:33 -0700168 "src/google/protobuf/generated_message_table_driven.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700169 "src/google/protobuf/io/gzip_stream.cc",
170 "src/google/protobuf/io/printer.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700171 "src/google/protobuf/io/tokenizer.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700172 "src/google/protobuf/map_field.cc",
173 "src/google/protobuf/message.cc",
174 "src/google/protobuf/reflection_ops.cc",
175 "src/google/protobuf/service.cc",
176 "src/google/protobuf/source_context.pb.cc",
177 "src/google/protobuf/struct.pb.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700178 "src/google/protobuf/stubs/mathlimits.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700179 "src/google/protobuf/stubs/substitute.cc",
180 "src/google/protobuf/text_format.cc",
181 "src/google/protobuf/timestamp.pb.cc",
182 "src/google/protobuf/type.pb.cc",
183 "src/google/protobuf/unknown_field_set.cc",
Bairen Yi312e2db2017-03-21 03:52:37 +0800184 "src/google/protobuf/util/delimited_message_util.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700185 "src/google/protobuf/util/field_comparator.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700186 "src/google/protobuf/util/field_mask_util.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700187 "src/google/protobuf/util/internal/datapiece.cc",
188 "src/google/protobuf/util/internal/default_value_objectwriter.cc",
189 "src/google/protobuf/util/internal/error_listener.cc",
190 "src/google/protobuf/util/internal/field_mask_utility.cc",
191 "src/google/protobuf/util/internal/json_escaping.cc",
192 "src/google/protobuf/util/internal/json_objectwriter.cc",
193 "src/google/protobuf/util/internal/json_stream_parser.cc",
194 "src/google/protobuf/util/internal/object_writer.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800195 "src/google/protobuf/util/internal/proto_writer.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700196 "src/google/protobuf/util/internal/protostream_objectsource.cc",
197 "src/google/protobuf/util/internal/protostream_objectwriter.cc",
198 "src/google/protobuf/util/internal/type_info.cc",
199 "src/google/protobuf/util/internal/type_info_test_helper.cc",
200 "src/google/protobuf/util/internal/utility.cc",
201 "src/google/protobuf/util/json_util.cc",
202 "src/google/protobuf/util/message_differencer.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700203 "src/google/protobuf/util/time_util.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700204 "src/google/protobuf/util/type_resolver_util.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700205 "src/google/protobuf/wire_format.cc",
206 "src/google/protobuf/wrappers.pb.cc",
207 ],
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700208 hdrs = glob(["src/**/*.h", "src/**/*.inc"]),
Param Reddy16792c62017-10-15 13:06:58 -0700209 copts = COPTS,
Jisi Liud19604f2015-06-17 17:37:58 -0700210 includes = ["src/"],
211 linkopts = LINK_OPTS,
212 visibility = ["//visibility:public"],
Cody Schroeder802d5432018-12-11 11:58:26 -0800213 deps = [":protobuf_lite"] + PROTOBUF_DEPS,
Jisi Liud19604f2015-06-17 17:37:58 -0700214)
215
Manjunath Kudlur6837b2d2017-03-02 18:02:05 -0800216# This provides just the header files for use in projects that need to build
217# shared libraries for dynamic loading. This target is available until Bazel
218# adds native support for such use cases.
219# TODO(keveman): Remove this target once the support gets added to Bazel.
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800220cc_library(
221 name = "protobuf_headers",
222 hdrs = glob(["src/**/*.h"]),
223 includes = ["src/"],
224 visibility = ["//visibility:public"],
225)
226
Jakob Buchgraber699c0eb2017-09-05 17:15:10 +0200227# Map of all well known protos.
228# name => (include path, imports)
229WELL_KNOWN_PROTO_MAP = {
230 "any" : ("google/protobuf/any.proto", []),
231 "api" : ("google/protobuf/api.proto", ["source_context", "type"]),
232 "compiler_plugin" : ("google/protobuf/compiler/plugin.proto", ["descriptor"]),
233 "descriptor" : ("google/protobuf/descriptor.proto", []),
234 "duration" : ("google/protobuf/duration.proto", []),
235 "empty" : ("google/protobuf/empty.proto", []),
236 "field_mask" : ("google/protobuf/field_mask.proto", []),
237 "source_context" : ("google/protobuf/source_context.proto", []),
238 "struct" : ("google/protobuf/struct.proto", []),
239 "timestamp" : ("google/protobuf/timestamp.proto", []),
240 "type" : ("google/protobuf/type.proto", ["any", "source_context"]),
241 "wrappers" : ("google/protobuf/wrappers.proto", []),
242}
243
244RELATIVE_WELL_KNOWN_PROTOS = [proto[1][0] for proto in WELL_KNOWN_PROTO_MAP.items()]
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700245
Jisi Liu993fb702015-10-19 17:19:49 -0700246WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
247
Steven Parkesd5a57322016-03-22 17:56:07 -0700248filegroup(
249 name = "well_known_protos",
250 srcs = WELL_KNOWN_PROTOS,
251 visibility = ["//visibility:public"],
252)
253
Jisi Liu39362b32015-10-14 17:12:11 -0700254cc_proto_library(
255 name = "cc_wkt_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700256 srcs = WELL_KNOWN_PROTOS,
Jisi Liu3101e732015-10-16 12:46:26 -0700257 include = "src",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800258 default_runtime = ":protobuf",
Jisi Liu993fb702015-10-19 17:19:49 -0700259 internal_bootstrap_hack = 1,
Jisi Liu04658a32015-10-20 15:00:13 -0700260 protoc = ":protoc",
Jisi Liu6a40bf82015-11-17 12:36:21 -0800261 visibility = ["//visibility:public"],
Jisi Liu39362b32015-10-14 17:12:11 -0700262)
263
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700264################################################################################
Jakob Buchgraber699c0eb2017-09-05 17:15:10 +0200265# Well Known Types Proto Library Rules
266#
267# These proto_library rules can be used with one of the language specific proto
268# library rules i.e. java_proto_library:
269#
270# java_proto_library(
271# name = "any_java_proto",
272# deps = ["@com_google_protobuf//:any_proto],
273# )
274################################################################################
275
276internal_copied_filegroup(
277 name = "_internal_wkt_protos",
278 srcs = WELL_KNOWN_PROTOS,
279 dest = "",
280 strip_prefix = "src",
James O'Kane950f5e42018-03-08 22:30:44 -0800281 visibility = ["//visibility:private"],
Jakob Buchgraber699c0eb2017-09-05 17:15:10 +0200282)
283
284[proto_library(
285 name = proto[0] + "_proto",
286 srcs = [proto[1][0]],
287 deps = [dep + "_proto" for dep in proto[1][1]],
288 visibility = ["//visibility:public"],
289 ) for proto in WELL_KNOWN_PROTO_MAP.items()]
290
291################################################################################
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700292# Protocol Buffers Compiler
293################################################################################
294
Jisi Liud19604f2015-06-17 17:37:58 -0700295cc_library(
296 name = "protoc_lib",
297 srcs = [
298 # AUTOGEN(protoc_lib_srcs)
299 "src/google/protobuf/compiler/code_generator.cc",
300 "src/google/protobuf/compiler/command_line_interface.cc",
301 "src/google/protobuf/compiler/cpp/cpp_enum.cc",
302 "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
303 "src/google/protobuf/compiler/cpp/cpp_extension.cc",
304 "src/google/protobuf/compiler/cpp/cpp_field.cc",
305 "src/google/protobuf/compiler/cpp/cpp_file.cc",
306 "src/google/protobuf/compiler/cpp/cpp_generator.cc",
307 "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
308 "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
309 "src/google/protobuf/compiler/cpp/cpp_message.cc",
310 "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
Adam Cozzette13fd0452017-09-12 10:32:01 -0700311 "src/google/protobuf/compiler/cpp/cpp_padding_optimizer.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700312 "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
313 "src/google/protobuf/compiler/cpp/cpp_service.cc",
314 "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
Ming Zhao5cdd9362015-10-05 14:37:21 -0700315 "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700316 "src/google/protobuf/compiler/csharp/csharp_enum.cc",
317 "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700318 "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
319 "src/google/protobuf/compiler/csharp/csharp_generator.cc",
320 "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
Jon Skeetb2ac8682015-07-15 13:17:42 +0100321 "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700322 "src/google/protobuf/compiler/csharp/csharp_message.cc",
323 "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
324 "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
Jon Skeeta6361a12015-11-19 13:05:17 +0000325 "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700326 "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
327 "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
328 "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
329 "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
Jon Skeetb2ac8682015-07-15 13:17:42 +0100330 "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700331 "src/google/protobuf/compiler/java/java_context.cc",
332 "src/google/protobuf/compiler/java/java_doc_comment.cc",
333 "src/google/protobuf/compiler/java/java_enum.cc",
334 "src/google/protobuf/compiler/java/java_enum_field.cc",
335 "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700336 "src/google/protobuf/compiler/java/java_enum_lite.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700337 "src/google/protobuf/compiler/java/java_extension.cc",
Jisi Liu1f4f3e22016-04-18 14:12:08 -0700338 "src/google/protobuf/compiler/java/java_extension_lite.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700339 "src/google/protobuf/compiler/java/java_field.cc",
340 "src/google/protobuf/compiler/java/java_file.cc",
341 "src/google/protobuf/compiler/java/java_generator.cc",
342 "src/google/protobuf/compiler/java/java_generator_factory.cc",
343 "src/google/protobuf/compiler/java/java_helpers.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700344 "src/google/protobuf/compiler/java/java_map_field.cc",
345 "src/google/protobuf/compiler/java/java_map_field_lite.cc",
346 "src/google/protobuf/compiler/java/java_message.cc",
347 "src/google/protobuf/compiler/java/java_message_builder.cc",
348 "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
349 "src/google/protobuf/compiler/java/java_message_field.cc",
350 "src/google/protobuf/compiler/java/java_message_field_lite.cc",
351 "src/google/protobuf/compiler/java/java_message_lite.cc",
352 "src/google/protobuf/compiler/java/java_name_resolver.cc",
353 "src/google/protobuf/compiler/java/java_primitive_field.cc",
354 "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
355 "src/google/protobuf/compiler/java/java_service.cc",
356 "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
357 "src/google/protobuf/compiler/java/java_string_field.cc",
358 "src/google/protobuf/compiler/java/java_string_field_lite.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800359 "src/google/protobuf/compiler/js/js_generator.cc",
Jisi Liuf92b4552016-12-05 10:16:47 -0800360 "src/google/protobuf/compiler/js/well_known_types_embed.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700361 "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
362 "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
363 "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
364 "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
365 "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
366 "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
367 "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
368 "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
369 "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
370 "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
371 "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
372 "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
Jisi Liud9473082016-09-22 15:14:58 -0700373 "src/google/protobuf/compiler/php/php_generator.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700374 "src/google/protobuf/compiler/plugin.cc",
Feng Xiaofd595fc2018-03-01 16:36:05 -0800375 "src/google/protobuf/compiler/plugin.pb.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700376 "src/google/protobuf/compiler/python/python_generator.cc",
377 "src/google/protobuf/compiler/ruby/ruby_generator.cc",
378 "src/google/protobuf/compiler/subprocess.cc",
379 "src/google/protobuf/compiler/zip_writer.cc",
380 ],
381 copts = COPTS,
382 includes = ["src/"],
Loo Rong Jie0456e262018-06-06 10:03:25 +0800383 linkopts = LINK_OPTS + select({
384 ":msvc": [
385 # Linking to setargv.obj makes the default command line argument
386 # parser expand wildcards, so the main method's argv will contain the
387 # expanded list instead of the wildcards.
388 #
389 # Adding dummy "-DEFAULTLIB:kernel32.lib", because:
390 # - Microsoft ships this object file next to default libraries
391 # - but this file is not a library, just a precompiled object
392 # - "-WHOLEARCHIVE" and "-DEFAULTLIB" only accept library,
393 # not precompiled object.
394 # - Bazel would assume linkopt that does not start with "-" or "$"
395 # as a label to a target, so we add a harmless "-DEFAULTLIB:kernel32.lib"
396 # before "setargv.obj".
397 # See https://msdn.microsoft.com/en-us/library/8bch7bkk.aspx
398 "-DEFAULTLIB:kernel32.lib setargv.obj",
399 ],
400 "//conditions:default": [],
401 }),
Jisi Liud19604f2015-06-17 17:37:58 -0700402 visibility = ["//visibility:public"],
403 deps = [":protobuf"],
404)
405
406cc_binary(
407 name = "protoc",
408 srcs = ["src/google/protobuf/compiler/main.cc"],
Jisi Liud19604f2015-06-17 17:37:58 -0700409 linkopts = LINK_OPTS,
410 visibility = ["//visibility:public"],
411 deps = [":protoc_lib"],
412)
413
Jisi Liud19604f2015-06-17 17:37:58 -0700414################################################################################
415# Tests
416################################################################################
417
Jisi Liu993fb702015-10-19 17:19:49 -0700418RELATIVE_LITE_TEST_PROTOS = [
Jisi Liud19604f2015-06-17 17:37:58 -0700419 # AUTOGEN(lite_test_protos)
420 "google/protobuf/map_lite_unittest.proto",
421 "google/protobuf/unittest_import_lite.proto",
422 "google/protobuf/unittest_import_public_lite.proto",
423 "google/protobuf/unittest_lite.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700424 "google/protobuf/unittest_no_arena_lite.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700425]
426
Jisi Liu993fb702015-10-19 17:19:49 -0700427LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
428
429RELATIVE_TEST_PROTOS = [
Jisi Liud19604f2015-06-17 17:37:58 -0700430 # AUTOGEN(test_protos)
431 "google/protobuf/any_test.proto",
432 "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
433 "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
434 "google/protobuf/map_proto2_unittest.proto",
435 "google/protobuf/map_unittest.proto",
436 "google/protobuf/unittest.proto",
437 "google/protobuf/unittest_arena.proto",
438 "google/protobuf/unittest_custom_options.proto",
439 "google/protobuf/unittest_drop_unknown_fields.proto",
440 "google/protobuf/unittest_embed_optimize_for.proto",
441 "google/protobuf/unittest_empty.proto",
442 "google/protobuf/unittest_enormous_descriptor.proto",
443 "google/protobuf/unittest_import.proto",
444 "google/protobuf/unittest_import_public.proto",
Feng Xiao32d78302017-03-29 14:01:40 -0700445 "google/protobuf/unittest_lazy_dependencies.proto",
446 "google/protobuf/unittest_lazy_dependencies_custom_option.proto",
447 "google/protobuf/unittest_lazy_dependencies_enum.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700448 "google/protobuf/unittest_lite_imports_nonlite.proto",
449 "google/protobuf/unittest_mset.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700450 "google/protobuf/unittest_mset_wire_format.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700451 "google/protobuf/unittest_no_arena.proto",
452 "google/protobuf/unittest_no_arena_import.proto",
453 "google/protobuf/unittest_no_field_presence.proto",
454 "google/protobuf/unittest_no_generic_services.proto",
455 "google/protobuf/unittest_optimize_for.proto",
456 "google/protobuf/unittest_preserve_unknown_enum.proto",
457 "google/protobuf/unittest_preserve_unknown_enum2.proto",
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700458 "google/protobuf/unittest_proto3.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700459 "google/protobuf/unittest_proto3_arena.proto",
Chad Whipkeybaf52bd2016-04-15 09:23:50 -0700460 "google/protobuf/unittest_proto3_arena_lite.proto",
461 "google/protobuf/unittest_proto3_lite.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700462 "google/protobuf/unittest_well_known_types.proto",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700463 "google/protobuf/util/internal/testdata/anys.proto",
464 "google/protobuf/util/internal/testdata/books.proto",
465 "google/protobuf/util/internal/testdata/default_value.proto",
466 "google/protobuf/util/internal/testdata/default_value_test.proto",
467 "google/protobuf/util/internal/testdata/field_mask.proto",
468 "google/protobuf/util/internal/testdata/maps.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700469 "google/protobuf/util/internal/testdata/oneofs.proto",
Jisi Liu9d4657a2016-09-22 15:11:17 -0700470 "google/protobuf/util/internal/testdata/proto3.proto",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700471 "google/protobuf/util/internal/testdata/struct.proto",
472 "google/protobuf/util/internal/testdata/timestamp_duration.proto",
Jisi Liu9d4657a2016-09-22 15:11:17 -0700473 "google/protobuf/util/internal/testdata/wrappers.proto",
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700474 "google/protobuf/util/json_format.proto",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700475 "google/protobuf/util/json_format_proto3.proto",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800476 "google/protobuf/util/message_differencer_unittest.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700477]
478
Jisi Liu993fb702015-10-19 17:19:49 -0700479TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
480
Jisi Liu39362b32015-10-14 17:12:11 -0700481cc_proto_library(
482 name = "cc_test_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700483 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
Jisi Liu3101e732015-10-16 12:46:26 -0700484 include = "src",
Jisi Liube92ffb2015-10-27 15:11:38 -0700485 default_runtime = ":protobuf",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800486 protoc = ":protoc",
Jisi Liud8701b52015-10-16 11:44:21 -0700487 deps = [":cc_wkt_protos"],
Jisi Liud19604f2015-06-17 17:37:58 -0700488)
489
490COMMON_TEST_SRCS = [
491 # AUTOGEN(common_test_srcs)
492 "src/google/protobuf/arena_test_util.cc",
493 "src/google/protobuf/map_test_util.cc",
494 "src/google/protobuf/test_util.cc",
Adam Cozzette5bed3682018-03-23 10:19:04 -0700495 "src/google/protobuf/test_util.inc",
Jisi Liud19604f2015-06-17 17:37:58 -0700496 "src/google/protobuf/testing/file.cc",
497 "src/google/protobuf/testing/googletest.cc",
498]
499
Jisi Liu7a0c4312015-06-18 16:45:27 -0700500cc_binary(
501 name = "test_plugin",
502 srcs = [
503 # AUTOGEN(test_plugin_srcs)
504 "src/google/protobuf/compiler/mock_code_generator.cc",
505 "src/google/protobuf/compiler/test_plugin.cc",
506 "src/google/protobuf/testing/file.cc",
507 ],
508 deps = [
509 ":protobuf",
510 ":protoc_lib",
511 "//external:gtest",
512 ],
513)
514
515cc_test(
Jisi Liu759245a2017-07-25 11:52:33 -0700516 name = "win32_test",
Hao Nguyenef1e8e72019-04-09 06:48:01 -0700517 srcs = ["src/google/protobuf/io/io_win32_unittest.cc"],
Jisi Liu759245a2017-07-25 11:52:33 -0700518 deps = [
519 ":protobuf_lite",
520 "//external:gtest_main",
521 ],
522 tags = ["manual", "windows"],
523)
524
525cc_test(
Jisi Liu7a0c4312015-06-18 16:45:27 -0700526 name = "protobuf_test",
Jisi Liu39362b32015-10-14 17:12:11 -0700527 srcs = COMMON_TEST_SRCS + [
Jisi Liu7a0c4312015-06-18 16:45:27 -0700528 # AUTOGEN(test_srcs)
529 "src/google/protobuf/any_test.cc",
530 "src/google/protobuf/arena_unittest.cc",
531 "src/google/protobuf/arenastring_unittest.cc",
Jisi Liu1c682e02017-10-18 14:31:23 -0700532 "src/google/protobuf/compiler/annotation_test_util.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700533 "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
Jisi Liu11b66612017-07-19 12:10:43 -0700534 "src/google/protobuf/compiler/cpp/cpp_move_unittest.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700535 "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
536 "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
Adam Cozzette5bed3682018-03-23 10:19:04 -0700537 "src/google/protobuf/compiler/cpp/cpp_unittest.inc",
Jisi Liu1f4f3e22016-04-18 14:12:08 -0700538 "src/google/protobuf/compiler/cpp/metadata_test.cc",
Feng Xiao32d78302017-03-29 14:01:40 -0700539 "src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700540 "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
541 "src/google/protobuf/compiler/importer_unittest.cc",
542 "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
543 "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
544 "src/google/protobuf/compiler/mock_code_generator.cc",
545 "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
546 "src/google/protobuf/compiler/parser_unittest.cc",
547 "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
548 "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
549 "src/google/protobuf/descriptor_database_unittest.cc",
550 "src/google/protobuf/descriptor_unittest.cc",
551 "src/google/protobuf/drop_unknown_fields_test.cc",
552 "src/google/protobuf/dynamic_message_unittest.cc",
553 "src/google/protobuf/extension_set_unittest.cc",
554 "src/google/protobuf/generated_message_reflection_unittest.cc",
555 "src/google/protobuf/io/coded_stream_unittest.cc",
Hao Nguyenef1e8e72019-04-09 06:48:01 -0700556 "src/google/protobuf/io/io_win32_unittest.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700557 "src/google/protobuf/io/printer_unittest.cc",
558 "src/google/protobuf/io/tokenizer_unittest.cc",
559 "src/google/protobuf/io/zero_copy_stream_unittest.cc",
560 "src/google/protobuf/map_field_test.cc",
561 "src/google/protobuf/map_test.cc",
562 "src/google/protobuf/message_unittest.cc",
Adam Cozzette5bed3682018-03-23 10:19:04 -0700563 "src/google/protobuf/message_unittest.inc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700564 "src/google/protobuf/no_field_presence_test.cc",
565 "src/google/protobuf/preserve_unknown_enum_test.cc",
Chad Whipkeybaf52bd2016-04-15 09:23:50 -0700566 "src/google/protobuf/proto3_arena_lite_unittest.cc",
Jisi Liuf86d39c2016-04-28 14:43:22 -0700567 "src/google/protobuf/proto3_arena_unittest.cc",
Chad Whipkeybaf52bd2016-04-15 09:23:50 -0700568 "src/google/protobuf/proto3_lite_unittest.cc",
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700569 "src/google/protobuf/proto3_lite_unittest.inc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700570 "src/google/protobuf/reflection_ops_unittest.cc",
571 "src/google/protobuf/repeated_field_reflection_unittest.cc",
572 "src/google/protobuf/repeated_field_unittest.cc",
573 "src/google/protobuf/stubs/bytestream_unittest.cc",
574 "src/google/protobuf/stubs/common_unittest.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700575 "src/google/protobuf/stubs/int128_unittest.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700576 "src/google/protobuf/stubs/status_test.cc",
577 "src/google/protobuf/stubs/statusor_test.cc",
578 "src/google/protobuf/stubs/stringpiece_unittest.cc",
579 "src/google/protobuf/stubs/stringprintf_unittest.cc",
580 "src/google/protobuf/stubs/structurally_valid_unittest.cc",
581 "src/google/protobuf/stubs/strutil_unittest.cc",
582 "src/google/protobuf/stubs/template_util_unittest.cc",
583 "src/google/protobuf/stubs/time_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700584 "src/google/protobuf/text_format_unittest.cc",
585 "src/google/protobuf/unknown_field_set_unittest.cc",
Byron Yicb3e84b2017-03-16 20:01:22 +0800586 "src/google/protobuf/util/delimited_message_util_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700587 "src/google/protobuf/util/field_comparator_test.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700588 "src/google/protobuf/util/field_mask_util_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700589 "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
590 "src/google/protobuf/util/internal/json_objectwriter_test.cc",
591 "src/google/protobuf/util/internal/json_stream_parser_test.cc",
592 "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
593 "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
594 "src/google/protobuf/util/internal/type_info_test_helper.cc",
595 "src/google/protobuf/util/json_util_test.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800596 "src/google/protobuf/util/message_differencer_unittest.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700597 "src/google/protobuf/util/time_util_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700598 "src/google/protobuf/util/type_resolver_util_test.cc",
599 "src/google/protobuf/well_known_types_unittest.cc",
600 "src/google/protobuf/wire_format_unittest.cc",
Yun Peng073487b2018-12-14 12:53:36 +0100601 ] + select({
602 "//conditions:default" : [
603 # Doesn't pass on Windows with MSVC
604 "src/google/protobuf/compiler/command_line_interface_unittest.cc",
605 ],
606 ":msvc": []
607 }),
Jisi Liu7a0c4312015-06-18 16:45:27 -0700608 copts = COPTS,
609 data = [
610 ":test_plugin",
Jisi Liu598480d2015-10-21 11:19:16 -0700611 ] + glob([
612 "src/google/protobuf/**/*",
Feng Xiaoacde1652017-03-29 15:14:18 -0700613 # Files for csharp_bootstrap_unittest.cc.
614 "conformance/**/*",
615 "csharp/src/**/*",
Jisi Liu598480d2015-10-21 11:19:16 -0700616 ]),
Jisi Liu7a0c4312015-06-18 16:45:27 -0700617 includes = [
618 "src/",
619 ],
620 linkopts = LINK_OPTS,
621 deps = [
Jisi Liu993fb702015-10-19 17:19:49 -0700622 ":cc_test_protos",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700623 ":protobuf",
624 ":protoc_lib",
625 "//external:gtest_main",
Cody Schroeder802d5432018-12-11 11:58:26 -0800626 ] + PROTOBUF_DEPS,
Jisi Liu7a0c4312015-06-18 16:45:27 -0700627)
Jisi Liu993fb702015-10-19 17:19:49 -0700628
629################################################################################
630# Java support
631################################################################################
Steven Parkesea188662016-02-25 07:53:19 -0800632internal_gen_well_known_protos_java(
Ming Zhao4fe03812016-01-21 23:03:28 -0800633 srcs = WELL_KNOWN_PROTOS,
Jisi Liu993fb702015-10-19 17:19:49 -0700634)
635
636java_library(
Jisi Liu166e9bb2015-10-21 10:56:38 -0700637 name = "protobuf_java",
Jisi Liu993fb702015-10-19 17:19:49 -0700638 srcs = glob([
Ming Zhao4fe03812016-01-21 23:03:28 -0800639 "java/core/src/main/java/com/google/protobuf/*.java",
Jisi Liu993fb702015-10-19 17:19:49 -0700640 ]) + [
Ming Zhao4fe03812016-01-21 23:03:28 -0800641 ":gen_well_known_protos_java",
Jisi Liu993fb702015-10-19 17:19:49 -0700642 ],
David Ostrovsky85b488f2018-01-31 09:01:27 +0100643 javacopts = select({
644 "//:jdk9": ["--add-modules=jdk.unsupported"],
645 "//conditions:default": ["-source 7", "-target 7"],
646 }),
Jisi Liu993fb702015-10-19 17:19:49 -0700647 visibility = ["//visibility:public"],
648)
649
Steven Parkesa9244ca2016-03-10 17:50:25 -0800650java_library(
651 name = "protobuf_java_util",
652 srcs = glob([
653 "java/util/src/main/java/com/google/protobuf/util/*.java",
654 ]),
David Ostrovsky019ceea2018-01-25 06:05:14 +0100655 javacopts = ["-source 7", "-target 7"],
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800656 visibility = ["//visibility:public"],
Steven Parkesa9244ca2016-03-10 17:50:25 -0800657 deps = [
David Z. Chen5ebeefb2016-04-08 13:30:13 -0700658 "protobuf_java",
David Ostrovsky35c9a5f2019-03-03 21:57:33 +0100659 "//external:error_prone_annotations",
David Z. Chen5ebeefb2016-04-08 13:30:13 -0700660 "//external:gson",
661 "//external:guava",
Steven Parkesa9244ca2016-03-10 17:50:25 -0800662 ],
Steven Parkesa9244ca2016-03-10 17:50:25 -0800663)
664
Jisi Liu993fb702015-10-19 17:19:49 -0700665################################################################################
666# Python support
667################################################################################
668
David Z. Chen985c9682016-02-11 18:11:10 -0800669py_library(
Jisi Liu993fb702015-10-19 17:19:49 -0700670 name = "python_srcs",
671 srcs = glob(
672 [
Calder Coalson142cbe02018-05-21 15:33:43 -0700673 "python/google/__init__.py",
Jisi Liu993fb702015-10-19 17:19:49 -0700674 "python/google/protobuf/*.py",
675 "python/google/protobuf/**/*.py",
676 ],
677 exclude = [
David Z. Chen02cd45c2016-05-20 16:49:04 -0700678 "python/google/protobuf/__init__.py",
679 "python/google/protobuf/**/__init__.py",
Jisi Liu993fb702015-10-19 17:19:49 -0700680 "python/google/protobuf/internal/*_test.py",
681 "python/google/protobuf/internal/test_util.py",
682 ],
683 ),
David Z. Chen985c9682016-02-11 18:11:10 -0800684 imports = ["python"],
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800685 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700686)
687
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800688cc_binary(
Richard Shindf5841f2016-10-18 13:16:44 -0700689 name = "python/google/protobuf/internal/_api_implementation.so",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800690 srcs = ["python/google/protobuf/internal/api_implementation.cc"],
691 copts = COPTS + [
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800692 "-DPYTHON_PROTO2_CPP_IMPL_V2",
693 ],
694 linkshared = 1,
695 linkstatic = 1,
Manjunath Kudlura1949212015-12-08 08:24:37 -0800696 deps = select({
697 "//conditions:default": [],
David Z. Chen985c9682016-02-11 18:11:10 -0800698 ":use_fast_cpp_protos": ["//external:python_headers"],
Manjunath Kudlura1949212015-12-08 08:24:37 -0800699 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800700)
701
702cc_binary(
Richard Shindf5841f2016-10-18 13:16:44 -0700703 name = "python/google/protobuf/pyext/_message.so",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800704 srcs = glob([
705 "python/google/protobuf/pyext/*.cc",
706 "python/google/protobuf/pyext/*.h",
707 ]),
708 copts = COPTS + [
709 "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
Manjunath Kudlur99a3e302016-02-16 15:17:10 -0800710 ] + select({
711 "//conditions:default": [],
712 ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
713 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800714 includes = [
715 "python/",
716 "src/",
717 ],
718 linkshared = 1,
719 linkstatic = 1,
Manjunath Kudlura1949212015-12-08 08:24:37 -0800720 deps = [
721 ":protobuf",
Thomas Colthurst7c651422018-05-29 18:26:11 -0400722 ":proto_api",
Manjunath Kudlura1949212015-12-08 08:24:37 -0800723 ] + select({
724 "//conditions:default": [],
David Z. Chen985c9682016-02-11 18:11:10 -0800725 ":use_fast_cpp_protos": ["//external:python_headers"],
Manjunath Kudlura1949212015-12-08 08:24:37 -0800726 }),
727)
728
729config_setting(
730 name = "use_fast_cpp_protos",
731 values = {
732 "define": "use_fast_cpp_protos=true",
733 },
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800734)
735
Manjunath Kudlur99a3e302016-02-16 15:17:10 -0800736config_setting(
737 name = "allow_oversize_protos",
738 values = {
739 "define": "allow_oversize_protos=true",
740 },
741)
742
David Z. Chen02cd45c2016-05-20 16:49:04 -0700743# Copy the builtin proto files from src/google/protobuf to
744# python/google/protobuf. This way, the generated Python sources will be in the
745# same directory as the Python runtime sources. This is necessary for the
746# modules to be imported correctly since they are all part of the same Python
747# package.
748internal_copied_filegroup(
749 name = "protos_python",
750 srcs = WELL_KNOWN_PROTOS,
David Z. Chen02cd45c2016-05-20 16:49:04 -0700751 dest = "python",
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800752 strip_prefix = "src",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700753)
754
755# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
756# which case we can simply add :protos_python in srcs.
757COPIED_WELL_KNOWN_PROTOS = ["python/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
758
Jisi Liu993fb702015-10-19 17:19:49 -0700759py_proto_library(
Jisi Liu166e9bb2015-10-21 10:56:38 -0700760 name = "protobuf_python",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700761 srcs = COPIED_WELL_KNOWN_PROTOS,
762 include = "python",
Manjunath Kudlura1949212015-12-08 08:24:37 -0800763 data = select({
764 "//conditions:default": [],
765 ":use_fast_cpp_protos": [
Richard Shindf5841f2016-10-18 13:16:44 -0700766 ":python/google/protobuf/internal/_api_implementation.so",
767 ":python/google/protobuf/pyext/_message.so",
Manjunath Kudlura1949212015-12-08 08:24:37 -0800768 ],
769 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800770 default_runtime = "",
Jisi Liu04658a32015-10-20 15:00:13 -0700771 protoc = ":protoc",
David Z. Chen985c9682016-02-11 18:11:10 -0800772 py_libs = [
773 ":python_srcs",
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800774 "//external:six",
David Z. Chen985c9682016-02-11 18:11:10 -0800775 ],
Adam Michael6044b242017-03-10 18:06:34 -0500776 py_extra_srcs = glob(["python/**/__init__.py"]),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800777 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700778 visibility = ["//visibility:public"],
779)
780
David Z. Chen02cd45c2016-05-20 16:49:04 -0700781# Copy the test proto files from src/google/protobuf to
782# python/google/protobuf. This way, the generated Python sources will be in the
783# same directory as the Python runtime sources. This is necessary for the
784# modules to be imported correctly by the tests since they are all part of the
785# same Python package.
786internal_copied_filegroup(
787 name = "protos_python_test",
788 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
David Z. Chen02cd45c2016-05-20 16:49:04 -0700789 dest = "python",
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800790 strip_prefix = "src",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700791)
792
793# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
794# which case we can simply add :protos_python_test in srcs.
795COPIED_LITE_TEST_PROTOS = ["python/" + s for s in RELATIVE_LITE_TEST_PROTOS]
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800796
David Z. Chen02cd45c2016-05-20 16:49:04 -0700797COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]
798
Jisi Liu993fb702015-10-19 17:19:49 -0700799py_proto_library(
800 name = "python_common_test_protos",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700801 srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
802 include = "python",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800803 default_runtime = "",
Jisi Liu04658a32015-10-20 15:00:13 -0700804 protoc = ":protoc",
David Z. Chen5ebeefb2016-04-08 13:30:13 -0700805 srcs_version = "PY2AND3",
Jisi Liu166e9bb2015-10-21 10:56:38 -0700806 deps = [":protobuf_python"],
Jisi Liu993fb702015-10-19 17:19:49 -0700807)
808
809py_proto_library(
810 name = "python_specific_test_protos",
Jisi Liu68e13f42015-10-22 11:13:14 -0700811 srcs = glob([
812 "python/google/protobuf/internal/*.proto",
813 "python/google/protobuf/internal/import_test_package/*.proto",
814 ]),
Jisi Liu993fb702015-10-19 17:19:49 -0700815 include = "python",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800816 default_runtime = ":protobuf_python",
Jisi Liu04658a32015-10-20 15:00:13 -0700817 protoc = ":protoc",
David Z. Chen5ebeefb2016-04-08 13:30:13 -0700818 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700819 deps = [":python_common_test_protos"],
820)
821
822py_library(
823 name = "python_tests",
David Z. Chen985c9682016-02-11 18:11:10 -0800824 srcs = glob(
825 [
826 "python/google/protobuf/internal/*_test.py",
827 "python/google/protobuf/internal/test_util.py",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700828 "python/google/protobuf/internal/import_test_package/__init__.py",
David Z. Chen985c9682016-02-11 18:11:10 -0800829 ],
830 ),
831 imports = ["python"],
Geoffrey Irving29799232015-12-03 13:11:19 -0800832 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700833 deps = [
Jisi Liu166e9bb2015-10-21 10:56:38 -0700834 ":protobuf_python",
Jisi Liu598480d2015-10-21 11:19:16 -0700835 ":python_common_test_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700836 ":python_specific_test_protos",
837 ],
838)
839
840internal_protobuf_py_tests(
Jisi Liu8f540262015-10-20 16:21:41 -0700841 name = "python_tests_batch",
Jisi Liu68e13f42015-10-22 11:13:14 -0700842 data = glob([
843 "src/google/protobuf/**/*",
844 ]),
Jisi Liu993fb702015-10-19 17:19:49 -0700845 modules = [
846 "descriptor_database_test",
847 "descriptor_pool_test",
848 "descriptor_test",
849 "generator_test",
850 "json_format_test",
851 "message_factory_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700852 "message_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700853 "proto_builder_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700854 "reflection_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700855 "service_reflection_test",
856 "symbol_database_test",
857 "text_encoding_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700858 "text_format_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700859 "unknown_fields_test",
860 "wire_format_test",
861 ],
862 deps = [":python_tests"],
863)
cgrushko45d92ae2016-12-02 19:40:50 -0500864
Thomas Colthurst7c651422018-05-29 18:26:11 -0400865cc_library(
866 name = "proto_api",
867 hdrs = ["python/google/protobuf/proto_api.h"],
868 deps = [
Thomas Colthurst7c651422018-05-29 18:26:11 -0400869 "//external:python_headers",
870 ],
Cory McLeanb7d3ec32018-06-11 12:18:45 -0400871 visibility = ["//visibility:public"],
Thomas Colthurst7c651422018-05-29 18:26:11 -0400872)
873
cgrushko45d92ae2016-12-02 19:40:50 -0500874proto_lang_toolchain(
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800875 name = "cc_toolchain",
876 command_line = "--cpp_out=$(OUT)",
877 runtime = ":protobuf",
878 visibility = ["//visibility:public"],
John Millikin350b1352018-02-24 11:36:49 -0800879 blacklisted_protos = [":_internal_wkt_protos_genrule"],
cgrushko45d92ae2016-12-02 19:40:50 -0500880)
cgrushkoe4baf3f2017-01-12 12:51:04 -0500881
882proto_lang_toolchain(
883 name = "java_toolchain",
884 command_line = "--java_out=$(OUT)",
885 runtime = ":protobuf_java",
886 visibility = ["//visibility:public"],
887)
makdharma286f0592017-05-01 09:49:26 -0700888
Thomas Van Lenten18aa2962018-11-01 09:37:14 -0400889alias(
890 name = "objectivec",
891 actual = ":protobuf_objc",
892 visibility = ["//visibility:public"],
893)
makdharma286f0592017-05-01 09:49:26 -0700894
895objc_library(
Thomas Van Lenten18aa2962018-11-01 09:37:14 -0400896 name = "protobuf_objc",
897 hdrs = [
898 "objectivec/GPBArray.h",
899 "objectivec/GPBBootstrap.h",
900 "objectivec/GPBCodedInputStream.h",
901 "objectivec/GPBCodedOutputStream.h",
902 "objectivec/GPBDescriptor.h",
903 "objectivec/GPBDictionary.h",
904 "objectivec/GPBExtensionInternals.h",
905 "objectivec/GPBExtensionRegistry.h",
906 "objectivec/GPBMessage.h",
907 "objectivec/GPBProtocolBuffers.h",
908 "objectivec/GPBProtocolBuffers_RuntimeSupport.h",
909 "objectivec/GPBRootObject.h",
910 "objectivec/GPBRuntimeTypes.h",
911 "objectivec/GPBUnknownField.h",
912 "objectivec/GPBUnknownFieldSet.h",
913 "objectivec/GPBUtilities.h",
914 "objectivec/GPBWellKnownTypes.h",
915 "objectivec/GPBWireFormat.h",
916 "objectivec/google/protobuf/Any.pbobjc.h",
917 "objectivec/google/protobuf/Api.pbobjc.h",
918 "objectivec/google/protobuf/Duration.pbobjc.h",
919 "objectivec/google/protobuf/Empty.pbobjc.h",
920 "objectivec/google/protobuf/FieldMask.pbobjc.h",
921 "objectivec/google/protobuf/SourceContext.pbobjc.h",
922 "objectivec/google/protobuf/Struct.pbobjc.h",
923 "objectivec/google/protobuf/Timestamp.pbobjc.h",
924 "objectivec/google/protobuf/Type.pbobjc.h",
925 "objectivec/google/protobuf/Wrappers.pbobjc.h",
926 # Package private headers, but exposed because the generated sources
927 # need to use them.
928 "objectivec/GPBArray_PackagePrivate.h",
929 "objectivec/GPBCodedInputStream_PackagePrivate.h",
930 "objectivec/GPBCodedOutputStream_PackagePrivate.h",
931 "objectivec/GPBDescriptor_PackagePrivate.h",
932 "objectivec/GPBDictionary_PackagePrivate.h",
933 "objectivec/GPBMessage_PackagePrivate.h",
934 "objectivec/GPBRootObject_PackagePrivate.h",
935 "objectivec/GPBUnknownFieldSet_PackagePrivate.h",
936 "objectivec/GPBUnknownField_PackagePrivate.h",
937 "objectivec/GPBUtilities_PackagePrivate.h",
938 ],
Benjamin Barenblat048f5c22018-07-11 13:20:01 -0400939 copts = [
940 "-Wno-vla",
941 ],
makdharma286f0592017-05-01 09:49:26 -0700942 includes = [
943 "objectivec",
944 ],
Thomas Van Lenten18aa2962018-11-01 09:37:14 -0400945 non_arc_srcs = [
946 "objectivec/GPBArray.m",
947 "objectivec/GPBCodedInputStream.m",
948 "objectivec/GPBCodedOutputStream.m",
949 "objectivec/GPBDescriptor.m",
950 "objectivec/GPBDictionary.m",
951 "objectivec/GPBExtensionInternals.m",
952 "objectivec/GPBExtensionRegistry.m",
953 "objectivec/GPBMessage.m",
954 "objectivec/GPBRootObject.m",
955 "objectivec/GPBUnknownField.m",
956 "objectivec/GPBUnknownFieldSet.m",
957 "objectivec/GPBUtilities.m",
958 "objectivec/GPBWellKnownTypes.m",
959 "objectivec/GPBWireFormat.m",
960 "objectivec/google/protobuf/Any.pbobjc.m",
961 "objectivec/google/protobuf/Api.pbobjc.m",
962 "objectivec/google/protobuf/Duration.pbobjc.m",
963 "objectivec/google/protobuf/Empty.pbobjc.m",
964 "objectivec/google/protobuf/FieldMask.pbobjc.m",
965 "objectivec/google/protobuf/SourceContext.pbobjc.m",
966 "objectivec/google/protobuf/Struct.pbobjc.m",
967 "objectivec/google/protobuf/Timestamp.pbobjc.m",
968 "objectivec/google/protobuf/Type.pbobjc.m",
969 "objectivec/google/protobuf/Wrappers.pbobjc.m",
970 ],
makdharma286f0592017-05-01 09:49:26 -0700971 visibility = ["//visibility:public"],
972)
Fahrzin Hemmati0d68b292018-03-26 19:08:26 -0700973
974################################################################################
975# Test generated proto support
976################################################################################
977
978genrule(
979 name = "generated_protos",
980 srcs = ["src/google/protobuf/unittest_import.proto"],
981 outs = ["unittest_gen.proto"],
982 cmd = "cat $(SRCS) | sed 's|google/|src/google/|' > $(OUTS)"
983)
984
985proto_library(
986 name = "generated_protos_proto",
Fahrzin Hemmati55962db2018-05-07 17:36:34 -0700987 srcs = [
988 "unittest_gen.proto",
989 "src/google/protobuf/unittest_import_public.proto",
990 ],
Fahrzin Hemmati0d68b292018-03-26 19:08:26 -0700991)
992
Fahrzin Hemmati0d68b292018-03-26 19:08:26 -0700993py_proto_library(
994 name = "generated_protos_py",
995 srcs = [
996 "unittest_gen.proto",
997 "src/google/protobuf/unittest_import_public.proto",
998 ],
999 default_runtime = "",
1000 protoc = ":protoc",
1001)
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001002
1003################################################################################
1004# Conformance tests
1005################################################################################
1006
1007proto_library(
1008 name = "test_messages_proto2_proto",
Joshua Haberman2996da42019-05-13 07:45:30 -07001009 srcs = ["src/google/protobuf/test_messages_proto2.proto"],
Josh Haberman25feb592018-11-03 14:43:20 -07001010 visibility = ["//visibility:public"],
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001011)
1012
1013proto_library(
1014 name = "test_messages_proto3_proto",
Joshua Haberman2996da42019-05-13 07:45:30 -07001015 srcs = ["src/google/protobuf/test_messages_proto3.proto"],
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001016 deps = [
1017 ":any_proto",
1018 ":duration_proto",
1019 ":field_mask_proto",
1020 ":struct_proto",
1021 ":timestamp_proto",
1022 ":wrappers_proto",
1023 ],
Josh Haberman25feb592018-11-03 14:43:20 -07001024 visibility = ["//visibility:public"],
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001025)
1026
1027cc_proto_library(
1028 name = "test_messages_proto2_proto_cc",
Joshua Haberman2996da42019-05-13 07:45:30 -07001029 srcs = ["src/google/protobuf/test_messages_proto2.proto"],
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001030)
1031
1032cc_proto_library(
1033 name = "test_messages_proto3_proto_cc",
Joshua Haberman2996da42019-05-13 07:45:30 -07001034 srcs = ["src/google/protobuf/test_messages_proto3.proto"],
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001035 deps = [
1036 ":cc_wkt_protos",
1037 ],
1038)
1039
1040proto_library(
1041 name = "conformance_proto",
Joshua Haberman2996da42019-05-13 07:45:30 -07001042 srcs = ["conformance/conformance.proto"],
Josh Haberman25feb592018-11-03 14:43:20 -07001043 visibility = ["//visibility:public"],
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001044)
1045
1046cc_proto_library(
1047 name = "conformance_proto_cc",
1048 srcs = ["conformance/conformance.proto"],
1049)
1050
1051cc_library(
1052 name = "jsoncpp",
1053 hdrs = ["conformance/third_party/jsoncpp/json.h"],
1054 srcs = ["conformance/third_party/jsoncpp/jsoncpp.cpp"],
1055 includes = ["conformance"],
1056)
1057
1058cc_library(
1059 name = "conformance_test",
1060 srcs = [
1061 "conformance/conformance_test.cc",
Joshua Haberman2996da42019-05-13 07:45:30 -07001062 "conformance/conformance_test_runner.cc",
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001063 ],
1064 hdrs = [
1065 "conformance/conformance_test.h",
1066 ],
Joshua Haberman2996da42019-05-13 07:45:30 -07001067 deps = [":conformance_proto_cc"],
1068 includes = ["conformance", "src"],
1069)
1070
1071cc_library(
1072 name = "binary_json_conformance_suite",
1073 srcs = ["conformance/binary_json_conformance_suite.cc"],
1074 hdrs = ["conformance/binary_json_conformance_suite.h"],
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001075 deps = [
Joshua Haberman2996da42019-05-13 07:45:30 -07001076 ":conformance_test",
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001077 ":jsoncpp",
1078 ":test_messages_proto2_proto_cc",
1079 ":test_messages_proto3_proto_cc",
1080 ],
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001081)
1082
Joshua Haberman2996da42019-05-13 07:45:30 -07001083cc_library(
1084 name = "text_format_conformance_suite",
1085 srcs = ["conformance/text_format_conformance_suite.cc"],
1086 hdrs = ["conformance/text_format_conformance_suite.h"],
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001087 deps = [
1088 ":conformance_test",
Joshua Haberman2996da42019-05-13 07:45:30 -07001089 ":test_messages_proto2_proto_cc",
1090 ":test_messages_proto3_proto_cc",
1091 ],
1092)
1093
Joshua Habermanc659a4a2019-05-14 14:01:16 -07001094cc_binary(
Joshua Haberman2996da42019-05-13 07:45:30 -07001095 name = "conformance_test_runner",
1096 srcs = ["conformance/conformance_test_main.cc"],
1097 deps = [
1098 ":binary_json_conformance_suite",
1099 ":conformance_test",
1100 ":text_format_conformance_suite",
Josh Haberman25feb592018-11-03 14:43:20 -07001101 ],
1102 visibility = ["//visibility:public"],
Josh Haberman6dec8cf2018-11-03 12:59:45 -07001103)