blob: 39ba0d9409403a2d2d98787e04897901fbace66b [file] [log] [blame]
Jisi Liud19604f2015-06-17 17:37:58 -07001# Bazel (http://bazel.io/) BUILD file for Protobuf.
2
3licenses(["notice"])
4
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -07005################################################################################
6# Protobuf Runtime Library
7################################################################################
8
Jisi Liud19604f2015-06-17 17:37:58 -07009COPTS = [
10 "-DHAVE_PTHREAD",
11 "-Wall",
12 "-Wwrite-strings",
13 "-Woverloaded-virtual",
14 "-Wno-sign-compare",
15 "-Wno-error=unused-function",
16]
17
18# Bazel should provide portable link_opts for pthread.
19LINK_OPTS = ["-lpthread"]
20
Jisi Liu04658a32015-10-20 15:00:13 -070021load(
22 "protobuf",
23 "cc_proto_library",
24 "py_proto_library",
Jisi Liubc4fd152015-10-20 16:02:58 -070025 "internal_copied_filegroup",
Jisi Liu04658a32015-10-20 15:00:13 -070026 "internal_protobuf_py_tests",
27)
Jisi Liu39362b32015-10-14 17:12:11 -070028
Pete Wardencb392042016-02-23 10:18:32 -080029config_setting(
Pete Wardenf0c1a862016-03-09 13:03:52 -080030 name = "ios_armv7",
Pete Wardencb392042016-02-23 10:18:32 -080031 values = {
32 "ios_cpu": "armv7",
Pete Wardenf0c1a862016-03-09 13:03:52 -080033 },
34)
35
36config_setting(
37 name = "ios_armv7s",
38 values = {
Pete Wardencb392042016-02-23 10:18:32 -080039 "ios_cpu": "armv7s",
Pete Wardenf0c1a862016-03-09 13:03:52 -080040 },
41)
42
43config_setting(
44 name = "ios_arm64",
45 values = {
Pete Wardencb392042016-02-23 10:18:32 -080046 "ios_cpu": "arm64",
47 },
48)
49
50IOS_ARM_COPTS = COPTS + [
51 "-DOS_IOS",
52 "-miphoneos-version-min=7.0",
53 "-arch armv7",
54 "-arch armv7s",
55 "-arch arm64",
56 "-D__thread=",
57 "-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/",
58]
59
Jisi Liud19604f2015-06-17 17:37:58 -070060cc_library(
61 name = "protobuf_lite",
62 srcs = [
63 # AUTOGEN(protobuf_lite_srcs)
64 "src/google/protobuf/arena.cc",
65 "src/google/protobuf/arenastring.cc",
66 "src/google/protobuf/extension_set.cc",
67 "src/google/protobuf/generated_message_util.cc",
68 "src/google/protobuf/io/coded_stream.cc",
69 "src/google/protobuf/io/zero_copy_stream.cc",
70 "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
71 "src/google/protobuf/message_lite.cc",
72 "src/google/protobuf/repeated_field.cc",
73 "src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc",
74 "src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -070075 "src/google/protobuf/stubs/bytestream.cc",
Jisi Liud19604f2015-06-17 17:37:58 -070076 "src/google/protobuf/stubs/common.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -070077 "src/google/protobuf/stubs/int128.cc",
Jisi Liud19604f2015-06-17 17:37:58 -070078 "src/google/protobuf/stubs/once.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -070079 "src/google/protobuf/stubs/status.cc",
80 "src/google/protobuf/stubs/statusor.cc",
81 "src/google/protobuf/stubs/stringpiece.cc",
Jisi Liud19604f2015-06-17 17:37:58 -070082 "src/google/protobuf/stubs/stringprintf.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -070083 "src/google/protobuf/stubs/structurally_valid.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -070084 "src/google/protobuf/stubs/strutil.cc",
85 "src/google/protobuf/stubs/time.cc",
Jisi Liud19604f2015-06-17 17:37:58 -070086 "src/google/protobuf/wire_format_lite.cc",
87 ],
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -080088 hdrs = glob(["src/google/protobuf/**/*.h"]),
Pete Wardencb392042016-02-23 10:18:32 -080089 copts = select({
Pete Wardenf0c1a862016-03-09 13:03:52 -080090 ":ios_armv7": IOS_ARM_COPTS,
91 ":ios_armv7s": IOS_ARM_COPTS,
92 ":ios_arm64": IOS_ARM_COPTS,
Pete Wardencb392042016-02-23 10:18:32 -080093 "//conditions:default": COPTS,
94 }),
Jisi Liud19604f2015-06-17 17:37:58 -070095 includes = ["src/"],
96 linkopts = LINK_OPTS,
97 visibility = ["//visibility:public"],
98)
99
100cc_library(
101 name = "protobuf",
102 srcs = [
103 # AUTOGEN(protobuf_srcs)
104 "src/google/protobuf/any.cc",
105 "src/google/protobuf/any.pb.cc",
106 "src/google/protobuf/api.pb.cc",
107 "src/google/protobuf/compiler/importer.cc",
108 "src/google/protobuf/compiler/parser.cc",
109 "src/google/protobuf/descriptor.cc",
110 "src/google/protobuf/descriptor.pb.cc",
111 "src/google/protobuf/descriptor_database.cc",
112 "src/google/protobuf/duration.pb.cc",
113 "src/google/protobuf/dynamic_message.cc",
114 "src/google/protobuf/empty.pb.cc",
115 "src/google/protobuf/extension_set_heavy.cc",
116 "src/google/protobuf/field_mask.pb.cc",
117 "src/google/protobuf/generated_message_reflection.cc",
118 "src/google/protobuf/io/gzip_stream.cc",
119 "src/google/protobuf/io/printer.cc",
120 "src/google/protobuf/io/strtod.cc",
121 "src/google/protobuf/io/tokenizer.cc",
122 "src/google/protobuf/io/zero_copy_stream_impl.cc",
123 "src/google/protobuf/map_field.cc",
124 "src/google/protobuf/message.cc",
125 "src/google/protobuf/reflection_ops.cc",
126 "src/google/protobuf/service.cc",
127 "src/google/protobuf/source_context.pb.cc",
128 "src/google/protobuf/struct.pb.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700129 "src/google/protobuf/stubs/mathlimits.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700130 "src/google/protobuf/stubs/substitute.cc",
131 "src/google/protobuf/text_format.cc",
132 "src/google/protobuf/timestamp.pb.cc",
133 "src/google/protobuf/type.pb.cc",
134 "src/google/protobuf/unknown_field_set.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700135 "src/google/protobuf/util/field_comparator.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700136 "src/google/protobuf/util/field_mask_util.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700137 "src/google/protobuf/util/internal/datapiece.cc",
138 "src/google/protobuf/util/internal/default_value_objectwriter.cc",
139 "src/google/protobuf/util/internal/error_listener.cc",
140 "src/google/protobuf/util/internal/field_mask_utility.cc",
141 "src/google/protobuf/util/internal/json_escaping.cc",
142 "src/google/protobuf/util/internal/json_objectwriter.cc",
143 "src/google/protobuf/util/internal/json_stream_parser.cc",
144 "src/google/protobuf/util/internal/object_writer.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800145 "src/google/protobuf/util/internal/proto_writer.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700146 "src/google/protobuf/util/internal/protostream_objectsource.cc",
147 "src/google/protobuf/util/internal/protostream_objectwriter.cc",
148 "src/google/protobuf/util/internal/type_info.cc",
149 "src/google/protobuf/util/internal/type_info_test_helper.cc",
150 "src/google/protobuf/util/internal/utility.cc",
151 "src/google/protobuf/util/json_util.cc",
152 "src/google/protobuf/util/message_differencer.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700153 "src/google/protobuf/util/time_util.cc",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700154 "src/google/protobuf/util/type_resolver_util.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700155 "src/google/protobuf/wire_format.cc",
156 "src/google/protobuf/wrappers.pb.cc",
157 ],
Lukacs T. Berki915d9cd2015-11-16 09:36:32 +0100158 hdrs = glob(["src/**/*.h"]),
Pete Wardencb392042016-02-23 10:18:32 -0800159 copts = select({
Pete Wardenf0c1a862016-03-09 13:03:52 -0800160 ":ios_armv7": IOS_ARM_COPTS,
161 ":ios_armv7s": IOS_ARM_COPTS,
162 ":ios_arm64": IOS_ARM_COPTS,
Pete Wardencb392042016-02-23 10:18:32 -0800163 "//conditions:default": COPTS,
164 }),
Jisi Liud19604f2015-06-17 17:37:58 -0700165 includes = ["src/"],
166 linkopts = LINK_OPTS,
167 visibility = ["//visibility:public"],
168 deps = [":protobuf_lite"],
169)
170
Jisi Liu14c8f8a2015-10-20 15:36:22 -0700171objc_library(
172 name = "protobuf_objc",
173 hdrs = ["objectivec/GPBProtocolBuffers.h"],
174 includes = ["objectivec"],
175 non_arc_srcs = ["objectivec/GPBProtocolBuffers.m"],
176 visibility = ["//visibility:public"],
177)
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700178
Jisi Liu993fb702015-10-19 17:19:49 -0700179RELATIVE_WELL_KNOWN_PROTOS = [
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700180 # AUTOGEN(well_known_protos)
181 "google/protobuf/any.proto",
182 "google/protobuf/api.proto",
183 "google/protobuf/compiler/plugin.proto",
184 "google/protobuf/descriptor.proto",
185 "google/protobuf/duration.proto",
186 "google/protobuf/empty.proto",
187 "google/protobuf/field_mask.proto",
188 "google/protobuf/source_context.proto",
189 "google/protobuf/struct.proto",
190 "google/protobuf/timestamp.proto",
191 "google/protobuf/type.proto",
192 "google/protobuf/wrappers.proto",
193]
194
Jisi Liu993fb702015-10-19 17:19:49 -0700195WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
196
Jisi Liu39362b32015-10-14 17:12:11 -0700197cc_proto_library(
198 name = "cc_wkt_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700199 srcs = WELL_KNOWN_PROTOS,
Jisi Liu3101e732015-10-16 12:46:26 -0700200 include = "src",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800201 default_runtime = ":protobuf",
Jisi Liu993fb702015-10-19 17:19:49 -0700202 internal_bootstrap_hack = 1,
Jisi Liu04658a32015-10-20 15:00:13 -0700203 protoc = ":protoc",
Jisi Liu6a40bf82015-11-17 12:36:21 -0800204 visibility = ["//visibility:public"],
Jisi Liu39362b32015-10-14 17:12:11 -0700205)
206
Jorge Canizalesd5d7bb32015-06-28 15:23:02 -0700207################################################################################
208# Protocol Buffers Compiler
209################################################################################
210
Jisi Liud19604f2015-06-17 17:37:58 -0700211cc_library(
212 name = "protoc_lib",
213 srcs = [
214 # AUTOGEN(protoc_lib_srcs)
215 "src/google/protobuf/compiler/code_generator.cc",
216 "src/google/protobuf/compiler/command_line_interface.cc",
217 "src/google/protobuf/compiler/cpp/cpp_enum.cc",
218 "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
219 "src/google/protobuf/compiler/cpp/cpp_extension.cc",
220 "src/google/protobuf/compiler/cpp/cpp_field.cc",
221 "src/google/protobuf/compiler/cpp/cpp_file.cc",
222 "src/google/protobuf/compiler/cpp/cpp_generator.cc",
223 "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
224 "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
225 "src/google/protobuf/compiler/cpp/cpp_message.cc",
226 "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
227 "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
228 "src/google/protobuf/compiler/cpp/cpp_service.cc",
229 "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
Ming Zhao5cdd9362015-10-05 14:37:21 -0700230 "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700231 "src/google/protobuf/compiler/csharp/csharp_enum.cc",
232 "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700233 "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
234 "src/google/protobuf/compiler/csharp/csharp_generator.cc",
235 "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
Jon Skeetb2ac8682015-07-15 13:17:42 +0100236 "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700237 "src/google/protobuf/compiler/csharp/csharp_message.cc",
238 "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
239 "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
Jon Skeeta6361a12015-11-19 13:05:17 +0000240 "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700241 "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
242 "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
243 "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
244 "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
Jon Skeetb2ac8682015-07-15 13:17:42 +0100245 "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700246 "src/google/protobuf/compiler/java/java_context.cc",
247 "src/google/protobuf/compiler/java/java_doc_comment.cc",
248 "src/google/protobuf/compiler/java/java_enum.cc",
249 "src/google/protobuf/compiler/java/java_enum_field.cc",
250 "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700251 "src/google/protobuf/compiler/java/java_enum_lite.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700252 "src/google/protobuf/compiler/java/java_extension.cc",
253 "src/google/protobuf/compiler/java/java_field.cc",
254 "src/google/protobuf/compiler/java/java_file.cc",
255 "src/google/protobuf/compiler/java/java_generator.cc",
256 "src/google/protobuf/compiler/java/java_generator_factory.cc",
257 "src/google/protobuf/compiler/java/java_helpers.cc",
258 "src/google/protobuf/compiler/java/java_lazy_message_field.cc",
259 "src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc",
260 "src/google/protobuf/compiler/java/java_map_field.cc",
261 "src/google/protobuf/compiler/java/java_map_field_lite.cc",
262 "src/google/protobuf/compiler/java/java_message.cc",
263 "src/google/protobuf/compiler/java/java_message_builder.cc",
264 "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
265 "src/google/protobuf/compiler/java/java_message_field.cc",
266 "src/google/protobuf/compiler/java/java_message_field_lite.cc",
267 "src/google/protobuf/compiler/java/java_message_lite.cc",
268 "src/google/protobuf/compiler/java/java_name_resolver.cc",
269 "src/google/protobuf/compiler/java/java_primitive_field.cc",
270 "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
271 "src/google/protobuf/compiler/java/java_service.cc",
272 "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
273 "src/google/protobuf/compiler/java/java_string_field.cc",
274 "src/google/protobuf/compiler/java/java_string_field_lite.cc",
275 "src/google/protobuf/compiler/javanano/javanano_enum.cc",
276 "src/google/protobuf/compiler/javanano/javanano_enum_field.cc",
277 "src/google/protobuf/compiler/javanano/javanano_extension.cc",
278 "src/google/protobuf/compiler/javanano/javanano_field.cc",
279 "src/google/protobuf/compiler/javanano/javanano_file.cc",
280 "src/google/protobuf/compiler/javanano/javanano_generator.cc",
281 "src/google/protobuf/compiler/javanano/javanano_helpers.cc",
282 "src/google/protobuf/compiler/javanano/javanano_map_field.cc",
283 "src/google/protobuf/compiler/javanano/javanano_message.cc",
284 "src/google/protobuf/compiler/javanano/javanano_message_field.cc",
285 "src/google/protobuf/compiler/javanano/javanano_primitive_field.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800286 "src/google/protobuf/compiler/js/js_generator.cc",
Jisi Liud19604f2015-06-17 17:37:58 -0700287 "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
288 "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
289 "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
290 "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
291 "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
292 "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
293 "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
294 "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
295 "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
296 "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
297 "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
298 "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
299 "src/google/protobuf/compiler/plugin.cc",
300 "src/google/protobuf/compiler/plugin.pb.cc",
301 "src/google/protobuf/compiler/python/python_generator.cc",
302 "src/google/protobuf/compiler/ruby/ruby_generator.cc",
303 "src/google/protobuf/compiler/subprocess.cc",
304 "src/google/protobuf/compiler/zip_writer.cc",
305 ],
306 copts = COPTS,
307 includes = ["src/"],
308 linkopts = LINK_OPTS,
309 visibility = ["//visibility:public"],
310 deps = [":protobuf"],
311)
312
313cc_binary(
314 name = "protoc",
315 srcs = ["src/google/protobuf/compiler/main.cc"],
Jisi Liud19604f2015-06-17 17:37:58 -0700316 linkopts = LINK_OPTS,
317 visibility = ["//visibility:public"],
318 deps = [":protoc_lib"],
319)
320
Jisi Liud19604f2015-06-17 17:37:58 -0700321################################################################################
322# Tests
323################################################################################
324
Jisi Liu993fb702015-10-19 17:19:49 -0700325RELATIVE_LITE_TEST_PROTOS = [
Jisi Liud19604f2015-06-17 17:37:58 -0700326 # AUTOGEN(lite_test_protos)
327 "google/protobuf/map_lite_unittest.proto",
328 "google/protobuf/unittest_import_lite.proto",
329 "google/protobuf/unittest_import_public_lite.proto",
330 "google/protobuf/unittest_lite.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700331 "google/protobuf/unittest_no_arena_lite.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700332]
333
Jisi Liu993fb702015-10-19 17:19:49 -0700334LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
335
336RELATIVE_TEST_PROTOS = [
Jisi Liud19604f2015-06-17 17:37:58 -0700337 # AUTOGEN(test_protos)
338 "google/protobuf/any_test.proto",
339 "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
340 "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
341 "google/protobuf/map_proto2_unittest.proto",
342 "google/protobuf/map_unittest.proto",
343 "google/protobuf/unittest.proto",
344 "google/protobuf/unittest_arena.proto",
345 "google/protobuf/unittest_custom_options.proto",
346 "google/protobuf/unittest_drop_unknown_fields.proto",
347 "google/protobuf/unittest_embed_optimize_for.proto",
348 "google/protobuf/unittest_empty.proto",
349 "google/protobuf/unittest_enormous_descriptor.proto",
350 "google/protobuf/unittest_import.proto",
351 "google/protobuf/unittest_import_public.proto",
352 "google/protobuf/unittest_lite_imports_nonlite.proto",
353 "google/protobuf/unittest_mset.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700354 "google/protobuf/unittest_mset_wire_format.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700355 "google/protobuf/unittest_no_arena.proto",
356 "google/protobuf/unittest_no_arena_import.proto",
357 "google/protobuf/unittest_no_field_presence.proto",
358 "google/protobuf/unittest_no_generic_services.proto",
359 "google/protobuf/unittest_optimize_for.proto",
360 "google/protobuf/unittest_preserve_unknown_enum.proto",
361 "google/protobuf/unittest_preserve_unknown_enum2.proto",
362 "google/protobuf/unittest_proto3_arena.proto",
363 "google/protobuf/unittest_well_known_types.proto",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700364 "google/protobuf/util/internal/testdata/anys.proto",
365 "google/protobuf/util/internal/testdata/books.proto",
366 "google/protobuf/util/internal/testdata/default_value.proto",
367 "google/protobuf/util/internal/testdata/default_value_test.proto",
368 "google/protobuf/util/internal/testdata/field_mask.proto",
369 "google/protobuf/util/internal/testdata/maps.proto",
Jisi Liub90f9f82015-08-25 17:06:33 -0700370 "google/protobuf/util/internal/testdata/oneofs.proto",
Jisi Liuaf3eafd2015-06-18 13:38:36 -0700371 "google/protobuf/util/internal/testdata/struct.proto",
372 "google/protobuf/util/internal/testdata/timestamp_duration.proto",
373 "google/protobuf/util/json_format_proto3.proto",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800374 "google/protobuf/util/message_differencer_unittest.proto",
Jisi Liud19604f2015-06-17 17:37:58 -0700375]
376
Jisi Liu993fb702015-10-19 17:19:49 -0700377TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
378
Jisi Liu39362b32015-10-14 17:12:11 -0700379cc_proto_library(
380 name = "cc_test_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700381 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
Jisi Liu3101e732015-10-16 12:46:26 -0700382 include = "src",
Jisi Liube92ffb2015-10-27 15:11:38 -0700383 default_runtime = ":protobuf",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800384 protoc = ":protoc",
Jisi Liud8701b52015-10-16 11:44:21 -0700385 deps = [":cc_wkt_protos"],
Jisi Liud19604f2015-06-17 17:37:58 -0700386)
387
388COMMON_TEST_SRCS = [
389 # AUTOGEN(common_test_srcs)
390 "src/google/protobuf/arena_test_util.cc",
391 "src/google/protobuf/map_test_util.cc",
392 "src/google/protobuf/test_util.cc",
393 "src/google/protobuf/testing/file.cc",
394 "src/google/protobuf/testing/googletest.cc",
395]
396
Jisi Liu7a0c4312015-06-18 16:45:27 -0700397cc_binary(
398 name = "test_plugin",
399 srcs = [
400 # AUTOGEN(test_plugin_srcs)
401 "src/google/protobuf/compiler/mock_code_generator.cc",
402 "src/google/protobuf/compiler/test_plugin.cc",
403 "src/google/protobuf/testing/file.cc",
404 ],
405 deps = [
406 ":protobuf",
407 ":protoc_lib",
408 "//external:gtest",
409 ],
410)
411
412cc_test(
413 name = "protobuf_test",
Jisi Liu39362b32015-10-14 17:12:11 -0700414 srcs = COMMON_TEST_SRCS + [
Jisi Liu7a0c4312015-06-18 16:45:27 -0700415 # AUTOGEN(test_srcs)
416 "src/google/protobuf/any_test.cc",
417 "src/google/protobuf/arena_unittest.cc",
418 "src/google/protobuf/arenastring_unittest.cc",
419 "src/google/protobuf/compiler/command_line_interface_unittest.cc",
420 "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
421 "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
422 "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
423 "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
424 "src/google/protobuf/compiler/importer_unittest.cc",
425 "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
426 "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
427 "src/google/protobuf/compiler/mock_code_generator.cc",
428 "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
429 "src/google/protobuf/compiler/parser_unittest.cc",
430 "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
431 "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
432 "src/google/protobuf/descriptor_database_unittest.cc",
433 "src/google/protobuf/descriptor_unittest.cc",
434 "src/google/protobuf/drop_unknown_fields_test.cc",
435 "src/google/protobuf/dynamic_message_unittest.cc",
436 "src/google/protobuf/extension_set_unittest.cc",
437 "src/google/protobuf/generated_message_reflection_unittest.cc",
438 "src/google/protobuf/io/coded_stream_unittest.cc",
439 "src/google/protobuf/io/printer_unittest.cc",
440 "src/google/protobuf/io/tokenizer_unittest.cc",
441 "src/google/protobuf/io/zero_copy_stream_unittest.cc",
442 "src/google/protobuf/map_field_test.cc",
443 "src/google/protobuf/map_test.cc",
444 "src/google/protobuf/message_unittest.cc",
445 "src/google/protobuf/no_field_presence_test.cc",
446 "src/google/protobuf/preserve_unknown_enum_test.cc",
447 "src/google/protobuf/proto3_arena_unittest.cc",
448 "src/google/protobuf/reflection_ops_unittest.cc",
449 "src/google/protobuf/repeated_field_reflection_unittest.cc",
450 "src/google/protobuf/repeated_field_unittest.cc",
451 "src/google/protobuf/stubs/bytestream_unittest.cc",
452 "src/google/protobuf/stubs/common_unittest.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700453 "src/google/protobuf/stubs/int128_unittest.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700454 "src/google/protobuf/stubs/once_unittest.cc",
455 "src/google/protobuf/stubs/status_test.cc",
456 "src/google/protobuf/stubs/statusor_test.cc",
457 "src/google/protobuf/stubs/stringpiece_unittest.cc",
458 "src/google/protobuf/stubs/stringprintf_unittest.cc",
459 "src/google/protobuf/stubs/structurally_valid_unittest.cc",
460 "src/google/protobuf/stubs/strutil_unittest.cc",
461 "src/google/protobuf/stubs/template_util_unittest.cc",
462 "src/google/protobuf/stubs/time_test.cc",
463 "src/google/protobuf/stubs/type_traits_unittest.cc",
464 "src/google/protobuf/text_format_unittest.cc",
465 "src/google/protobuf/unknown_field_set_unittest.cc",
466 "src/google/protobuf/util/field_comparator_test.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700467 "src/google/protobuf/util/field_mask_util_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700468 "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
469 "src/google/protobuf/util/internal/json_objectwriter_test.cc",
470 "src/google/protobuf/util/internal/json_stream_parser_test.cc",
471 "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
472 "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
473 "src/google/protobuf/util/internal/type_info_test_helper.cc",
474 "src/google/protobuf/util/json_util_test.cc",
Feng Xiaoef6c72b2015-12-28 17:33:55 -0800475 "src/google/protobuf/util/message_differencer_unittest.cc",
Jisi Liub90f9f82015-08-25 17:06:33 -0700476 "src/google/protobuf/util/time_util_test.cc",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700477 "src/google/protobuf/util/type_resolver_util_test.cc",
478 "src/google/protobuf/well_known_types_unittest.cc",
479 "src/google/protobuf/wire_format_unittest.cc",
480 ],
481 copts = COPTS,
482 data = [
483 ":test_plugin",
Jisi Liu598480d2015-10-21 11:19:16 -0700484 ] + glob([
485 "src/google/protobuf/**/*",
486 ]),
Jisi Liu7a0c4312015-06-18 16:45:27 -0700487 includes = [
488 "src/",
489 ],
490 linkopts = LINK_OPTS,
491 deps = [
Jisi Liu993fb702015-10-19 17:19:49 -0700492 ":cc_test_protos",
Jisi Liu7a0c4312015-06-18 16:45:27 -0700493 ":protobuf",
494 ":protoc_lib",
495 "//external:gtest_main",
496 ],
497)
Jisi Liu993fb702015-10-19 17:19:49 -0700498
499################################################################################
500# Java support
501################################################################################
502genrule(
Ming Zhao4fe03812016-01-21 23:03:28 -0800503 name = "gen_well_known_protos_java",
504 srcs = WELL_KNOWN_PROTOS,
505 outs = [
Manjunath Kudlur99a3e302016-02-16 15:17:10 -0800506 "wellknown.srcjar",
Ming Zhao4fe03812016-01-21 23:03:28 -0800507 ],
508 cmd = "$(location :protoc) --java_out=$(@D)/wellknown.jar" +
Manjunath Kudlur99a3e302016-02-16 15:17:10 -0800509 " -Isrc $(SRCS) " +
510 " && mv $(@D)/wellknown.jar $(@D)/wellknown.srcjar",
Jisi Liu993fb702015-10-19 17:19:49 -0700511 tools = [":protoc"],
512)
513
514java_library(
Jisi Liu166e9bb2015-10-21 10:56:38 -0700515 name = "protobuf_java",
Jisi Liu993fb702015-10-19 17:19:49 -0700516 srcs = glob([
Ming Zhao4fe03812016-01-21 23:03:28 -0800517 "java/core/src/main/java/com/google/protobuf/*.java",
Jisi Liu993fb702015-10-19 17:19:49 -0700518 ]) + [
Ming Zhao4fe03812016-01-21 23:03:28 -0800519 ":gen_well_known_protos_java",
Jisi Liu993fb702015-10-19 17:19:49 -0700520 ],
521 visibility = ["//visibility:public"],
522)
523
524################################################################################
525# Python support
526################################################################################
527
Jisi Liu7b948cc2015-10-19 17:56:27 -0700528# Hack:
529# protoc generated files contain imports like:
530# "from google.protobuf.xxx import yyy"
531# However, the sources files of the python runtime are not directly under
532# "google/protobuf" (they are under python/google/protobuf). We workaround
533# this by copying runtime source files into the desired location to workaround
534# the import issue. Ideally py_library should support something similiar to the
535# "include" attribute in cc_library to inject the PYTHON_PATH for all libraries
536# that depend on the target.
537#
538# If you use python protobuf as a third_party library in your bazel managed
Jisi Liue1f60f52015-10-22 13:55:37 -0700539# project:
540# 1) Please import the whole package to //google/protobuf in your
Jisi Liu7b948cc2015-10-19 17:56:27 -0700541# project. Otherwise, bazel disallows generated files out of the current
542# package, thus we won't be able to copy protobuf runtime files into
543# //google/protobuf/.
Jisi Liue1f60f52015-10-22 13:55:37 -0700544# 2) The runtime also requires "six" for Python2/3 compatibility, please see the
545# WORKSPACE file and bind "six" to your workspace as well.
Jisi Liubc4fd152015-10-20 16:02:58 -0700546internal_copied_filegroup(
Jisi Liu993fb702015-10-19 17:19:49 -0700547 name = "python_srcs",
548 srcs = glob(
549 [
550 "python/google/protobuf/*.py",
551 "python/google/protobuf/**/*.py",
552 ],
553 exclude = [
554 "python/google/protobuf/internal/*_test.py",
555 "python/google/protobuf/internal/test_util.py",
556 ],
557 ),
558 include = "python",
559)
560
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800561cc_binary(
Manjunath Kudlurd03ef202015-12-08 10:46:17 -0800562 name = "internal/_api_implementation.so",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800563 srcs = ["python/google/protobuf/internal/api_implementation.cc"],
564 copts = COPTS + [
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800565 "-DPYTHON_PROTO2_CPP_IMPL_V2",
566 ],
567 linkshared = 1,
568 linkstatic = 1,
Manjunath Kudlura1949212015-12-08 08:24:37 -0800569 deps = select({
570 "//conditions:default": [],
571 ":use_fast_cpp_protos": ["//util/python:python_headers"],
572 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800573)
574
575cc_binary(
Manjunath Kudlurd03ef202015-12-08 10:46:17 -0800576 name = "pyext/_message.so",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800577 srcs = glob([
578 "python/google/protobuf/pyext/*.cc",
579 "python/google/protobuf/pyext/*.h",
580 ]),
581 copts = COPTS + [
582 "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
Manjunath Kudlur99a3e302016-02-16 15:17:10 -0800583 ] + select({
584 "//conditions:default": [],
585 ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
586 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800587 includes = [
588 "python/",
589 "src/",
590 ],
591 linkshared = 1,
592 linkstatic = 1,
Manjunath Kudlura1949212015-12-08 08:24:37 -0800593 deps = [
594 ":protobuf",
595 ] + select({
596 "//conditions:default": [],
597 ":use_fast_cpp_protos": ["//util/python:python_headers"],
598 }),
599)
600
601config_setting(
602 name = "use_fast_cpp_protos",
603 values = {
604 "define": "use_fast_cpp_protos=true",
605 },
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800606)
607
Manjunath Kudlur99a3e302016-02-16 15:17:10 -0800608config_setting(
609 name = "allow_oversize_protos",
610 values = {
611 "define": "allow_oversize_protos=true",
612 },
613)
614
Jisi Liu993fb702015-10-19 17:19:49 -0700615py_proto_library(
Jisi Liu166e9bb2015-10-21 10:56:38 -0700616 name = "protobuf_python",
Jisi Liu993fb702015-10-19 17:19:49 -0700617 srcs = WELL_KNOWN_PROTOS,
618 include = "src",
Manjunath Kudlura1949212015-12-08 08:24:37 -0800619 data = select({
620 "//conditions:default": [],
621 ":use_fast_cpp_protos": [
Manjunath Kudlurd03ef202015-12-08 10:46:17 -0800622 ":internal/_api_implementation.so",
623 ":pyext/_message.so",
Manjunath Kudlura1949212015-12-08 08:24:37 -0800624 ],
625 }),
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800626 default_runtime = "",
Jisi Liu04658a32015-10-20 15:00:13 -0700627 protoc = ":protoc",
Jisi Liu993fb702015-10-19 17:19:49 -0700628 py_extra_srcs = [":python_srcs"],
Jisi Liufbc51b72015-10-22 13:38:17 -0700629 py_libs = ["//external:six"],
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800630 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700631 visibility = ["//visibility:public"],
632)
633
Jisi Liubc4fd152015-10-20 16:02:58 -0700634internal_copied_filegroup(
Jisi Liu993fb702015-10-19 17:19:49 -0700635 name = "python_test_srcs",
636 srcs = glob(
637 [
638 "python/google/protobuf/internal/*_test.py",
639 "python/google/protobuf/internal/test_util.py",
640 ],
641 ),
642 include = "python",
643)
644
645py_proto_library(
646 name = "python_common_test_protos",
647 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
648 include = "src",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800649 default_runtime = "",
Jisi Liu04658a32015-10-20 15:00:13 -0700650 protoc = ":protoc",
Jisi Liu166e9bb2015-10-21 10:56:38 -0700651 deps = [":protobuf_python"],
Jisi Liu993fb702015-10-19 17:19:49 -0700652)
653
654py_proto_library(
655 name = "python_specific_test_protos",
Jisi Liu68e13f42015-10-22 11:13:14 -0700656 srcs = glob([
657 "python/google/protobuf/internal/*.proto",
658 "python/google/protobuf/internal/import_test_package/*.proto",
659 ]),
Jisi Liu993fb702015-10-19 17:19:49 -0700660 include = "python",
Manjunath Kudlur3ff1dca2015-12-07 13:08:21 -0800661 default_runtime = ":protobuf_python",
Jisi Liu04658a32015-10-20 15:00:13 -0700662 protoc = ":protoc",
Jisi Liu993fb702015-10-19 17:19:49 -0700663 deps = [":python_common_test_protos"],
664)
665
666py_library(
667 name = "python_tests",
668 srcs = [":python_test_srcs"],
Geoffrey Irving29799232015-12-03 13:11:19 -0800669 srcs_version = "PY2AND3",
Jisi Liu993fb702015-10-19 17:19:49 -0700670 deps = [
Jisi Liu166e9bb2015-10-21 10:56:38 -0700671 ":protobuf_python",
Jisi Liu598480d2015-10-21 11:19:16 -0700672 ":python_common_test_protos",
Jisi Liu993fb702015-10-19 17:19:49 -0700673 ":python_specific_test_protos",
674 ],
675)
676
677internal_protobuf_py_tests(
Jisi Liu8f540262015-10-20 16:21:41 -0700678 name = "python_tests_batch",
Jisi Liu68e13f42015-10-22 11:13:14 -0700679 data = glob([
680 "src/google/protobuf/**/*",
681 ]),
Jisi Liu993fb702015-10-19 17:19:49 -0700682 modules = [
683 "descriptor_database_test",
684 "descriptor_pool_test",
685 "descriptor_test",
686 "generator_test",
687 "json_format_test",
688 "message_factory_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700689 "message_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700690 "proto_builder_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700691 "reflection_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700692 "service_reflection_test",
693 "symbol_database_test",
694 "text_encoding_test",
Jisi Liu68e13f42015-10-22 11:13:14 -0700695 "text_format_test",
Jisi Liu993fb702015-10-19 17:19:49 -0700696 "unknown_fields_test",
697 "wire_format_test",
698 ],
699 deps = [":python_tests"],
700)