blob: eb8077ae749992021c5179ef4a0c99be824cf6e1 [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
22ZLIB_DEPS = ["//external:zlib"]
23
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 "-Wall",
Yun Peng0b059a32017-05-31 14:01:23 +020053 "-Woverloaded-virtual",
54 "-Wno-sign-compare",
55 "-Wno-unused-function",
Justine Tunneyac5371d2017-11-17 18:27:39 -080056 # Prevents ISO C++ const string assignment warnings for pyext sources.
57 "-Wno-writable-strings",
depristo2506cf52018-06-28 22:54:43 +000058 "-Wno-write-strings",
Yun Peng0b059a32017-05-31 14:01:23 +020059 ],
60})
61
scentinib30ddee2018-08-28 14:07:55 +020062load(":compiler_config_setting.bzl", "create_compiler_config_setting")
63
64create_compiler_config_setting(name = "msvc", value = "msvc-cl")
Yun Peng0b059a32017-05-31 14:01:23 +020065
Andrew Harpb56b4612016-04-04 15:13:30 -040066config_setting(
67 name = "android",
68 values = {
69 "crosstool_top": "//external:android/crosstool",
70 },
71)
72
Pascal Muetscharda6957f22018-03-22 13:14:10 -070073# Android and MSVC builds do not need to link in a separate pthread library.
Andrew Harpb56b4612016-04-04 15:13:30 -040074LINK_OPTS = select({
Andrew Harp3b4e7dc2016-04-04 16:13:31 -040075 ":android": [],
Jan Tattermuschccc56a32018-05-24 09:51:53 -070076 ":msvc": [
Loo Rong Jie0456e262018-06-06 10:03:25 +080077 # Suppress linker warnings about files with no symbols defined.
78 "-ignore:4221",
Laszlo Csomor55171682017-12-01 12:05:32 +010079 ],
Daniel Ylitalo32fa55e2017-01-25 22:04:11 +010080 "//conditions:default": ["-lpthread", "-lm"],
Andrew Harpb56b4612016-04-04 15:13:30 -040081})
Jisi Liud19604f2015-06-17 17:37:58 -070082
Jisi Liu04658a32015-10-20 15:00:13 -070083load(
cgrushko65a4d202017-02-08 15:23:57 -050084 ":protobuf.bzl",
Jisi Liu04658a32015-10-20 15:00:13 -070085 "cc_proto_library",
86 "py_proto_library",
David Z. Chen02cd45c2016-05-20 16:49:04 -070087 "internal_copied_filegroup",
Steven Parkesea188662016-02-25 07:53:19 -080088 "internal_gen_well_known_protos_java",
Jisi Liu04658a32015-10-20 15:00:13 -070089 "internal_protobuf_py_tests",
90)
Jisi Liu39362b32015-10-14 17:12:11 -070091
Jisi Liud19604f2015-06-17 17:37:58 -070092cc_library(
93 name = "protobuf_lite",
94 srcs = [
95 # AUTOGEN(protobuf_lite_srcs)
96 "src/google/protobuf/arena.cc",
97 "src/google/protobuf/arenastring.cc",
98 "src/google/protobuf/extension_set.cc",
Jisi Liu12c186f2017-07-25 14:38:00 -070099 "src/google/protobuf/generated_message_table_driven_lite.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700100 "src/google/protobuf/generated_message_util.cc",
Adam Cozzette609d7522017-12-07 14:16:50 -0800101 "src/google/protobuf/implicit_weak_message.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700102 "src/google/protobuf/io/coded_stream.cc",
103 "src/google/protobuf/io/zero_copy_stream.cc",
104 "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
105 "src/google/protobuf/message_lite.cc",
106 "src/google/protobuf/repeated_field.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700107 "src/google/protobuf/stubs/bytestream.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700108 "src/google/protobuf/stubs/common.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700109 "src/google/protobuf/stubs/int128.cc",
Jisi Liu759245a2017-07-25 11:52:33 -0700110 "src/google/protobuf/stubs/io_win32.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700111 "src/google/protobuf/stubs/status.cc",
112 "src/google/protobuf/stubs/statusor.cc",
113 "src/google/protobuf/stubs/stringpiece.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700114 "src/google/protobuf/stubs/stringprintf.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700115 "src/google/protobuf/stubs/structurally_valid.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700116 "src/google/protobuf/stubs/strutil.cc",
117 "src/google/protobuf/stubs/time.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700118 "src/google/protobuf/wire_format_lite.cc",
119 ],
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700120 hdrs = glob(["src/google/protobuf/**/*.h", "src/google/protobuf/**/*.inc"]),
Param Reddy16792c62017-10-15 13:06:58 -0700121 copts = COPTS,
Jisi Liud19604f2015-06-17 17:37:58 -0700122 includes = ["src/"],
123 linkopts = LINK_OPTS,
124 visibility = ["//visibility:public"],
125)
126
Cody Schroeder802d5432018-12-11 11:58:26 -0800127PROTOBUF_DEPS = select({
128 ":msvc": [],
129 "//conditions:default": ZLIB_DEPS,
130})
131
Jisi Liud19604f2015-06-17 17:37:58 -0700132cc_library(
133 name = "protobuf",
134 srcs = [
135 # AUTOGEN(protobuf_srcs)
136 "src/google/protobuf/any.cc",
137 "src/google/protobuf/any.pb.cc",
138 "src/google/protobuf/api.pb.cc",
139 "src/google/protobuf/compiler/importer.cc",
140 "src/google/protobuf/compiler/parser.cc",
141 "src/google/protobuf/descriptor.cc",
142 "src/google/protobuf/descriptor.pb.cc",
143 "src/google/protobuf/descriptor_database.cc",
144 "src/google/protobuf/duration.pb.cc",
145 "src/google/protobuf/dynamic_message.cc",
146 "src/google/protobuf/empty.pb.cc",
147 "src/google/protobuf/extension_set_heavy.cc",
148 "src/google/protobuf/field_mask.pb.cc",
149 "src/google/protobuf/generated_message_reflection.cc",
Jisi Liu759245a2017-07-25 11:52:33 -0700150 "src/google/protobuf/generated_message_table_driven.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700151 "src/google/protobuf/io/gzip_stream.cc",
152 "src/google/protobuf/io/printer.cc",
153 "src/google/protobuf/io/strtod.cc",
154 "src/google/protobuf/io/tokenizer.cc",
155 "src/google/protobuf/io/zero_copy_stream_impl.cc",
156 "src/google/protobuf/map_field.cc",
157 "src/google/protobuf/message.cc",
158 "src/google/protobuf/reflection_ops.cc",
159 "src/google/protobuf/service.cc",
160 "src/google/protobuf/source_context.pb.cc",
161 "src/google/protobuf/struct.pb.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700162 "src/google/protobuf/stubs/mathlimits.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700163 "src/google/protobuf/stubs/substitute.cc",
164 "src/google/protobuf/text_format.cc",
165 "src/google/protobuf/timestamp.pb.cc",
166 "src/google/protobuf/type.pb.cc",
167 "src/google/protobuf/unknown_field_set.cc",
Bairen Yi312e2db2017-03-21 03:52:37 +0800168 "src/google/protobuf/util/delimited_message_util.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700169 "src/google/protobuf/util/field_comparator.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700170 "src/google/protobuf/util/field_mask_util.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700171 "src/google/protobuf/util/internal/datapiece.cc",
172 "src/google/protobuf/util/internal/default_value_objectwriter.cc",
173 "src/google/protobuf/util/internal/error_listener.cc",
174 "src/google/protobuf/util/internal/field_mask_utility.cc",
175 "src/google/protobuf/util/internal/json_escaping.cc",
176 "src/google/protobuf/util/internal/json_objectwriter.cc",
177 "src/google/protobuf/util/internal/json_stream_parser.cc",
178 "src/google/protobuf/util/internal/object_writer.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800179 "src/google/protobuf/util/internal/proto_writer.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700180 "src/google/protobuf/util/internal/protostream_objectsource.cc",
181 "src/google/protobuf/util/internal/protostream_objectwriter.cc",
182 "src/google/protobuf/util/internal/type_info.cc",
183 "src/google/protobuf/util/internal/type_info_test_helper.cc",
184 "src/google/protobuf/util/internal/utility.cc",
185 "src/google/protobuf/util/json_util.cc",
186 "src/google/protobuf/util/message_differencer.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700187 "src/google/protobuf/util/time_util.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700188 "src/google/protobuf/util/type_resolver_util.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700189 "src/google/protobuf/wire_format.cc",
190 "src/google/protobuf/wrappers.pb.cc",
191 ],
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700192 hdrs = glob(["src/**/*.h", "src/**/*.inc"]),
Param Reddy16792c62017-10-15 13:06:58 -0700193 copts = COPTS,
Jisi Liud19604f2015-06-17 17:37:58 -0700194 includes = ["src/"],
195 linkopts = LINK_OPTS,
196 visibility = ["//visibility:public"],
Cody Schroeder802d5432018-12-11 11:58:26 -0800197 deps = [":protobuf_lite"] + PROTOBUF_DEPS,
Jisi Liud19604f2015-06-17 17:37:58 -0700198)
199
Manjunath Kudlur6837b2d2017-03-02 18:02:05 -0800200# This provides just the header files for use in projects that need to build
201# shared libraries for dynamic loading. This target is available until Bazel
202# adds native support for such use cases.
203# TODO(keveman): Remove this target once the support gets added to Bazel.
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800204cc_library(
205 name = "protobuf_headers",
206 hdrs = glob(["src/**/*.h"]),
207 includes = ["src/"],
208 visibility = ["//visibility:public"],
209)
210
Jakob Buchgraber699c0eb2017-09-05 17:15:10 +0200211# Map of all well known protos.
212# name => (include path, imports)
213WELL_KNOWN_PROTO_MAP = {
214 "any" : ("google/protobuf/any.proto", []),
215 "api" : ("google/protobuf/api.proto", ["source_context", "type"]),
216 "compiler_plugin" : ("google/protobuf/compiler/plugin.proto", ["descriptor"]),
217 "descriptor" : ("google/protobuf/descriptor.proto", []),
218 "duration" : ("google/protobuf/duration.proto", []),
219 "empty" : ("google/protobuf/empty.proto", []),
220 "field_mask" : ("google/protobuf/field_mask.proto", []),
221 "source_context" : ("google/protobuf/source_context.proto", []),
222 "struct" : ("google/protobuf/struct.proto", []),
223 "timestamp" : ("google/protobuf/timestamp.proto", []),
224 "type" : ("google/protobuf/type.proto", ["any", "source_context"]),
225 "wrappers" : ("google/protobuf/wrappers.proto", []),
226}
227
228RELATIVE_WELL_KNOWN_PROTOS = [proto[1][0] for proto in WELL_KNOWN_PROTO_MAP.items()]
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700229
Jisi Liu993fb702015-10-19 17:19:49 -0700230WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
231
Steven Parkesd5a57322016-03-22 17:56:07 -0700232filegroup(
233 name = "well_known_protos",
234 srcs = WELL_KNOWN_PROTOS,
235 visibility = ["//visibility:public"],
236)
237
Jisi Liu39362b32015-10-14 17:12:11 -0700238cc_proto_library(
239 name = "cc_wkt_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700240 srcs = WELL_KNOWN_PROTOS,
Jisi Liu3101e732015-10-16 12:46:26 -0700241 include = "src",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800242 default_runtime = ":protobuf",
Jisi Liu993fb702015-10-19 17:19:49 -0700243 internal_bootstrap_hack = 1,
Jisi Liu04658a32015-10-20 15:00:13 -0700244 protoc = ":protoc",
Jisi Liu6a40bf82015-11-17 12:36:21 -0800245 visibility = ["//visibility:public"],
Jisi Liu39362b32015-10-14 17:12:11 -0700246)
247
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700248################################################################################
Jakob Buchgraber699c0eb2017-09-05 17:15:10 +0200249# Well Known Types Proto Library Rules
250#
251# These proto_library rules can be used with one of the language specific proto
252# library rules i.e. java_proto_library:
253#
254# java_proto_library(
255# name = "any_java_proto",
256# deps = ["@com_google_protobuf//:any_proto],
257# )
258################################################################################
259
260internal_copied_filegroup(
261 name = "_internal_wkt_protos",
262 srcs = WELL_KNOWN_PROTOS,
263 dest = "",
264 strip_prefix = "src",
James O'Kane950f5e42018-03-08 22:30:44 -0800265 visibility = ["//visibility:private"],
Jakob Buchgraber699c0eb2017-09-05 17:15:10 +0200266)
267
268[proto_library(
269 name = proto[0] + "_proto",
270 srcs = [proto[1][0]],
271 deps = [dep + "_proto" for dep in proto[1][1]],
272 visibility = ["//visibility:public"],
273 ) for proto in WELL_KNOWN_PROTO_MAP.items()]
274
275################################################################################
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700276# Protocol Buffers Compiler
277################################################################################
278
Jisi Liud19604f2015-06-17 17:37:58 -0700279cc_library(
280 name = "protoc_lib",
281 srcs = [
282 # AUTOGEN(protoc_lib_srcs)
283 "src/google/protobuf/compiler/code_generator.cc",
284 "src/google/protobuf/compiler/command_line_interface.cc",
285 "src/google/protobuf/compiler/cpp/cpp_enum.cc",
286 "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
287 "src/google/protobuf/compiler/cpp/cpp_extension.cc",
288 "src/google/protobuf/compiler/cpp/cpp_field.cc",
289 "src/google/protobuf/compiler/cpp/cpp_file.cc",
290 "src/google/protobuf/compiler/cpp/cpp_generator.cc",
291 "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
292 "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
293 "src/google/protobuf/compiler/cpp/cpp_message.cc",
294 "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
Adam Cozzette13fd0452017-09-12 10:32:01 -0700295 "src/google/protobuf/compiler/cpp/cpp_padding_optimizer.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700296 "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
297 "src/google/protobuf/compiler/cpp/cpp_service.cc",
298 "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
Ming Zhao5cdd9362015-10-05 14:37:21 -0700299 "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700300 "src/google/protobuf/compiler/csharp/csharp_enum.cc",
301 "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700302 "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
303 "src/google/protobuf/compiler/csharp/csharp_generator.cc",
304 "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
Jon Skeetb2ac8682015-07-15 13:17:42 +0100305 "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700306 "src/google/protobuf/compiler/csharp/csharp_message.cc",
307 "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
308 "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
Jon Skeeta6361a12015-11-19 13:05:17 +0000309 "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700310 "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
311 "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
312 "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
313 "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
Jon Skeetb2ac8682015-07-15 13:17:42 +0100314 "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700315 "src/google/protobuf/compiler/java/java_context.cc",
316 "src/google/protobuf/compiler/java/java_doc_comment.cc",
317 "src/google/protobuf/compiler/java/java_enum.cc",
318 "src/google/protobuf/compiler/java/java_enum_field.cc",
319 "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700320 "src/google/protobuf/compiler/java/java_enum_lite.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700321 "src/google/protobuf/compiler/java/java_extension.cc",
Jisi Liu1f4f3e22016-04-18 14:12:08 -0700322 "src/google/protobuf/compiler/java/java_extension_lite.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700323 "src/google/protobuf/compiler/java/java_field.cc",
324 "src/google/protobuf/compiler/java/java_file.cc",
325 "src/google/protobuf/compiler/java/java_generator.cc",
326 "src/google/protobuf/compiler/java/java_generator_factory.cc",
327 "src/google/protobuf/compiler/java/java_helpers.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700328 "src/google/protobuf/compiler/java/java_map_field.cc",
329 "src/google/protobuf/compiler/java/java_map_field_lite.cc",
330 "src/google/protobuf/compiler/java/java_message.cc",
331 "src/google/protobuf/compiler/java/java_message_builder.cc",
332 "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
333 "src/google/protobuf/compiler/java/java_message_field.cc",
334 "src/google/protobuf/compiler/java/java_message_field_lite.cc",
335 "src/google/protobuf/compiler/java/java_message_lite.cc",
336 "src/google/protobuf/compiler/java/java_name_resolver.cc",
337 "src/google/protobuf/compiler/java/java_primitive_field.cc",
338 "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
339 "src/google/protobuf/compiler/java/java_service.cc",
340 "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
341 "src/google/protobuf/compiler/java/java_string_field.cc",
342 "src/google/protobuf/compiler/java/java_string_field_lite.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800343 "src/google/protobuf/compiler/js/js_generator.cc",
Jisi Liuf92b4552016-12-05 10:16:47 -0800344 "src/google/protobuf/compiler/js/well_known_types_embed.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700345 "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
346 "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
347 "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
348 "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
349 "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
350 "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
351 "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
352 "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
353 "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
354 "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
355 "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
356 "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
Jisi Liud9473082016-09-22 15:14:58 -0700357 "src/google/protobuf/compiler/php/php_generator.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700358 "src/google/protobuf/compiler/plugin.cc",
Feng Xiaofd595fc2018-03-01 16:36:05 -0800359 "src/google/protobuf/compiler/plugin.pb.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700360 "src/google/protobuf/compiler/python/python_generator.cc",
361 "src/google/protobuf/compiler/ruby/ruby_generator.cc",
362 "src/google/protobuf/compiler/subprocess.cc",
363 "src/google/protobuf/compiler/zip_writer.cc",
364 ],
365 copts = COPTS,
366 includes = ["src/"],
Loo Rong Jie0456e262018-06-06 10:03:25 +0800367 linkopts = LINK_OPTS + select({
368 ":msvc": [
369 # Linking to setargv.obj makes the default command line argument
370 # parser expand wildcards, so the main method's argv will contain the
371 # expanded list instead of the wildcards.
372 #
373 # Adding dummy "-DEFAULTLIB:kernel32.lib", because:
374 # - Microsoft ships this object file next to default libraries
375 # - but this file is not a library, just a precompiled object
376 # - "-WHOLEARCHIVE" and "-DEFAULTLIB" only accept library,
377 # not precompiled object.
378 # - Bazel would assume linkopt that does not start with "-" or "$"
379 # as a label to a target, so we add a harmless "-DEFAULTLIB:kernel32.lib"
380 # before "setargv.obj".
381 # See https://msdn.microsoft.com/en-us/library/8bch7bkk.aspx
382 "-DEFAULTLIB:kernel32.lib setargv.obj",
383 ],
384 "//conditions:default": [],
385 }),
Jisi Liud19604f2015-06-17 17:37:58 -0700386 visibility = ["//visibility:public"],
387 deps = [":protobuf"],
388)
389
390cc_binary(
391 name = "protoc",
392 srcs = ["src/google/protobuf/compiler/main.cc"],
Jisi Liud19604f2015-06-17 17:37:58 -0700393 linkopts = LINK_OPTS,
394 visibility = ["//visibility:public"],
395 deps = [":protoc_lib"],
396)
397
Jisi Liud19604f2015-06-17 17:37:58 -0700398################################################################################
399# Tests
400################################################################################
401
Jisi Liu993fb702015-10-19 17:19:49 -0700402RELATIVE_LITE_TEST_PROTOS = [
Jisi Liud19604f2015-06-17 17:37:58 -0700403 # AUTOGEN(lite_test_protos)
404 "google/protobuf/map_lite_unittest.proto",
405 "google/protobuf/unittest_import_lite.proto",
406 "google/protobuf/unittest_import_public_lite.proto",
407 "google/protobuf/unittest_lite.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700408 "google/protobuf/unittest_no_arena_lite.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700409]
410
Jisi Liu993fb702015-10-19 17:19:49 -0700411LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
412
413RELATIVE_TEST_PROTOS = [
Jisi Liud19604f2015-06-17 17:37:58 -0700414 # AUTOGEN(test_protos)
415 "google/protobuf/any_test.proto",
416 "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
417 "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
418 "google/protobuf/map_proto2_unittest.proto",
419 "google/protobuf/map_unittest.proto",
420 "google/protobuf/unittest.proto",
421 "google/protobuf/unittest_arena.proto",
422 "google/protobuf/unittest_custom_options.proto",
423 "google/protobuf/unittest_drop_unknown_fields.proto",
424 "google/protobuf/unittest_embed_optimize_for.proto",
425 "google/protobuf/unittest_empty.proto",
426 "google/protobuf/unittest_enormous_descriptor.proto",
427 "google/protobuf/unittest_import.proto",
428 "google/protobuf/unittest_import_public.proto",
Feng Xiao32d78302017-03-29 14:01:40 -0700429 "google/protobuf/unittest_lazy_dependencies.proto",
430 "google/protobuf/unittest_lazy_dependencies_custom_option.proto",
431 "google/protobuf/unittest_lazy_dependencies_enum.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700432 "google/protobuf/unittest_lite_imports_nonlite.proto",
433 "google/protobuf/unittest_mset.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700434 "google/protobuf/unittest_mset_wire_format.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700435 "google/protobuf/unittest_no_arena.proto",
436 "google/protobuf/unittest_no_arena_import.proto",
437 "google/protobuf/unittest_no_field_presence.proto",
438 "google/protobuf/unittest_no_generic_services.proto",
439 "google/protobuf/unittest_optimize_for.proto",
440 "google/protobuf/unittest_preserve_unknown_enum.proto",
441 "google/protobuf/unittest_preserve_unknown_enum2.proto",
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700442 "google/protobuf/unittest_proto3.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700443 "google/protobuf/unittest_proto3_arena.proto",
Chad Whipkeybaf52bd2016-04-15 09:23:50 -0700444 "google/protobuf/unittest_proto3_arena_lite.proto",
445 "google/protobuf/unittest_proto3_lite.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700446 "google/protobuf/unittest_well_known_types.proto",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700447 "google/protobuf/util/internal/testdata/anys.proto",
448 "google/protobuf/util/internal/testdata/books.proto",
449 "google/protobuf/util/internal/testdata/default_value.proto",
450 "google/protobuf/util/internal/testdata/default_value_test.proto",
451 "google/protobuf/util/internal/testdata/field_mask.proto",
452 "google/protobuf/util/internal/testdata/maps.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700453 "google/protobuf/util/internal/testdata/oneofs.proto",
Jisi Liu9d4657a2016-09-22 15:11:17 -0700454 "google/protobuf/util/internal/testdata/proto3.proto",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700455 "google/protobuf/util/internal/testdata/struct.proto",
456 "google/protobuf/util/internal/testdata/timestamp_duration.proto",
Jisi Liu9d4657a2016-09-22 15:11:17 -0700457 "google/protobuf/util/internal/testdata/wrappers.proto",
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700458 "google/protobuf/util/json_format.proto",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700459 "google/protobuf/util/json_format_proto3.proto",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800460 "google/protobuf/util/message_differencer_unittest.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700461]
462
Jisi Liu993fb702015-10-19 17:19:49 -0700463TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
464
Jisi Liu39362b32015-10-14 17:12:11 -0700465cc_proto_library(
466 name = "cc_test_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700467 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
Jisi Liu3101e732015-10-16 12:46:26 -0700468 include = "src",
Jisi Liube92ffb2015-10-27 15:11:38 -0700469 default_runtime = ":protobuf",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800470 protoc = ":protoc",
Jisi Liud8701b52015-10-16 11:44:21 -0700471 deps = [":cc_wkt_protos"],
Jisi Liud19604f2015-06-17 17:37:58 -0700472)
473
474COMMON_TEST_SRCS = [
475 # AUTOGEN(common_test_srcs)
476 "src/google/protobuf/arena_test_util.cc",
477 "src/google/protobuf/map_test_util.cc",
478 "src/google/protobuf/test_util.cc",
Adam Cozzette5bed3682018-03-23 10:19:04 -0700479 "src/google/protobuf/test_util.inc",
Jisi Liud19604f2015-06-17 17:37:58 -0700480 "src/google/protobuf/testing/file.cc",
481 "src/google/protobuf/testing/googletest.cc",
482]
483
Jisi Liu7a0c4312015-06-18 16:45:27 -0700484cc_binary(
485 name = "test_plugin",
486 srcs = [
487 # AUTOGEN(test_plugin_srcs)
488 "src/google/protobuf/compiler/mock_code_generator.cc",
489 "src/google/protobuf/compiler/test_plugin.cc",
490 "src/google/protobuf/testing/file.cc",
491 ],
492 deps = [
493 ":protobuf",
494 ":protoc_lib",
495 "//external:gtest",
496 ],
497)
498
499cc_test(
Jisi Liu759245a2017-07-25 11:52:33 -0700500 name = "win32_test",
501 srcs = ["src/google/protobuf/stubs/io_win32_unittest.cc"],
502 deps = [
503 ":protobuf_lite",
504 "//external:gtest_main",
505 ],
506 tags = ["manual", "windows"],
507)
508
509cc_test(
Jisi Liu7a0c4312015-06-18 16:45:27 -0700510 name = "protobuf_test",
Jisi Liu39362b32015-10-14 17:12:11 -0700511 srcs = COMMON_TEST_SRCS + [
Jisi Liu7a0c4312015-06-18 16:45:27 -0700512 # AUTOGEN(test_srcs)
513 "src/google/protobuf/any_test.cc",
514 "src/google/protobuf/arena_unittest.cc",
515 "src/google/protobuf/arenastring_unittest.cc",
Jisi Liu1c682e02017-10-18 14:31:23 -0700516 "src/google/protobuf/compiler/annotation_test_util.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700517 "src/google/protobuf/compiler/command_line_interface_unittest.cc",
518 "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
Jisi Liu11b66612017-07-19 12:10:43 -0700519 "src/google/protobuf/compiler/cpp/cpp_move_unittest.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700520 "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
521 "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
Adam Cozzette5bed3682018-03-23 10:19:04 -0700522 "src/google/protobuf/compiler/cpp/cpp_unittest.inc",
Jisi Liu1f4f3e22016-04-18 14:12:08 -0700523 "src/google/protobuf/compiler/cpp/metadata_test.cc",
Feng Xiao32d78302017-03-29 14:01:40 -0700524 "src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700525 "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
526 "src/google/protobuf/compiler/importer_unittest.cc",
527 "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
528 "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
529 "src/google/protobuf/compiler/mock_code_generator.cc",
530 "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
531 "src/google/protobuf/compiler/parser_unittest.cc",
532 "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
533 "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
534 "src/google/protobuf/descriptor_database_unittest.cc",
535 "src/google/protobuf/descriptor_unittest.cc",
536 "src/google/protobuf/drop_unknown_fields_test.cc",
537 "src/google/protobuf/dynamic_message_unittest.cc",
538 "src/google/protobuf/extension_set_unittest.cc",
539 "src/google/protobuf/generated_message_reflection_unittest.cc",
540 "src/google/protobuf/io/coded_stream_unittest.cc",
541 "src/google/protobuf/io/printer_unittest.cc",
542 "src/google/protobuf/io/tokenizer_unittest.cc",
543 "src/google/protobuf/io/zero_copy_stream_unittest.cc",
544 "src/google/protobuf/map_field_test.cc",
545 "src/google/protobuf/map_test.cc",
546 "src/google/protobuf/message_unittest.cc",
Adam Cozzette5bed3682018-03-23 10:19:04 -0700547 "src/google/protobuf/message_unittest.inc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700548 "src/google/protobuf/no_field_presence_test.cc",
549 "src/google/protobuf/preserve_unknown_enum_test.cc",
Chad Whipkeybaf52bd2016-04-15 09:23:50 -0700550 "src/google/protobuf/proto3_arena_lite_unittest.cc",
Jisi Liuf86d39c2016-04-28 14:43:22 -0700551 "src/google/protobuf/proto3_arena_unittest.cc",
Chad Whipkeybaf52bd2016-04-15 09:23:50 -0700552 "src/google/protobuf/proto3_lite_unittest.cc",
Feng Xiaobde4eaf2018-08-13 12:58:55 -0700553 "src/google/protobuf/proto3_lite_unittest.inc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700554 "src/google/protobuf/reflection_ops_unittest.cc",
555 "src/google/protobuf/repeated_field_reflection_unittest.cc",
556 "src/google/protobuf/repeated_field_unittest.cc",
557 "src/google/protobuf/stubs/bytestream_unittest.cc",
558 "src/google/protobuf/stubs/common_unittest.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700559 "src/google/protobuf/stubs/int128_unittest.cc",
Jisi Liu759245a2017-07-25 11:52:33 -0700560 "src/google/protobuf/stubs/io_win32_unittest.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700561 "src/google/protobuf/stubs/status_test.cc",
562 "src/google/protobuf/stubs/statusor_test.cc",
563 "src/google/protobuf/stubs/stringpiece_unittest.cc",
564 "src/google/protobuf/stubs/stringprintf_unittest.cc",
565 "src/google/protobuf/stubs/structurally_valid_unittest.cc",
566 "src/google/protobuf/stubs/strutil_unittest.cc",
567 "src/google/protobuf/stubs/template_util_unittest.cc",
568 "src/google/protobuf/stubs/time_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700569 "src/google/protobuf/text_format_unittest.cc",
570 "src/google/protobuf/unknown_field_set_unittest.cc",
Byron Yicb3e84b2017-03-16 20:01:22 +0800571 "src/google/protobuf/util/delimited_message_util_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700572 "src/google/protobuf/util/field_comparator_test.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700573 "src/google/protobuf/util/field_mask_util_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700574 "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
575 "src/google/protobuf/util/internal/json_objectwriter_test.cc",
576 "src/google/protobuf/util/internal/json_stream_parser_test.cc",
577 "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
578 "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
579 "src/google/protobuf/util/internal/type_info_test_helper.cc",
580 "src/google/protobuf/util/json_util_test.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800581 "src/google/protobuf/util/message_differencer_unittest.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700582 "src/google/protobuf/util/time_util_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700583 "src/google/protobuf/util/type_resolver_util_test.cc",
584 "src/google/protobuf/well_known_types_unittest.cc",
585 "src/google/protobuf/wire_format_unittest.cc",
586 ],
587 copts = COPTS,
588 data = [
589 ":test_plugin",
Jisi Liu598480d2015-10-21 11:19:16 -0700590 ] + glob([
591 "src/google/protobuf/**/*",
Feng Xiaoacde1652017-03-29 15:14:18 -0700592 # Files for csharp_bootstrap_unittest.cc.
593 "conformance/**/*",
594 "csharp/src/**/*",
Jisi Liu598480d2015-10-21 11:19:16 -0700595 ]),
Jisi Liu7a0c4312015-06-18 16:45:27 -0700596 includes = [
597 "src/",
598 ],
599 linkopts = LINK_OPTS,
600 deps = [
Jisi Liu993fb702015-10-19 17:19:49 -0700601 ":cc_test_protos",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700602 ":protobuf",
603 ":protoc_lib",
604 "//external:gtest_main",
Cody Schroeder802d5432018-12-11 11:58:26 -0800605 ] + PROTOBUF_DEPS,
Jisi Liu7a0c4312015-06-18 16:45:27 -0700606)
Jisi Liu993fb702015-10-19 17:19:49 -0700607
608################################################################################
609# Java support
610################################################################################
Steven Parkesea188662016-02-25 07:53:19 -0800611internal_gen_well_known_protos_java(
Ming Zhao4fe03812016-01-21 23:03:28 -0800612 srcs = WELL_KNOWN_PROTOS,
Jisi Liu993fb702015-10-19 17:19:49 -0700613)
614
615java_library(
Jisi Liu166e9bb2015-10-21 10:56:38 -0700616 name = "protobuf_java",
Jisi Liu993fb702015-10-19 17:19:49 -0700617 srcs = glob([
Ming Zhao4fe03812016-01-21 23:03:28 -0800618 "java/core/src/main/java/com/google/protobuf/*.java",
Jisi Liu993fb702015-10-19 17:19:49 -0700619 ]) + [
Ming Zhao4fe03812016-01-21 23:03:28 -0800620 ":gen_well_known_protos_java",
Jisi Liu993fb702015-10-19 17:19:49 -0700621 ],
David Ostrovsky85b488f2018-01-31 09:01:27 +0100622 javacopts = select({
623 "//:jdk9": ["--add-modules=jdk.unsupported"],
624 "//conditions:default": ["-source 7", "-target 7"],
625 }),
Jisi Liu993fb702015-10-19 17:19:49 -0700626 visibility = ["//visibility:public"],
627)
628
Steven Parkesa9244ca2016-03-10 17:50:25 -0800629java_library(
630 name = "protobuf_java_util",
631 srcs = glob([
632 "java/util/src/main/java/com/google/protobuf/util/*.java",
633 ]),
David Ostrovsky019ceea2018-01-25 06:05:14 +0100634 javacopts = ["-source 7", "-target 7"],
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800635 visibility = ["//visibility:public"],
Steven Parkesa9244ca2016-03-10 17:50:25 -0800636 deps = [
David Z. Chen5ebeefb2016-04-08 13:30:13 -0700637 "protobuf_java",
638 "//external:gson",
639 "//external:guava",
Steven Parkesa9244ca2016-03-10 17:50:25 -0800640 ],
Steven Parkesa9244ca2016-03-10 17:50:25 -0800641)
642
Jisi Liu993fb702015-10-19 17:19:49 -0700643################################################################################
644# Python support
645################################################################################
646
David Z. Chen985c9682016-02-11 18:11:10 -0800647py_library(
Jisi Liu993fb702015-10-19 17:19:49 -0700648 name = "python_srcs",
649 srcs = glob(
650 [
Calder Coalson142cbe02018-05-21 15:33:43 -0700651 "python/google/__init__.py",
Jisi Liu993fb702015-10-19 17:19:49 -0700652 "python/google/protobuf/*.py",
653 "python/google/protobuf/**/*.py",
654 ],
655 exclude = [
David Z. Chen02cd45c2016-05-20 16:49:04 -0700656 "python/google/protobuf/__init__.py",
657 "python/google/protobuf/**/__init__.py",
Jisi Liu993fb702015-10-19 17:19:49 -0700658 "python/google/protobuf/internal/*_test.py",
659 "python/google/protobuf/internal/test_util.py",
660 ],
661 ),
David Z. Chen985c9682016-02-11 18:11:10 -0800662 imports = ["python"],
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800663 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700664)
665
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800666cc_binary(
Richard Shindf5841f2016-10-18 13:16:44 -0700667 name = "python/google/protobuf/internal/_api_implementation.so",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800668 srcs = ["python/google/protobuf/internal/api_implementation.cc"],
669 copts = COPTS + [
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800670 "-DPYTHON_PROTO2_CPP_IMPL_V2",
671 ],
672 linkshared = 1,
673 linkstatic = 1,
Manjunath Kudlura1949212015-12-08 08:24:37 -0800674 deps = select({
675 "//conditions:default": [],
David Z. Chen985c9682016-02-11 18:11:10 -0800676 ":use_fast_cpp_protos": ["//external:python_headers"],
Manjunath Kudlura1949212015-12-08 08:24:37 -0800677 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800678)
679
680cc_binary(
Richard Shindf5841f2016-10-18 13:16:44 -0700681 name = "python/google/protobuf/pyext/_message.so",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800682 srcs = glob([
683 "python/google/protobuf/pyext/*.cc",
684 "python/google/protobuf/pyext/*.h",
685 ]),
686 copts = COPTS + [
687 "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
Manjunath Kudlur99a3e302016-02-16 15:17:10 -0800688 ] + select({
689 "//conditions:default": [],
690 ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
691 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800692 includes = [
693 "python/",
694 "src/",
695 ],
696 linkshared = 1,
697 linkstatic = 1,
Manjunath Kudlura1949212015-12-08 08:24:37 -0800698 deps = [
699 ":protobuf",
Thomas Colthurst7c651422018-05-29 18:26:11 -0400700 ":proto_api",
Manjunath Kudlura1949212015-12-08 08:24:37 -0800701 ] + select({
702 "//conditions:default": [],
David Z. Chen985c9682016-02-11 18:11:10 -0800703 ":use_fast_cpp_protos": ["//external:python_headers"],
Manjunath Kudlura1949212015-12-08 08:24:37 -0800704 }),
705)
706
707config_setting(
708 name = "use_fast_cpp_protos",
709 values = {
710 "define": "use_fast_cpp_protos=true",
711 },
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800712)
713
Manjunath Kudlur99a3e302016-02-16 15:17:10 -0800714config_setting(
715 name = "allow_oversize_protos",
716 values = {
717 "define": "allow_oversize_protos=true",
718 },
719)
720
David Z. Chen02cd45c2016-05-20 16:49:04 -0700721# Copy the builtin proto files from src/google/protobuf to
722# python/google/protobuf. This way, the generated Python sources will be in the
723# same directory as the Python runtime sources. This is necessary for the
724# modules to be imported correctly since they are all part of the same Python
725# package.
726internal_copied_filegroup(
727 name = "protos_python",
728 srcs = WELL_KNOWN_PROTOS,
David Z. Chen02cd45c2016-05-20 16:49:04 -0700729 dest = "python",
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800730 strip_prefix = "src",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700731)
732
733# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
734# which case we can simply add :protos_python in srcs.
735COPIED_WELL_KNOWN_PROTOS = ["python/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
736
Jisi Liu993fb702015-10-19 17:19:49 -0700737py_proto_library(
Jisi Liu166e9bb2015-10-21 10:56:38 -0700738 name = "protobuf_python",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700739 srcs = COPIED_WELL_KNOWN_PROTOS,
740 include = "python",
Manjunath Kudlura1949212015-12-08 08:24:37 -0800741 data = select({
742 "//conditions:default": [],
743 ":use_fast_cpp_protos": [
Richard Shindf5841f2016-10-18 13:16:44 -0700744 ":python/google/protobuf/internal/_api_implementation.so",
745 ":python/google/protobuf/pyext/_message.so",
Manjunath Kudlura1949212015-12-08 08:24:37 -0800746 ],
747 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800748 default_runtime = "",
Jisi Liu04658a32015-10-20 15:00:13 -0700749 protoc = ":protoc",
David Z. Chen985c9682016-02-11 18:11:10 -0800750 py_libs = [
751 ":python_srcs",
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800752 "//external:six",
David Z. Chen985c9682016-02-11 18:11:10 -0800753 ],
Adam Michael6044b242017-03-10 18:06:34 -0500754 py_extra_srcs = glob(["python/**/__init__.py"]),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800755 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700756 visibility = ["//visibility:public"],
757)
758
David Z. Chen02cd45c2016-05-20 16:49:04 -0700759# Copy the test proto files from src/google/protobuf to
760# python/google/protobuf. This way, the generated Python sources will be in the
761# same directory as the Python runtime sources. This is necessary for the
762# modules to be imported correctly by the tests since they are all part of the
763# same Python package.
764internal_copied_filegroup(
765 name = "protos_python_test",
766 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
David Z. Chen02cd45c2016-05-20 16:49:04 -0700767 dest = "python",
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800768 strip_prefix = "src",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700769)
770
771# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
772# which case we can simply add :protos_python_test in srcs.
773COPIED_LITE_TEST_PROTOS = ["python/" + s for s in RELATIVE_LITE_TEST_PROTOS]
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800774
David Z. Chen02cd45c2016-05-20 16:49:04 -0700775COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]
776
Jisi Liu993fb702015-10-19 17:19:49 -0700777py_proto_library(
778 name = "python_common_test_protos",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700779 srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
780 include = "python",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800781 default_runtime = "",
Jisi Liu04658a32015-10-20 15:00:13 -0700782 protoc = ":protoc",
David Z. Chen5ebeefb2016-04-08 13:30:13 -0700783 srcs_version = "PY2AND3",
Jisi Liu166e9bb2015-10-21 10:56:38 -0700784 deps = [":protobuf_python"],
Jisi Liu993fb702015-10-19 17:19:49 -0700785)
786
787py_proto_library(
788 name = "python_specific_test_protos",
Jisi Liu68e13f42015-10-22 11:13:14 -0700789 srcs = glob([
790 "python/google/protobuf/internal/*.proto",
791 "python/google/protobuf/internal/import_test_package/*.proto",
792 ]),
Jisi Liu993fb702015-10-19 17:19:49 -0700793 include = "python",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800794 default_runtime = ":protobuf_python",
Jisi Liu04658a32015-10-20 15:00:13 -0700795 protoc = ":protoc",
David Z. Chen5ebeefb2016-04-08 13:30:13 -0700796 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700797 deps = [":python_common_test_protos"],
798)
799
800py_library(
801 name = "python_tests",
David Z. Chen985c9682016-02-11 18:11:10 -0800802 srcs = glob(
803 [
804 "python/google/protobuf/internal/*_test.py",
805 "python/google/protobuf/internal/test_util.py",
David Z. Chen02cd45c2016-05-20 16:49:04 -0700806 "python/google/protobuf/internal/import_test_package/__init__.py",
David Z. Chen985c9682016-02-11 18:11:10 -0800807 ],
808 ),
809 imports = ["python"],
Geoffrey Irving29799232015-12-03 13:11:19 -0800810 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700811 deps = [
Jisi Liu166e9bb2015-10-21 10:56:38 -0700812 ":protobuf_python",
Jisi Liu598480d2015-10-21 11:19:16 -0700813 ":python_common_test_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700814 ":python_specific_test_protos",
815 ],
816)
817
818internal_protobuf_py_tests(
Jisi Liu8f540262015-10-20 16:21:41 -0700819 name = "python_tests_batch",
Jisi Liu68e13f42015-10-22 11:13:14 -0700820 data = glob([
821 "src/google/protobuf/**/*",
822 ]),
Jisi Liu993fb702015-10-19 17:19:49 -0700823 modules = [
824 "descriptor_database_test",
825 "descriptor_pool_test",
826 "descriptor_test",
827 "generator_test",
828 "json_format_test",
829 "message_factory_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700830 "message_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700831 "proto_builder_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700832 "reflection_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700833 "service_reflection_test",
834 "symbol_database_test",
835 "text_encoding_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700836 "text_format_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700837 "unknown_fields_test",
838 "wire_format_test",
839 ],
840 deps = [":python_tests"],
841)
cgrushko45d92ae2016-12-02 19:40:50 -0500842
Thomas Colthurst7c651422018-05-29 18:26:11 -0400843cc_library(
844 name = "proto_api",
845 hdrs = ["python/google/protobuf/proto_api.h"],
846 deps = [
Thomas Colthurst7c651422018-05-29 18:26:11 -0400847 "//external:python_headers",
848 ],
Cory McLeanb7d3ec32018-06-11 12:18:45 -0400849 visibility = ["//visibility:public"],
Thomas Colthurst7c651422018-05-29 18:26:11 -0400850)
851
cgrushko45d92ae2016-12-02 19:40:50 -0500852proto_lang_toolchain(
Manjunath Kudlur2d430f82017-02-23 08:17:24 -0800853 name = "cc_toolchain",
854 command_line = "--cpp_out=$(OUT)",
855 runtime = ":protobuf",
856 visibility = ["//visibility:public"],
John Millikin350b1352018-02-24 11:36:49 -0800857 blacklisted_protos = [":_internal_wkt_protos_genrule"],
cgrushko45d92ae2016-12-02 19:40:50 -0500858)
cgrushkoe4baf3f2017-01-12 12:51:04 -0500859
860proto_lang_toolchain(
861 name = "java_toolchain",
862 command_line = "--java_out=$(OUT)",
863 runtime = ":protobuf_java",
864 visibility = ["//visibility:public"],
865)
makdharma286f0592017-05-01 09:49:26 -0700866
Thomas Van Lenten18aa2962018-11-01 09:37:14 -0400867alias(
868 name = "objectivec",
869 actual = ":protobuf_objc",
870 visibility = ["//visibility:public"],
871)
makdharma286f0592017-05-01 09:49:26 -0700872
873objc_library(
Thomas Van Lenten18aa2962018-11-01 09:37:14 -0400874 name = "protobuf_objc",
875 hdrs = [
876 "objectivec/GPBArray.h",
877 "objectivec/GPBBootstrap.h",
878 "objectivec/GPBCodedInputStream.h",
879 "objectivec/GPBCodedOutputStream.h",
880 "objectivec/GPBDescriptor.h",
881 "objectivec/GPBDictionary.h",
882 "objectivec/GPBExtensionInternals.h",
883 "objectivec/GPBExtensionRegistry.h",
884 "objectivec/GPBMessage.h",
885 "objectivec/GPBProtocolBuffers.h",
886 "objectivec/GPBProtocolBuffers_RuntimeSupport.h",
887 "objectivec/GPBRootObject.h",
888 "objectivec/GPBRuntimeTypes.h",
889 "objectivec/GPBUnknownField.h",
890 "objectivec/GPBUnknownFieldSet.h",
891 "objectivec/GPBUtilities.h",
892 "objectivec/GPBWellKnownTypes.h",
893 "objectivec/GPBWireFormat.h",
894 "objectivec/google/protobuf/Any.pbobjc.h",
895 "objectivec/google/protobuf/Api.pbobjc.h",
896 "objectivec/google/protobuf/Duration.pbobjc.h",
897 "objectivec/google/protobuf/Empty.pbobjc.h",
898 "objectivec/google/protobuf/FieldMask.pbobjc.h",
899 "objectivec/google/protobuf/SourceContext.pbobjc.h",
900 "objectivec/google/protobuf/Struct.pbobjc.h",
901 "objectivec/google/protobuf/Timestamp.pbobjc.h",
902 "objectivec/google/protobuf/Type.pbobjc.h",
903 "objectivec/google/protobuf/Wrappers.pbobjc.h",
904 # Package private headers, but exposed because the generated sources
905 # need to use them.
906 "objectivec/GPBArray_PackagePrivate.h",
907 "objectivec/GPBCodedInputStream_PackagePrivate.h",
908 "objectivec/GPBCodedOutputStream_PackagePrivate.h",
909 "objectivec/GPBDescriptor_PackagePrivate.h",
910 "objectivec/GPBDictionary_PackagePrivate.h",
911 "objectivec/GPBMessage_PackagePrivate.h",
912 "objectivec/GPBRootObject_PackagePrivate.h",
913 "objectivec/GPBUnknownFieldSet_PackagePrivate.h",
914 "objectivec/GPBUnknownField_PackagePrivate.h",
915 "objectivec/GPBUtilities_PackagePrivate.h",
916 ],
Benjamin Barenblat048f5c22018-07-11 13:20:01 -0400917 copts = [
918 "-Wno-vla",
919 ],
makdharma286f0592017-05-01 09:49:26 -0700920 includes = [
921 "objectivec",
922 ],
Thomas Van Lenten18aa2962018-11-01 09:37:14 -0400923 non_arc_srcs = [
924 "objectivec/GPBArray.m",
925 "objectivec/GPBCodedInputStream.m",
926 "objectivec/GPBCodedOutputStream.m",
927 "objectivec/GPBDescriptor.m",
928 "objectivec/GPBDictionary.m",
929 "objectivec/GPBExtensionInternals.m",
930 "objectivec/GPBExtensionRegistry.m",
931 "objectivec/GPBMessage.m",
932 "objectivec/GPBRootObject.m",
933 "objectivec/GPBUnknownField.m",
934 "objectivec/GPBUnknownFieldSet.m",
935 "objectivec/GPBUtilities.m",
936 "objectivec/GPBWellKnownTypes.m",
937 "objectivec/GPBWireFormat.m",
938 "objectivec/google/protobuf/Any.pbobjc.m",
939 "objectivec/google/protobuf/Api.pbobjc.m",
940 "objectivec/google/protobuf/Duration.pbobjc.m",
941 "objectivec/google/protobuf/Empty.pbobjc.m",
942 "objectivec/google/protobuf/FieldMask.pbobjc.m",
943 "objectivec/google/protobuf/SourceContext.pbobjc.m",
944 "objectivec/google/protobuf/Struct.pbobjc.m",
945 "objectivec/google/protobuf/Timestamp.pbobjc.m",
946 "objectivec/google/protobuf/Type.pbobjc.m",
947 "objectivec/google/protobuf/Wrappers.pbobjc.m",
948 ],
makdharma286f0592017-05-01 09:49:26 -0700949 visibility = ["//visibility:public"],
950)
Fahrzin Hemmati0d68b292018-03-26 19:08:26 -0700951
952################################################################################
953# Test generated proto support
954################################################################################
955
956genrule(
957 name = "generated_protos",
958 srcs = ["src/google/protobuf/unittest_import.proto"],
959 outs = ["unittest_gen.proto"],
960 cmd = "cat $(SRCS) | sed 's|google/|src/google/|' > $(OUTS)"
961)
962
963proto_library(
964 name = "generated_protos_proto",
Fahrzin Hemmati55962db2018-05-07 17:36:34 -0700965 srcs = [
966 "unittest_gen.proto",
967 "src/google/protobuf/unittest_import_public.proto",
968 ],
Fahrzin Hemmati0d68b292018-03-26 19:08:26 -0700969)
970
Fahrzin Hemmati0d68b292018-03-26 19:08:26 -0700971py_proto_library(
972 name = "generated_protos_py",
973 srcs = [
974 "unittest_gen.proto",
975 "src/google/protobuf/unittest_import_public.proto",
976 ],
977 default_runtime = "",
978 protoc = ":protoc",
979)