blob: 76a73f566967a97520b1747a62b2d4bdf10ba44f [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################################################################################
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -070019# Protobuf Runtime Library
20################################################################################
21
Pascal Muetscharda6957f22018-03-22 13:14:10 -070022MSVC_COPTS = [
Yun Peng0b059a32017-05-31 14:01:23 +020023 "/DHAVE_PTHREAD",
24 "/wd4018", # -Wno-sign-compare
Loo Rong Jie0456e262018-06-06 10:03:25 +080025 "/wd4065", # switch statement contains 'default' but no 'case' labels
26 "/wd4146", # unary minus operator applied to unsigned type, result still unsigned
27 "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data
28 "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
29 "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data
30 "/wd4305", # 'identifier' : truncation from 'type1' to 'type2'
31 "/wd4307", # 'operator' : integral constant overflow
32 "/wd4309", # 'conversion' : truncation of constant value
33 "/wd4334", # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
34 "/wd4355", # 'this' : used in base member initializer list
35 "/wd4506", # no definition for inline function 'function'
Yun Peng0b059a32017-05-31 14:01:23 +020036 "/wd4514", # -Wno-unused-function
Loo Rong Jie0456e262018-06-06 10:03:25 +080037 "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning)
38 "/wd4996", # The compiler encountered a deprecated declaration.
Jisi Liud19604f2015-06-17 17:37:58 -070039]
40
Yun Peng0b059a32017-05-31 14:01:23 +020041COPTS = select({
Pascal Muetscharda6957f22018-03-22 13:14:10 -070042 ":msvc" : MSVC_COPTS,
Yun Peng0b059a32017-05-31 14:01:23 +020043 "//conditions:default": [
44 "-DHAVE_PTHREAD",
45 "-Wall",
Yun Peng0b059a32017-05-31 14:01:23 +020046 "-Woverloaded-virtual",
47 "-Wno-sign-compare",
48 "-Wno-unused-function",
Justine Tunneyac5371d2017-11-17 18:27:39 -080049 # Prevents ISO C++ const string assignment warnings for pyext sources.
50 "-Wno-writable-strings",
depristo2506cf52018-06-28 22:54:43 +000051 "-Wno-write-strings",
Yun Peng0b059a32017-05-31 14:01:23 +020052 ],
53})
54
scentinib30ddee2018-08-28 14:07:55 +020055load(":compiler_config_setting.bzl", "create_compiler_config_setting")
56
57create_compiler_config_setting(name = "msvc", value = "msvc-cl")
Yun Peng0b059a32017-05-31 14:01:23 +020058
Andrew Harpb56b4612016-04-04 15:13:30 -040059config_setting(
60 name = "android",
61 values = {
62 "crosstool_top": "//external:android/crosstool",
63 },
64)
65
Pascal Muetscharda6957f22018-03-22 13:14:10 -070066# Android and MSVC builds do not need to link in a separate pthread library.
Andrew Harpb56b4612016-04-04 15:13:30 -040067LINK_OPTS = select({
Andrew Harp3b4e7dc2016-04-04 16:13:31 -040068 ":android": [],
Jan Tattermuschccc56a32018-05-24 09:51:53 -070069 ":msvc": [
Loo Rong Jie0456e262018-06-06 10:03:25 +080070 # Suppress linker warnings about files with no symbols defined.
71 "-ignore:4221",
Laszlo Csomor55171682017-12-01 12:05:32 +010072 ],
Daniel Ylitalo32fa55e2017-01-25 22:04:11 +010073 "//conditions:default": ["-lpthread", "-lm"],
Andrew Harpb56b4612016-04-04 15:13:30 -040074})
Jisi Liud19604f2015-06-17 17:37:58 -070075
Jisi Liu04658a32015-10-20 15:00:13 -070076load(
cgrushko65a4d202017-02-08 15:23:57 -050077 ":protobuf.bzl",
Jisi Liu04658a32015-10-20 15:00:13 -070078 "cc_proto_library",
79 "py_proto_library",
David Z. Chen02cd45c2016-05-20 16:49:04 -070080 "internal_copied_filegroup",
Steven Parkesea188662016-02-25 07:53:19 -080081 "internal_gen_well_known_protos_java",
Jisi Liu04658a32015-10-20 15:00:13 -070082 "internal_protobuf_py_tests",
83)
Jisi Liu39362b32015-10-14 17:12:11 -070084
Jisi Liud19604f2015-06-17 17:37:58 -070085cc_library(
86 name = "protobuf_lite",
87 srcs = [
88 # AUTOGEN(protobuf_lite_srcs)
89 "src/google/protobuf/arena.cc",
90 "src/google/protobuf/arenastring.cc",
91 "src/google/protobuf/extension_set.cc",
Jisi Liu12c186f2017-07-25 14:38:00 -070092 "src/google/protobuf/generated_message_table_driven_lite.cc",
Jisi Liud19604f2015-06-17 17:37:58 -070093 "src/google/protobuf/generated_message_util.cc",
Adam Cozzette609d7522017-12-07 14:16:50 -080094 "src/google/protobuf/implicit_weak_message.cc",
Jisi Liud19604f2015-06-17 17:37:58 -070095 "src/google/protobuf/io/coded_stream.cc",
96 "src/google/protobuf/io/zero_copy_stream.cc",
97 "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
98 "src/google/protobuf/message_lite.cc",
99 "src/google/protobuf/repeated_field.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700100 "src/google/protobuf/stubs/bytestream.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700101 "src/google/protobuf/stubs/common.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700102 "src/google/protobuf/stubs/int128.cc",
Jisi Liu759245a2017-07-25 11:52:33 -0700103 "src/google/protobuf/stubs/io_win32.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700104 "src/google/protobuf/stubs/status.cc",
105 "src/google/protobuf/stubs/statusor.cc",
106 "src/google/protobuf/stubs/stringpiece.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700107 "src/google/protobuf/stubs/stringprintf.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700108 "src/google/protobuf/stubs/structurally_valid.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700109 "src/google/protobuf/stubs/strutil.cc",
110 "src/google/protobuf/stubs/time.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700111 "src/google/protobuf/wire_format_lite.cc",
112 ],
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700113 hdrs = glob(["src/google/protobuf/**/*.h", "src/google/protobuf/**/*.inc"]),
Param Reddy16792c62017-10-15 13:06:58 -0700114 copts = COPTS,
Jisi Liud19604f2015-06-17 17:37:58 -0700115 includes = ["src/"],
116 linkopts = LINK_OPTS,
117 visibility = ["//visibility:public"],
118)
119
120cc_library(
121 name = "protobuf",
122 srcs = [
123 # AUTOGEN(protobuf_srcs)
124 "src/google/protobuf/any.cc",
125 "src/google/protobuf/any.pb.cc",
126 "src/google/protobuf/api.pb.cc",
127 "src/google/protobuf/compiler/importer.cc",
128 "src/google/protobuf/compiler/parser.cc",
129 "src/google/protobuf/descriptor.cc",
130 "src/google/protobuf/descriptor.pb.cc",
131 "src/google/protobuf/descriptor_database.cc",
132 "src/google/protobuf/duration.pb.cc",
133 "src/google/protobuf/dynamic_message.cc",
134 "src/google/protobuf/empty.pb.cc",
135 "src/google/protobuf/extension_set_heavy.cc",
136 "src/google/protobuf/field_mask.pb.cc",
137 "src/google/protobuf/generated_message_reflection.cc",
Jisi Liu759245a2017-07-25 11:52:33 -0700138 "src/google/protobuf/generated_message_table_driven.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700139 "src/google/protobuf/io/gzip_stream.cc",
140 "src/google/protobuf/io/printer.cc",
141 "src/google/protobuf/io/strtod.cc",
142 "src/google/protobuf/io/tokenizer.cc",
143 "src/google/protobuf/io/zero_copy_stream_impl.cc",
144 "src/google/protobuf/map_field.cc",
145 "src/google/protobuf/message.cc",
146 "src/google/protobuf/reflection_ops.cc",
147 "src/google/protobuf/service.cc",
148 "src/google/protobuf/source_context.pb.cc",
149 "src/google/protobuf/struct.pb.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700150 "src/google/protobuf/stubs/mathlimits.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700151 "src/google/protobuf/stubs/substitute.cc",
152 "src/google/protobuf/text_format.cc",
153 "src/google/protobuf/timestamp.pb.cc",
154 "src/google/protobuf/type.pb.cc",
155 "src/google/protobuf/unknown_field_set.cc",
Bairen Yi312e2db2017-03-21 03:52:37 +0800156 "src/google/protobuf/util/delimited_message_util.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700157 "src/google/protobuf/util/field_comparator.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700158 "src/google/protobuf/util/field_mask_util.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700159 "src/google/protobuf/util/internal/datapiece.cc",
160 "src/google/protobuf/util/internal/default_value_objectwriter.cc",
161 "src/google/protobuf/util/internal/error_listener.cc",
162 "src/google/protobuf/util/internal/field_mask_utility.cc",
163 "src/google/protobuf/util/internal/json_escaping.cc",
164 "src/google/protobuf/util/internal/json_objectwriter.cc",
165 "src/google/protobuf/util/internal/json_stream_parser.cc",
166 "src/google/protobuf/util/internal/object_writer.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800167 "src/google/protobuf/util/internal/proto_writer.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700168 "src/google/protobuf/util/internal/protostream_objectsource.cc",
169 "src/google/protobuf/util/internal/protostream_objectwriter.cc",
170 "src/google/protobuf/util/internal/type_info.cc",
171 "src/google/protobuf/util/internal/type_info_test_helper.cc",
172 "src/google/protobuf/util/internal/utility.cc",
173 "src/google/protobuf/util/json_util.cc",
174 "src/google/protobuf/util/message_differencer.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700175 "src/google/protobuf/util/time_util.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700176 "src/google/protobuf/util/type_resolver_util.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700177 "src/google/protobuf/wire_format.cc",
178 "src/google/protobuf/wrappers.pb.cc",
179 ],
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700180 hdrs = glob(["src/**/*.h", "src/**/*.inc"]),
Param Reddy16792c62017-10-15 13:06:58 -0700181 copts = COPTS,
Jisi Liud19604f2015-06-17 17:37:58 -0700182 includes = ["src/"],
183 linkopts = LINK_OPTS,
184 visibility = ["//visibility:public"],
185 deps = [":protobuf_lite"],
186)
187
Manjunath Kudlur6837b2d2017-03-02 18:02:05 -0800188# This provides just the header files for use in projects that need to build
189# shared libraries for dynamic loading. This target is available until Bazel
190# adds native support for such use cases.
191# TODO(keveman): Remove this target once the support gets added to Bazel.
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800192cc_library(
193 name = "protobuf_headers",
194 hdrs = glob(["src/**/*.h"]),
195 includes = ["src/"],
196 visibility = ["//visibility:public"],
197)
198
Jakob Buchgraber699c0eb2017-09-05 17:15:10 +0200199# Map of all well known protos.
200# name => (include path, imports)
201WELL_KNOWN_PROTO_MAP = {
202 "any" : ("google/protobuf/any.proto", []),
203 "api" : ("google/protobuf/api.proto", ["source_context", "type"]),
204 "compiler_plugin" : ("google/protobuf/compiler/plugin.proto", ["descriptor"]),
205 "descriptor" : ("google/protobuf/descriptor.proto", []),
206 "duration" : ("google/protobuf/duration.proto", []),
207 "empty" : ("google/protobuf/empty.proto", []),
208 "field_mask" : ("google/protobuf/field_mask.proto", []),
209 "source_context" : ("google/protobuf/source_context.proto", []),
210 "struct" : ("google/protobuf/struct.proto", []),
211 "timestamp" : ("google/protobuf/timestamp.proto", []),
212 "type" : ("google/protobuf/type.proto", ["any", "source_context"]),
213 "wrappers" : ("google/protobuf/wrappers.proto", []),
214}
215
216RELATIVE_WELL_KNOWN_PROTOS = [proto[1][0] for proto in WELL_KNOWN_PROTO_MAP.items()]
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700217
Jisi Liu993fb702015-10-19 17:19:49 -0700218WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
219
Steven Parkesd5a57322016-03-22 17:56:07 -0700220filegroup(
221 name = "well_known_protos",
222 srcs = WELL_KNOWN_PROTOS,
223 visibility = ["//visibility:public"],
224)
225
Jisi Liu39362b32015-10-14 17:12:11 -0700226cc_proto_library(
227 name = "cc_wkt_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700228 srcs = WELL_KNOWN_PROTOS,
Jisi Liu3101e732015-10-16 12:46:26 -0700229 include = "src",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800230 default_runtime = ":protobuf",
Jisi Liu993fb702015-10-19 17:19:49 -0700231 internal_bootstrap_hack = 1,
Jisi Liu04658a32015-10-20 15:00:13 -0700232 protoc = ":protoc",
Jisi Liu6a40bf82015-11-17 12:36:21 -0800233 visibility = ["//visibility:public"],
Jisi Liu39362b32015-10-14 17:12:11 -0700234)
235
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700236################################################################################
Jakob Buchgraber699c0eb2017-09-05 17:15:10 +0200237# Well Known Types Proto Library Rules
238#
239# These proto_library rules can be used with one of the language specific proto
240# library rules i.e. java_proto_library:
241#
242# java_proto_library(
243# name = "any_java_proto",
244# deps = ["@com_google_protobuf//:any_proto],
245# )
246################################################################################
247
248internal_copied_filegroup(
249 name = "_internal_wkt_protos",
250 srcs = WELL_KNOWN_PROTOS,
251 dest = "",
252 strip_prefix = "src",
James O'Kane950f5e42018-03-08 22:30:44 -0800253 visibility = ["//visibility:private"],
Jakob Buchgraber699c0eb2017-09-05 17:15:10 +0200254)
255
256[proto_library(
257 name = proto[0] + "_proto",
258 srcs = [proto[1][0]],
259 deps = [dep + "_proto" for dep in proto[1][1]],
260 visibility = ["//visibility:public"],
261 ) for proto in WELL_KNOWN_PROTO_MAP.items()]
262
263################################################################################
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700264# Protocol Buffers Compiler
265################################################################################
266
Jisi Liud19604f2015-06-17 17:37:58 -0700267cc_library(
268 name = "protoc_lib",
269 srcs = [
270 # AUTOGEN(protoc_lib_srcs)
271 "src/google/protobuf/compiler/code_generator.cc",
272 "src/google/protobuf/compiler/command_line_interface.cc",
273 "src/google/protobuf/compiler/cpp/cpp_enum.cc",
274 "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
275 "src/google/protobuf/compiler/cpp/cpp_extension.cc",
276 "src/google/protobuf/compiler/cpp/cpp_field.cc",
277 "src/google/protobuf/compiler/cpp/cpp_file.cc",
278 "src/google/protobuf/compiler/cpp/cpp_generator.cc",
279 "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
280 "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
281 "src/google/protobuf/compiler/cpp/cpp_message.cc",
282 "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
Adam Cozzette13fd0452017-09-12 10:32:01 -0700283 "src/google/protobuf/compiler/cpp/cpp_padding_optimizer.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700284 "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
285 "src/google/protobuf/compiler/cpp/cpp_service.cc",
286 "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
Ming Zhao5cdd9362015-10-05 14:37:21 -0700287 "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700288 "src/google/protobuf/compiler/csharp/csharp_enum.cc",
289 "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700290 "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
291 "src/google/protobuf/compiler/csharp/csharp_generator.cc",
292 "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
Jon Skeetb2ac8682015-07-15 13:17:42 +0100293 "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700294 "src/google/protobuf/compiler/csharp/csharp_message.cc",
295 "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
296 "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
Jon Skeeta6361a12015-11-19 13:05:17 +0000297 "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700298 "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
299 "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
300 "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
301 "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
Jon Skeetb2ac8682015-07-15 13:17:42 +0100302 "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700303 "src/google/protobuf/compiler/java/java_context.cc",
304 "src/google/protobuf/compiler/java/java_doc_comment.cc",
305 "src/google/protobuf/compiler/java/java_enum.cc",
306 "src/google/protobuf/compiler/java/java_enum_field.cc",
307 "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700308 "src/google/protobuf/compiler/java/java_enum_lite.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700309 "src/google/protobuf/compiler/java/java_extension.cc",
Jisi Liu1f4f3e22016-04-18 14:12:08 -0700310 "src/google/protobuf/compiler/java/java_extension_lite.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700311 "src/google/protobuf/compiler/java/java_field.cc",
312 "src/google/protobuf/compiler/java/java_file.cc",
313 "src/google/protobuf/compiler/java/java_generator.cc",
314 "src/google/protobuf/compiler/java/java_generator_factory.cc",
315 "src/google/protobuf/compiler/java/java_helpers.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700316 "src/google/protobuf/compiler/java/java_map_field.cc",
317 "src/google/protobuf/compiler/java/java_map_field_lite.cc",
318 "src/google/protobuf/compiler/java/java_message.cc",
319 "src/google/protobuf/compiler/java/java_message_builder.cc",
320 "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
321 "src/google/protobuf/compiler/java/java_message_field.cc",
322 "src/google/protobuf/compiler/java/java_message_field_lite.cc",
323 "src/google/protobuf/compiler/java/java_message_lite.cc",
324 "src/google/protobuf/compiler/java/java_name_resolver.cc",
325 "src/google/protobuf/compiler/java/java_primitive_field.cc",
326 "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
327 "src/google/protobuf/compiler/java/java_service.cc",
328 "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
329 "src/google/protobuf/compiler/java/java_string_field.cc",
330 "src/google/protobuf/compiler/java/java_string_field_lite.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800331 "src/google/protobuf/compiler/js/js_generator.cc",
Jisi Liuf92b4552016-12-05 10:16:47 -0800332 "src/google/protobuf/compiler/js/well_known_types_embed.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700333 "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
334 "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
335 "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
336 "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
337 "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
338 "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
339 "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
340 "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
341 "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
342 "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
343 "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
344 "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
Jisi Liud9473082016-09-22 15:14:58 -0700345 "src/google/protobuf/compiler/php/php_generator.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700346 "src/google/protobuf/compiler/plugin.cc",
Feng Xiaofd595fc2018-03-01 16:36:05 -0800347 "src/google/protobuf/compiler/plugin.pb.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700348 "src/google/protobuf/compiler/python/python_generator.cc",
349 "src/google/protobuf/compiler/ruby/ruby_generator.cc",
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700350 "src/google/protobuf/compiler/scc.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700351 "src/google/protobuf/compiler/subprocess.cc",
352 "src/google/protobuf/compiler/zip_writer.cc",
353 ],
354 copts = COPTS,
355 includes = ["src/"],
Loo Rong Jie0456e262018-06-06 10:03:25 +0800356 linkopts = LINK_OPTS + select({
357 ":msvc": [
358 # Linking to setargv.obj makes the default command line argument
359 # parser expand wildcards, so the main method's argv will contain the
360 # expanded list instead of the wildcards.
361 #
362 # Adding dummy "-DEFAULTLIB:kernel32.lib", because:
363 # - Microsoft ships this object file next to default libraries
364 # - but this file is not a library, just a precompiled object
365 # - "-WHOLEARCHIVE" and "-DEFAULTLIB" only accept library,
366 # not precompiled object.
367 # - Bazel would assume linkopt that does not start with "-" or "$"
368 # as a label to a target, so we add a harmless "-DEFAULTLIB:kernel32.lib"
369 # before "setargv.obj".
370 # See https://msdn.microsoft.com/en-us/library/8bch7bkk.aspx
371 "-DEFAULTLIB:kernel32.lib setargv.obj",
372 ],
373 "//conditions:default": [],
374 }),
Jisi Liud19604f2015-06-17 17:37:58 -0700375 visibility = ["//visibility:public"],
376 deps = [":protobuf"],
377)
378
379cc_binary(
380 name = "protoc",
381 srcs = ["src/google/protobuf/compiler/main.cc"],
Jisi Liud19604f2015-06-17 17:37:58 -0700382 linkopts = LINK_OPTS,
383 visibility = ["//visibility:public"],
384 deps = [":protoc_lib"],
385)
386
Jisi Liud19604f2015-06-17 17:37:58 -0700387################################################################################
388# Tests
389################################################################################
390
Jisi Liu993fb702015-10-19 17:19:49 -0700391RELATIVE_LITE_TEST_PROTOS = [
Jisi Liud19604f2015-06-17 17:37:58 -0700392 # AUTOGEN(lite_test_protos)
393 "google/protobuf/map_lite_unittest.proto",
394 "google/protobuf/unittest_import_lite.proto",
395 "google/protobuf/unittest_import_public_lite.proto",
396 "google/protobuf/unittest_lite.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700397 "google/protobuf/unittest_no_arena_lite.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700398]
399
Jisi Liu993fb702015-10-19 17:19:49 -0700400LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
401
402RELATIVE_TEST_PROTOS = [
Jisi Liud19604f2015-06-17 17:37:58 -0700403 # AUTOGEN(test_protos)
404 "google/protobuf/any_test.proto",
405 "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
406 "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
407 "google/protobuf/map_proto2_unittest.proto",
408 "google/protobuf/map_unittest.proto",
409 "google/protobuf/unittest.proto",
410 "google/protobuf/unittest_arena.proto",
411 "google/protobuf/unittest_custom_options.proto",
412 "google/protobuf/unittest_drop_unknown_fields.proto",
413 "google/protobuf/unittest_embed_optimize_for.proto",
414 "google/protobuf/unittest_empty.proto",
415 "google/protobuf/unittest_enormous_descriptor.proto",
416 "google/protobuf/unittest_import.proto",
417 "google/protobuf/unittest_import_public.proto",
Feng Xiao32d78302017-03-29 14:01:40 -0700418 "google/protobuf/unittest_lazy_dependencies.proto",
419 "google/protobuf/unittest_lazy_dependencies_custom_option.proto",
420 "google/protobuf/unittest_lazy_dependencies_enum.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700421 "google/protobuf/unittest_lite_imports_nonlite.proto",
422 "google/protobuf/unittest_mset.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700423 "google/protobuf/unittest_mset_wire_format.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700424 "google/protobuf/unittest_no_arena.proto",
425 "google/protobuf/unittest_no_arena_import.proto",
426 "google/protobuf/unittest_no_field_presence.proto",
427 "google/protobuf/unittest_no_generic_services.proto",
428 "google/protobuf/unittest_optimize_for.proto",
429 "google/protobuf/unittest_preserve_unknown_enum.proto",
430 "google/protobuf/unittest_preserve_unknown_enum2.proto",
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700431 "google/protobuf/unittest_proto3.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700432 "google/protobuf/unittest_proto3_arena.proto",
Chad Whipkeybaf52bd2016-04-15 09:23:50 -0700433 "google/protobuf/unittest_proto3_arena_lite.proto",
434 "google/protobuf/unittest_proto3_lite.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700435 "google/protobuf/unittest_well_known_types.proto",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700436 "google/protobuf/util/internal/testdata/anys.proto",
437 "google/protobuf/util/internal/testdata/books.proto",
438 "google/protobuf/util/internal/testdata/default_value.proto",
439 "google/protobuf/util/internal/testdata/default_value_test.proto",
440 "google/protobuf/util/internal/testdata/field_mask.proto",
441 "google/protobuf/util/internal/testdata/maps.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700442 "google/protobuf/util/internal/testdata/oneofs.proto",
Jisi Liu9d4657a2016-09-22 15:11:17 -0700443 "google/protobuf/util/internal/testdata/proto3.proto",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700444 "google/protobuf/util/internal/testdata/struct.proto",
445 "google/protobuf/util/internal/testdata/timestamp_duration.proto",
Jisi Liu9d4657a2016-09-22 15:11:17 -0700446 "google/protobuf/util/internal/testdata/wrappers.proto",
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700447 "google/protobuf/util/json_format.proto",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700448 "google/protobuf/util/json_format_proto3.proto",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800449 "google/protobuf/util/message_differencer_unittest.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700450]
451
Jisi Liu993fb702015-10-19 17:19:49 -0700452TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
453
Jisi Liu39362b32015-10-14 17:12:11 -0700454cc_proto_library(
455 name = "cc_test_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700456 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
Jisi Liu3101e732015-10-16 12:46:26 -0700457 include = "src",
Jisi Liube92ffb2015-10-27 15:11:38 -0700458 default_runtime = ":protobuf",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800459 protoc = ":protoc",
Jisi Liud8701b52015-10-16 11:44:21 -0700460 deps = [":cc_wkt_protos"],
Jisi Liud19604f2015-06-17 17:37:58 -0700461)
462
463COMMON_TEST_SRCS = [
464 # AUTOGEN(common_test_srcs)
465 "src/google/protobuf/arena_test_util.cc",
466 "src/google/protobuf/map_test_util.cc",
467 "src/google/protobuf/test_util.cc",
Adam Cozzette5bed3682018-03-23 10:19:04 -0700468 "src/google/protobuf/test_util.inc",
Jisi Liud19604f2015-06-17 17:37:58 -0700469 "src/google/protobuf/testing/file.cc",
470 "src/google/protobuf/testing/googletest.cc",
471]
472
Jisi Liu7a0c4312015-06-18 16:45:27 -0700473cc_binary(
474 name = "test_plugin",
475 srcs = [
476 # AUTOGEN(test_plugin_srcs)
477 "src/google/protobuf/compiler/mock_code_generator.cc",
478 "src/google/protobuf/compiler/test_plugin.cc",
479 "src/google/protobuf/testing/file.cc",
480 ],
481 deps = [
482 ":protobuf",
483 ":protoc_lib",
484 "//external:gtest",
485 ],
486)
487
488cc_test(
Jisi Liu759245a2017-07-25 11:52:33 -0700489 name = "win32_test",
490 srcs = ["src/google/protobuf/stubs/io_win32_unittest.cc"],
491 deps = [
492 ":protobuf_lite",
493 "//external:gtest_main",
494 ],
495 tags = ["manual", "windows"],
496)
497
498cc_test(
Jisi Liu7a0c4312015-06-18 16:45:27 -0700499 name = "protobuf_test",
Jisi Liu39362b32015-10-14 17:12:11 -0700500 srcs = COMMON_TEST_SRCS + [
Jisi Liu7a0c4312015-06-18 16:45:27 -0700501 # AUTOGEN(test_srcs)
502 "src/google/protobuf/any_test.cc",
503 "src/google/protobuf/arena_unittest.cc",
504 "src/google/protobuf/arenastring_unittest.cc",
Jisi Liu1c682e02017-10-18 14:31:23 -0700505 "src/google/protobuf/compiler/annotation_test_util.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700506 "src/google/protobuf/compiler/command_line_interface_unittest.cc",
507 "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
Jisi Liu11b66612017-07-19 12:10:43 -0700508 "src/google/protobuf/compiler/cpp/cpp_move_unittest.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700509 "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
510 "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
Adam Cozzette5bed3682018-03-23 10:19:04 -0700511 "src/google/protobuf/compiler/cpp/cpp_unittest.inc",
Jisi Liu1f4f3e22016-04-18 14:12:08 -0700512 "src/google/protobuf/compiler/cpp/metadata_test.cc",
Feng Xiao32d78302017-03-29 14:01:40 -0700513 "src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700514 "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
515 "src/google/protobuf/compiler/importer_unittest.cc",
516 "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
517 "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
518 "src/google/protobuf/compiler/mock_code_generator.cc",
519 "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
520 "src/google/protobuf/compiler/parser_unittest.cc",
521 "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
522 "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
523 "src/google/protobuf/descriptor_database_unittest.cc",
524 "src/google/protobuf/descriptor_unittest.cc",
525 "src/google/protobuf/drop_unknown_fields_test.cc",
526 "src/google/protobuf/dynamic_message_unittest.cc",
527 "src/google/protobuf/extension_set_unittest.cc",
528 "src/google/protobuf/generated_message_reflection_unittest.cc",
529 "src/google/protobuf/io/coded_stream_unittest.cc",
530 "src/google/protobuf/io/printer_unittest.cc",
531 "src/google/protobuf/io/tokenizer_unittest.cc",
532 "src/google/protobuf/io/zero_copy_stream_unittest.cc",
533 "src/google/protobuf/map_field_test.cc",
534 "src/google/protobuf/map_test.cc",
535 "src/google/protobuf/message_unittest.cc",
Adam Cozzette5bed3682018-03-23 10:19:04 -0700536 "src/google/protobuf/message_unittest.inc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700537 "src/google/protobuf/no_field_presence_test.cc",
538 "src/google/protobuf/preserve_unknown_enum_test.cc",
Chad Whipkeybaf52bd2016-04-15 09:23:50 -0700539 "src/google/protobuf/proto3_arena_lite_unittest.cc",
Jisi Liuf86d39c2016-04-28 14:43:22 -0700540 "src/google/protobuf/proto3_arena_unittest.cc",
Chad Whipkeybaf52bd2016-04-15 09:23:50 -0700541 "src/google/protobuf/proto3_lite_unittest.cc",
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700542 "src/google/protobuf/proto3_lite_unittest.inc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700543 "src/google/protobuf/reflection_ops_unittest.cc",
544 "src/google/protobuf/repeated_field_reflection_unittest.cc",
545 "src/google/protobuf/repeated_field_unittest.cc",
546 "src/google/protobuf/stubs/bytestream_unittest.cc",
547 "src/google/protobuf/stubs/common_unittest.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700548 "src/google/protobuf/stubs/int128_unittest.cc",
Jisi Liu759245a2017-07-25 11:52:33 -0700549 "src/google/protobuf/stubs/io_win32_unittest.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700550 "src/google/protobuf/stubs/status_test.cc",
551 "src/google/protobuf/stubs/statusor_test.cc",
552 "src/google/protobuf/stubs/stringpiece_unittest.cc",
553 "src/google/protobuf/stubs/stringprintf_unittest.cc",
554 "src/google/protobuf/stubs/structurally_valid_unittest.cc",
555 "src/google/protobuf/stubs/strutil_unittest.cc",
556 "src/google/protobuf/stubs/template_util_unittest.cc",
557 "src/google/protobuf/stubs/time_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700558 "src/google/protobuf/text_format_unittest.cc",
559 "src/google/protobuf/unknown_field_set_unittest.cc",
Byron Yicb3e84b2017-03-16 20:01:22 +0800560 "src/google/protobuf/util/delimited_message_util_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700561 "src/google/protobuf/util/field_comparator_test.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700562 "src/google/protobuf/util/field_mask_util_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700563 "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
564 "src/google/protobuf/util/internal/json_objectwriter_test.cc",
565 "src/google/protobuf/util/internal/json_stream_parser_test.cc",
566 "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
567 "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
568 "src/google/protobuf/util/internal/type_info_test_helper.cc",
569 "src/google/protobuf/util/json_util_test.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800570 "src/google/protobuf/util/message_differencer_unittest.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700571 "src/google/protobuf/util/time_util_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700572 "src/google/protobuf/util/type_resolver_util_test.cc",
573 "src/google/protobuf/well_known_types_unittest.cc",
574 "src/google/protobuf/wire_format_unittest.cc",
575 ],
576 copts = COPTS,
577 data = [
578 ":test_plugin",
Jisi Liu598480d2015-10-21 11:19:16 -0700579 ] + glob([
580 "src/google/protobuf/**/*",
Feng Xiaoacde1652017-03-29 15:14:18 -0700581 # Files for csharp_bootstrap_unittest.cc.
582 "conformance/**/*",
583 "csharp/src/**/*",
Jisi Liu598480d2015-10-21 11:19:16 -0700584 ]),
Jisi Liu7a0c4312015-06-18 16:45:27 -0700585 includes = [
586 "src/",
587 ],
588 linkopts = LINK_OPTS,
589 deps = [
Jisi Liu993fb702015-10-19 17:19:49 -0700590 ":cc_test_protos",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700591 ":protobuf",
592 ":protoc_lib",
593 "//external:gtest_main",
594 ],
595)
Jisi Liu993fb702015-10-19 17:19:49 -0700596
597################################################################################
598# Java support
599################################################################################
Steven Parkesea188662016-02-25 07:53:19 -0800600internal_gen_well_known_protos_java(
Ming Zhao4fe03812016-01-21 23:03:28 -0800601 srcs = WELL_KNOWN_PROTOS,
Jisi Liu993fb702015-10-19 17:19:49 -0700602)
603
604java_library(
Jisi Liu166e9bb2015-10-21 10:56:38 -0700605 name = "protobuf_java",
Jisi Liu993fb702015-10-19 17:19:49 -0700606 srcs = glob([
Ming Zhao4fe03812016-01-21 23:03:28 -0800607 "java/core/src/main/java/com/google/protobuf/*.java",
Jisi Liu993fb702015-10-19 17:19:49 -0700608 ]) + [
Ming Zhao4fe03812016-01-21 23:03:28 -0800609 ":gen_well_known_protos_java",
Jisi Liu993fb702015-10-19 17:19:49 -0700610 ],
David Ostrovsky85b488f2018-01-31 09:01:27 +0100611 javacopts = select({
612 "//:jdk9": ["--add-modules=jdk.unsupported"],
613 "//conditions:default": ["-source 7", "-target 7"],
614 }),
Jisi Liu993fb702015-10-19 17:19:49 -0700615 visibility = ["//visibility:public"],
616)
617
Steven Parkesa9244ca2016-03-10 17:50:25 -0800618java_library(
619 name = "protobuf_java_util",
620 srcs = glob([
621 "java/util/src/main/java/com/google/protobuf/util/*.java",
622 ]),
David Ostrovsky019ceea2018-01-25 06:05:14 +0100623 javacopts = ["-source 7", "-target 7"],
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800624 visibility = ["//visibility:public"],
Steven Parkesa9244ca2016-03-10 17:50:25 -0800625 deps = [
David Z. Chen5ebeefb2016-04-08 13:30:13 -0700626 "protobuf_java",
627 "//external:gson",
628 "//external:guava",
Steven Parkesa9244ca2016-03-10 17:50:25 -0800629 ],
Steven Parkesa9244ca2016-03-10 17:50:25 -0800630)
631
Jisi Liu993fb702015-10-19 17:19:49 -0700632################################################################################
633# Python support
634################################################################################
635
David Z. Chen985c9682016-02-11 18:11:10 -0800636py_library(
Jisi Liu993fb702015-10-19 17:19:49 -0700637 name = "python_srcs",
638 srcs = glob(
639 [
Calder Coalson142cbe02018-05-21 15:33:43 -0700640 "python/google/__init__.py",
Jisi Liu993fb702015-10-19 17:19:49 -0700641 "python/google/protobuf/*.py",
642 "python/google/protobuf/**/*.py",
643 ],
644 exclude = [
David Z. Chen02cd45c2016-05-20 16:49:04 -0700645 "python/google/protobuf/__init__.py",
646 "python/google/protobuf/**/__init__.py",
Jisi Liu993fb702015-10-19 17:19:49 -0700647 "python/google/protobuf/internal/*_test.py",
648 "python/google/protobuf/internal/test_util.py",
649 ],
650 ),
David Z. Chen985c9682016-02-11 18:11:10 -0800651 imports = ["python"],
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800652 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700653)
654
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800655cc_binary(
Richard Shindf5841f2016-10-18 13:16:44 -0700656 name = "python/google/protobuf/internal/_api_implementation.so",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800657 srcs = ["python/google/protobuf/internal/api_implementation.cc"],
658 copts = COPTS + [
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800659 "-DPYTHON_PROTO2_CPP_IMPL_V2",
660 ],
661 linkshared = 1,
662 linkstatic = 1,
Manjunath Kudlura1949212015-12-08 08:24:37 -0800663 deps = select({
664 "//conditions:default": [],
David Z. Chen985c9682016-02-11 18:11:10 -0800665 ":use_fast_cpp_protos": ["//external:python_headers"],
Manjunath Kudlura1949212015-12-08 08:24:37 -0800666 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800667)
668
669cc_binary(
Richard Shindf5841f2016-10-18 13:16:44 -0700670 name = "python/google/protobuf/pyext/_message.so",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800671 srcs = glob([
672 "python/google/protobuf/pyext/*.cc",
673 "python/google/protobuf/pyext/*.h",
674 ]),
675 copts = COPTS + [
676 "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
Manjunath Kudlur99a3e302016-02-16 15:17:10 -0800677 ] + select({
678 "//conditions:default": [],
679 ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
680 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800681 includes = [
682 "python/",
683 "src/",
684 ],
685 linkshared = 1,
686 linkstatic = 1,
Manjunath Kudlura1949212015-12-08 08:24:37 -0800687 deps = [
688 ":protobuf",
Thomas Colthurst7c651422018-05-29 18:26:11 -0400689 ":proto_api",
Manjunath Kudlura1949212015-12-08 08:24:37 -0800690 ] + select({
691 "//conditions:default": [],
David Z. Chen985c9682016-02-11 18:11:10 -0800692 ":use_fast_cpp_protos": ["//external:python_headers"],
Manjunath Kudlura1949212015-12-08 08:24:37 -0800693 }),
694)
695
696config_setting(
697 name = "use_fast_cpp_protos",
698 values = {
699 "define": "use_fast_cpp_protos=true",
700 },
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800701)
702
Manjunath Kudlur99a3e302016-02-16 15:17:10 -0800703config_setting(
704 name = "allow_oversize_protos",
705 values = {
706 "define": "allow_oversize_protos=true",
707 },
708)
709
David Z. Chen02cd45c2016-05-20 16:49:04 -0700710# Copy the builtin proto files from src/google/protobuf to
711# python/google/protobuf. This way, the generated Python sources will be in the
712# same directory as the Python runtime sources. This is necessary for the
713# modules to be imported correctly since they are all part of the same Python
714# package.
715internal_copied_filegroup(
716 name = "protos_python",
717 srcs = WELL_KNOWN_PROTOS,
David Z. Chen02cd45c2016-05-20 16:49:04 -0700718 dest = "python",
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800719 strip_prefix = "src",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700720)
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 in srcs.
724COPIED_WELL_KNOWN_PROTOS = ["python/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
725
Jisi Liu993fb702015-10-19 17:19:49 -0700726py_proto_library(
Jisi Liu166e9bb2015-10-21 10:56:38 -0700727 name = "protobuf_python",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700728 srcs = COPIED_WELL_KNOWN_PROTOS,
729 include = "python",
Manjunath Kudlura1949212015-12-08 08:24:37 -0800730 data = select({
731 "//conditions:default": [],
732 ":use_fast_cpp_protos": [
Richard Shindf5841f2016-10-18 13:16:44 -0700733 ":python/google/protobuf/internal/_api_implementation.so",
734 ":python/google/protobuf/pyext/_message.so",
Manjunath Kudlura1949212015-12-08 08:24:37 -0800735 ],
736 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800737 default_runtime = "",
Jisi Liu04658a32015-10-20 15:00:13 -0700738 protoc = ":protoc",
David Z. Chen985c9682016-02-11 18:11:10 -0800739 py_libs = [
740 ":python_srcs",
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800741 "//external:six",
David Z. Chen985c9682016-02-11 18:11:10 -0800742 ],
Adam Michael6044b242017-03-10 18:06:34 -0500743 py_extra_srcs = glob(["python/**/__init__.py"]),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800744 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700745 visibility = ["//visibility:public"],
746)
747
David Z. Chen02cd45c2016-05-20 16:49:04 -0700748# Copy the test proto files from src/google/protobuf to
749# python/google/protobuf. This way, the generated Python sources will be in the
750# same directory as the Python runtime sources. This is necessary for the
751# modules to be imported correctly by the tests since they are all part of the
752# same Python package.
753internal_copied_filegroup(
754 name = "protos_python_test",
755 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
David Z. Chen02cd45c2016-05-20 16:49:04 -0700756 dest = "python",
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800757 strip_prefix = "src",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700758)
759
760# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
761# which case we can simply add :protos_python_test in srcs.
762COPIED_LITE_TEST_PROTOS = ["python/" + s for s in RELATIVE_LITE_TEST_PROTOS]
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800763
David Z. Chen02cd45c2016-05-20 16:49:04 -0700764COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]
765
Jisi Liu993fb702015-10-19 17:19:49 -0700766py_proto_library(
767 name = "python_common_test_protos",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700768 srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
769 include = "python",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800770 default_runtime = "",
Jisi Liu04658a32015-10-20 15:00:13 -0700771 protoc = ":protoc",
David Z. Chen5ebeefb2016-04-08 13:30:13 -0700772 srcs_version = "PY2AND3",
Jisi Liu166e9bb2015-10-21 10:56:38 -0700773 deps = [":protobuf_python"],
Jisi Liu993fb702015-10-19 17:19:49 -0700774)
775
776py_proto_library(
777 name = "python_specific_test_protos",
Jisi Liu68e13f42015-10-22 11:13:14 -0700778 srcs = glob([
779 "python/google/protobuf/internal/*.proto",
780 "python/google/protobuf/internal/import_test_package/*.proto",
781 ]),
Jisi Liu993fb702015-10-19 17:19:49 -0700782 include = "python",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800783 default_runtime = ":protobuf_python",
Jisi Liu04658a32015-10-20 15:00:13 -0700784 protoc = ":protoc",
David Z. Chen5ebeefb2016-04-08 13:30:13 -0700785 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700786 deps = [":python_common_test_protos"],
787)
788
789py_library(
790 name = "python_tests",
David Z. Chen985c9682016-02-11 18:11:10 -0800791 srcs = glob(
792 [
793 "python/google/protobuf/internal/*_test.py",
794 "python/google/protobuf/internal/test_util.py",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700795 "python/google/protobuf/internal/import_test_package/__init__.py",
David Z. Chen985c9682016-02-11 18:11:10 -0800796 ],
797 ),
798 imports = ["python"],
Geoffrey Irving29799232015-12-03 13:11:19 -0800799 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700800 deps = [
Jisi Liu166e9bb2015-10-21 10:56:38 -0700801 ":protobuf_python",
Jisi Liu598480d2015-10-21 11:19:16 -0700802 ":python_common_test_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700803 ":python_specific_test_protos",
804 ],
805)
806
807internal_protobuf_py_tests(
Jisi Liu8f540262015-10-20 16:21:41 -0700808 name = "python_tests_batch",
Jisi Liu68e13f42015-10-22 11:13:14 -0700809 data = glob([
810 "src/google/protobuf/**/*",
811 ]),
Jisi Liu993fb702015-10-19 17:19:49 -0700812 modules = [
813 "descriptor_database_test",
814 "descriptor_pool_test",
815 "descriptor_test",
816 "generator_test",
817 "json_format_test",
818 "message_factory_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700819 "message_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700820 "proto_builder_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700821 "reflection_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700822 "service_reflection_test",
823 "symbol_database_test",
824 "text_encoding_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700825 "text_format_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700826 "unknown_fields_test",
827 "wire_format_test",
828 ],
829 deps = [":python_tests"],
830)
cgrushko45d92ae2016-12-02 19:40:50 -0500831
Thomas Colthurst7c651422018-05-29 18:26:11 -0400832cc_library(
833 name = "proto_api",
834 hdrs = ["python/google/protobuf/proto_api.h"],
835 deps = [
Thomas Colthurst7c651422018-05-29 18:26:11 -0400836 "//external:python_headers",
837 ],
Cory McLeanb7d3ec32018-06-11 12:18:45 -0400838 visibility = ["//visibility:public"],
Thomas Colthurst7c651422018-05-29 18:26:11 -0400839)
840
cgrushko45d92ae2016-12-02 19:40:50 -0500841proto_lang_toolchain(
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800842 name = "cc_toolchain",
843 command_line = "--cpp_out=$(OUT)",
844 runtime = ":protobuf",
845 visibility = ["//visibility:public"],
John Millikin350b1352018-02-24 11:36:49 -0800846 blacklisted_protos = [":_internal_wkt_protos_genrule"],
cgrushko45d92ae2016-12-02 19:40:50 -0500847)
cgrushkoe4baf3f2017-01-12 12:51:04 -0500848
849proto_lang_toolchain(
850 name = "java_toolchain",
851 command_line = "--java_out=$(OUT)",
852 runtime = ":protobuf_java",
853 visibility = ["//visibility:public"],
854)
makdharma286f0592017-05-01 09:49:26 -0700855
Thomas Van Lenten18aa2962018-11-01 09:37:14 -0400856alias(
857 name = "objectivec",
858 actual = ":protobuf_objc",
859 visibility = ["//visibility:public"],
860)
makdharma286f0592017-05-01 09:49:26 -0700861
862objc_library(
Thomas Van Lenten18aa2962018-11-01 09:37:14 -0400863 name = "protobuf_objc",
864 hdrs = [
865 "objectivec/GPBArray.h",
866 "objectivec/GPBBootstrap.h",
867 "objectivec/GPBCodedInputStream.h",
868 "objectivec/GPBCodedOutputStream.h",
869 "objectivec/GPBDescriptor.h",
870 "objectivec/GPBDictionary.h",
871 "objectivec/GPBExtensionInternals.h",
872 "objectivec/GPBExtensionRegistry.h",
873 "objectivec/GPBMessage.h",
874 "objectivec/GPBProtocolBuffers.h",
875 "objectivec/GPBProtocolBuffers_RuntimeSupport.h",
876 "objectivec/GPBRootObject.h",
877 "objectivec/GPBRuntimeTypes.h",
878 "objectivec/GPBUnknownField.h",
879 "objectivec/GPBUnknownFieldSet.h",
880 "objectivec/GPBUtilities.h",
881 "objectivec/GPBWellKnownTypes.h",
882 "objectivec/GPBWireFormat.h",
883 "objectivec/google/protobuf/Any.pbobjc.h",
884 "objectivec/google/protobuf/Api.pbobjc.h",
885 "objectivec/google/protobuf/Duration.pbobjc.h",
886 "objectivec/google/protobuf/Empty.pbobjc.h",
887 "objectivec/google/protobuf/FieldMask.pbobjc.h",
888 "objectivec/google/protobuf/SourceContext.pbobjc.h",
889 "objectivec/google/protobuf/Struct.pbobjc.h",
890 "objectivec/google/protobuf/Timestamp.pbobjc.h",
891 "objectivec/google/protobuf/Type.pbobjc.h",
892 "objectivec/google/protobuf/Wrappers.pbobjc.h",
893 # Package private headers, but exposed because the generated sources
894 # need to use them.
895 "objectivec/GPBArray_PackagePrivate.h",
896 "objectivec/GPBCodedInputStream_PackagePrivate.h",
897 "objectivec/GPBCodedOutputStream_PackagePrivate.h",
898 "objectivec/GPBDescriptor_PackagePrivate.h",
899 "objectivec/GPBDictionary_PackagePrivate.h",
900 "objectivec/GPBMessage_PackagePrivate.h",
901 "objectivec/GPBRootObject_PackagePrivate.h",
902 "objectivec/GPBUnknownFieldSet_PackagePrivate.h",
903 "objectivec/GPBUnknownField_PackagePrivate.h",
904 "objectivec/GPBUtilities_PackagePrivate.h",
905 ],
Benjamin Barenblat048f5c22018-07-11 13:20:01 -0400906 copts = [
907 "-Wno-vla",
908 ],
makdharma286f0592017-05-01 09:49:26 -0700909 includes = [
910 "objectivec",
911 ],
Thomas Van Lenten18aa2962018-11-01 09:37:14 -0400912 non_arc_srcs = [
913 "objectivec/GPBArray.m",
914 "objectivec/GPBCodedInputStream.m",
915 "objectivec/GPBCodedOutputStream.m",
916 "objectivec/GPBDescriptor.m",
917 "objectivec/GPBDictionary.m",
918 "objectivec/GPBExtensionInternals.m",
919 "objectivec/GPBExtensionRegistry.m",
920 "objectivec/GPBMessage.m",
921 "objectivec/GPBRootObject.m",
922 "objectivec/GPBUnknownField.m",
923 "objectivec/GPBUnknownFieldSet.m",
924 "objectivec/GPBUtilities.m",
925 "objectivec/GPBWellKnownTypes.m",
926 "objectivec/GPBWireFormat.m",
927 "objectivec/google/protobuf/Any.pbobjc.m",
928 "objectivec/google/protobuf/Api.pbobjc.m",
929 "objectivec/google/protobuf/Duration.pbobjc.m",
930 "objectivec/google/protobuf/Empty.pbobjc.m",
931 "objectivec/google/protobuf/FieldMask.pbobjc.m",
932 "objectivec/google/protobuf/SourceContext.pbobjc.m",
933 "objectivec/google/protobuf/Struct.pbobjc.m",
934 "objectivec/google/protobuf/Timestamp.pbobjc.m",
935 "objectivec/google/protobuf/Type.pbobjc.m",
936 "objectivec/google/protobuf/Wrappers.pbobjc.m",
937 ],
makdharma286f0592017-05-01 09:49:26 -0700938 visibility = ["//visibility:public"],
939)
Fahrzin Hemmati0d68b292018-03-26 19:08:26 -0700940
941################################################################################
942# Test generated proto support
943################################################################################
944
945genrule(
946 name = "generated_protos",
947 srcs = ["src/google/protobuf/unittest_import.proto"],
948 outs = ["unittest_gen.proto"],
949 cmd = "cat $(SRCS) | sed 's|google/|src/google/|' > $(OUTS)"
950)
951
952proto_library(
953 name = "generated_protos_proto",
Fahrzin Hemmati55962db2018-05-07 17:36:34 -0700954 srcs = [
955 "unittest_gen.proto",
956 "src/google/protobuf/unittest_import_public.proto",
957 ],
Fahrzin Hemmati0d68b292018-03-26 19:08:26 -0700958)
959
Fahrzin Hemmati0d68b292018-03-26 19:08:26 -0700960py_proto_library(
961 name = "generated_protos_py",
962 srcs = [
963 "unittest_gen.proto",
964 "src/google/protobuf/unittest_import_public.proto",
965 ],
966 default_runtime = "",
967 protoc = ":protoc",
968)
Josh Haberman6dec8cf2018-11-03 12:59:45 -0700969
970################################################################################
971# Conformance tests
972################################################################################
973
974proto_library(
975 name = "test_messages_proto2_proto",
976 srcs = [
977 "src/google/protobuf/test_messages_proto2.proto",
978 ],
979)
980
981proto_library(
982 name = "test_messages_proto3_proto",
983 srcs = [
984 "src/google/protobuf/test_messages_proto3.proto",
985 ],
986 deps = [
987 ":any_proto",
988 ":duration_proto",
989 ":field_mask_proto",
990 ":struct_proto",
991 ":timestamp_proto",
992 ":wrappers_proto",
993 ],
994)
995
996cc_proto_library(
997 name = "test_messages_proto2_proto_cc",
998 srcs = [
999 "src/google/protobuf/test_messages_proto2.proto",
1000 ],
1001)
1002
1003cc_proto_library(
1004 name = "test_messages_proto3_proto_cc",
1005 srcs = [
1006 "src/google/protobuf/test_messages_proto3.proto",
1007 ],
1008 deps = [
1009 ":cc_wkt_protos",
1010 ],
1011)
1012
1013proto_library(
1014 name = "conformance_proto",
1015 srcs = [
1016 "conformance/conformance.proto",
1017 ],
1018)
1019
1020cc_proto_library(
1021 name = "conformance_proto_cc",
1022 srcs = ["conformance/conformance.proto"],
1023)
1024
1025cc_library(
1026 name = "jsoncpp",
1027 hdrs = ["conformance/third_party/jsoncpp/json.h"],
1028 srcs = ["conformance/third_party/jsoncpp/jsoncpp.cpp"],
1029 includes = ["conformance"],
1030)
1031
1032cc_library(
1033 name = "conformance_test",
1034 srcs = [
1035 "conformance/conformance_test.cc",
1036 "conformance/conformance_test_impl.cc",
1037 ],
1038 hdrs = [
1039 "conformance/conformance_test.h",
1040 ],
1041 deps = [
1042 ":conformance_proto_cc",
1043 ":jsoncpp",
1044 ":test_messages_proto2_proto_cc",
1045 ":test_messages_proto3_proto_cc",
1046 ],
1047 includes = ["conformance", "src"],
1048)
1049
1050cc_binary(
1051 name = "conformance_test_runner",
1052 srcs = [
1053 "conformance/conformance_test_runner.cc",
1054 ],
1055 deps = [
1056 ":conformance_test",
1057 ]
1058)