blob: 9b5c4ffad5537585dfa26a65c30ac3c411be4346 [file] [log] [blame]
Brian Silverman9c614bc2016-02-15 20:20:02 -05001# Bazel (http://bazel.io/) BUILD file for Protobuf.
2
3licenses(["notice"])
4
Austin Schuhf9724442018-10-28 20:30:21 -07005exports_files(["LICENSE"])
6
7################################################################################
8# Java 9 configuration
9################################################################################
10
11config_setting(
12 name = "jdk9",
13 values = {
14 "java_toolchain": "@bazel_tools//tools/jdk:toolchain_jdk9",
15 },
16)
Brian Silverman3fca9d72016-02-20 02:32:51 -050017
Brian Silverman9c614bc2016-02-15 20:20:02 -050018################################################################################
19# Protobuf Runtime Library
20################################################################################
21
Austin Schuhf9724442018-10-28 20:30:21 -070022config_setting(
23 name = "msvc",
24 values = {"compiler": "msvc-cl"},
25 visibility = ["//visibility:public"],
26)
27
28config_setting(
29 name = "android",
30 values = {
31 "crosstool_top": "//external:android/crosstool",
32 },
33)
34
35# Android and MSVC builds do not need to link in a separate pthread library.
36LINK_OPTS = select({
37 ":android": [],
38 ":msvc": [],
39 "//conditions:default": [
40 "-lpthread",
41 "-lm",
Brian Silverman3fca9d72016-02-20 02:32:51 -050042 ],
43})
Brian Silverman9c614bc2016-02-15 20:20:02 -050044
Brian Silverman9c614bc2016-02-15 20:20:02 -050045load(
Austin Schuh4f857292018-02-15 23:42:04 -080046 ":protobuf.bzl",
Austin Schuhdde64052019-12-11 20:28:00 -080047 "COPTS",
Brian Silverman9c614bc2016-02-15 20:20:02 -050048 "cc_proto_library",
Brian Silverman9c614bc2016-02-15 20:20:02 -050049 "internal_copied_filegroup",
Austin Schuhf9724442018-10-28 20:30:21 -070050 "internal_gen_well_known_protos_java",
Brian Silverman9c614bc2016-02-15 20:20:02 -050051 "internal_protobuf_py_tests",
Austin Schuhdde64052019-12-11 20:28:00 -080052 "py_proto_library",
Brian Silverman9c614bc2016-02-15 20:20:02 -050053)
54
55cc_library(
56 name = "protobuf_lite",
57 srcs = [
58 # AUTOGEN(protobuf_lite_srcs)
59 "src/google/protobuf/arena.cc",
60 "src/google/protobuf/arenastring.cc",
61 "src/google/protobuf/extension_set.cc",
Austin Schuhf9724442018-10-28 20:30:21 -070062 "src/google/protobuf/generated_message_table_driven_lite.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -050063 "src/google/protobuf/generated_message_util.cc",
Austin Schuhf9724442018-10-28 20:30:21 -070064 "src/google/protobuf/implicit_weak_message.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -050065 "src/google/protobuf/io/coded_stream.cc",
66 "src/google/protobuf/io/zero_copy_stream.cc",
67 "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
68 "src/google/protobuf/message_lite.cc",
69 "src/google/protobuf/repeated_field.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -050070 "src/google/protobuf/stubs/bytestream.cc",
71 "src/google/protobuf/stubs/common.cc",
72 "src/google/protobuf/stubs/int128.cc",
Austin Schuhf9724442018-10-28 20:30:21 -070073 "src/google/protobuf/stubs/io_win32.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -050074 "src/google/protobuf/stubs/status.cc",
75 "src/google/protobuf/stubs/statusor.cc",
76 "src/google/protobuf/stubs/stringpiece.cc",
77 "src/google/protobuf/stubs/stringprintf.cc",
78 "src/google/protobuf/stubs/structurally_valid.cc",
79 "src/google/protobuf/stubs/strutil.cc",
80 "src/google/protobuf/stubs/time.cc",
81 "src/google/protobuf/wire_format_lite.cc",
82 ],
83 hdrs = glob(["src/google/protobuf/**/*.h"]),
84 copts = COPTS,
85 includes = ["src/"],
86 linkopts = LINK_OPTS,
87 visibility = ["//visibility:public"],
88)
89
90cc_library(
91 name = "protobuf",
92 srcs = [
93 # AUTOGEN(protobuf_srcs)
94 "src/google/protobuf/any.cc",
95 "src/google/protobuf/any.pb.cc",
96 "src/google/protobuf/api.pb.cc",
97 "src/google/protobuf/compiler/importer.cc",
98 "src/google/protobuf/compiler/parser.cc",
99 "src/google/protobuf/descriptor.cc",
100 "src/google/protobuf/descriptor.pb.cc",
101 "src/google/protobuf/descriptor_database.cc",
102 "src/google/protobuf/duration.pb.cc",
103 "src/google/protobuf/dynamic_message.cc",
104 "src/google/protobuf/empty.pb.cc",
105 "src/google/protobuf/extension_set_heavy.cc",
106 "src/google/protobuf/field_mask.pb.cc",
107 "src/google/protobuf/generated_message_reflection.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700108 "src/google/protobuf/generated_message_table_driven.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500109 "src/google/protobuf/io/gzip_stream.cc",
110 "src/google/protobuf/io/printer.cc",
111 "src/google/protobuf/io/strtod.cc",
112 "src/google/protobuf/io/tokenizer.cc",
113 "src/google/protobuf/io/zero_copy_stream_impl.cc",
114 "src/google/protobuf/map_field.cc",
115 "src/google/protobuf/message.cc",
116 "src/google/protobuf/reflection_ops.cc",
117 "src/google/protobuf/service.cc",
118 "src/google/protobuf/source_context.pb.cc",
119 "src/google/protobuf/struct.pb.cc",
120 "src/google/protobuf/stubs/mathlimits.cc",
121 "src/google/protobuf/stubs/substitute.cc",
122 "src/google/protobuf/text_format.cc",
123 "src/google/protobuf/timestamp.pb.cc",
124 "src/google/protobuf/type.pb.cc",
125 "src/google/protobuf/unknown_field_set.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700126 "src/google/protobuf/util/delimited_message_util.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500127 "src/google/protobuf/util/field_comparator.cc",
128 "src/google/protobuf/util/field_mask_util.cc",
129 "src/google/protobuf/util/internal/datapiece.cc",
130 "src/google/protobuf/util/internal/default_value_objectwriter.cc",
131 "src/google/protobuf/util/internal/error_listener.cc",
132 "src/google/protobuf/util/internal/field_mask_utility.cc",
133 "src/google/protobuf/util/internal/json_escaping.cc",
134 "src/google/protobuf/util/internal/json_objectwriter.cc",
135 "src/google/protobuf/util/internal/json_stream_parser.cc",
136 "src/google/protobuf/util/internal/object_writer.cc",
137 "src/google/protobuf/util/internal/proto_writer.cc",
138 "src/google/protobuf/util/internal/protostream_objectsource.cc",
139 "src/google/protobuf/util/internal/protostream_objectwriter.cc",
140 "src/google/protobuf/util/internal/type_info.cc",
141 "src/google/protobuf/util/internal/type_info_test_helper.cc",
142 "src/google/protobuf/util/internal/utility.cc",
143 "src/google/protobuf/util/json_util.cc",
144 "src/google/protobuf/util/message_differencer.cc",
145 "src/google/protobuf/util/time_util.cc",
146 "src/google/protobuf/util/type_resolver_util.cc",
147 "src/google/protobuf/wire_format.cc",
148 "src/google/protobuf/wrappers.pb.cc",
149 ],
150 hdrs = glob(["src/**/*.h"]),
151 copts = COPTS,
152 includes = ["src/"],
153 linkopts = LINK_OPTS,
154 visibility = ["//visibility:public"],
155 deps = [":protobuf_lite"],
156)
157
Austin Schuhf9724442018-10-28 20:30:21 -0700158# This provides just the header files for use in projects that need to build
159# shared libraries for dynamic loading. This target is available until Bazel
160# adds native support for such use cases.
161# TODO(keveman): Remove this target once the support gets added to Bazel.
162cc_library(
163 name = "protobuf_headers",
164 hdrs = glob(["src/**/*.h"]),
165 includes = ["src/"],
166 visibility = ["//visibility:public"],
167)
168
Brian Silverman9c614bc2016-02-15 20:20:02 -0500169objc_library(
170 name = "protobuf_objc",
171 hdrs = ["objectivec/GPBProtocolBuffers.h"],
172 includes = ["objectivec"],
173 non_arc_srcs = ["objectivec/GPBProtocolBuffers.m"],
174 visibility = ["//visibility:public"],
175)
176
Austin Schuhf9724442018-10-28 20:30:21 -0700177# Map of all well known protos.
178# name => (include path, imports)
179WELL_KNOWN_PROTO_MAP = {
180 "any": ("google/protobuf/any.proto", []),
181 "api": (
182 "google/protobuf/api.proto",
183 [
184 "source_context",
185 "type",
186 ],
187 ),
188 "compiler_plugin": (
189 "google/protobuf/compiler/plugin.proto",
190 ["descriptor"],
191 ),
192 "descriptor": ("google/protobuf/descriptor.proto", []),
193 "duration": ("google/protobuf/duration.proto", []),
194 "empty": ("google/protobuf/empty.proto", []),
195 "field_mask": ("google/protobuf/field_mask.proto", []),
196 "source_context": ("google/protobuf/source_context.proto", []),
197 "struct": ("google/protobuf/struct.proto", []),
198 "timestamp": ("google/protobuf/timestamp.proto", []),
199 "type": (
200 "google/protobuf/type.proto",
201 [
202 "any",
203 "source_context",
204 ],
205 ),
206 "wrappers": ("google/protobuf/wrappers.proto", []),
207}
208
209RELATIVE_WELL_KNOWN_PROTOS = [proto[1][0] for proto in WELL_KNOWN_PROTO_MAP.items()]
Brian Silverman9c614bc2016-02-15 20:20:02 -0500210
211WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
212
Brian Silvermaneb16fa42016-02-20 15:29:56 -0500213filegroup(
214 name = "well_known_protos",
215 srcs = WELL_KNOWN_PROTOS,
216 visibility = ["//visibility:public"],
217)
218
Brian Silverman9c614bc2016-02-15 20:20:02 -0500219cc_proto_library(
220 name = "cc_wkt_protos",
221 srcs = WELL_KNOWN_PROTOS,
222 include = "src",
223 default_runtime = ":protobuf",
224 internal_bootstrap_hack = 1,
225 protoc = ":protoc",
226 visibility = ["//visibility:public"],
227)
228
229################################################################################
Austin Schuhf9724442018-10-28 20:30:21 -0700230# Well Known Types Proto Library Rules
231#
232# These proto_library rules can be used with one of the language specific proto
233# library rules i.e. java_proto_library:
234#
235# java_proto_library(
236# name = "any_java_proto",
237# deps = ["@com_google_protobuf//:any_proto],
238# )
239################################################################################
240
241internal_copied_filegroup(
242 name = "_internal_wkt_protos",
243 srcs = WELL_KNOWN_PROTOS,
244 dest = "",
245 strip_prefix = "src",
246 visibility = ["//visibility:private"],
247)
248
249[proto_library(
250 name = proto[0] + "_proto",
251 srcs = [proto[1][0]],
252 visibility = ["//visibility:public"],
253 deps = [dep + "_proto" for dep in proto[1][1]],
254) for proto in WELL_KNOWN_PROTO_MAP.items()]
255
256################################################################################
Brian Silverman9c614bc2016-02-15 20:20:02 -0500257# Protocol Buffers Compiler
258################################################################################
259
260cc_library(
261 name = "protoc_lib",
262 srcs = [
263 # AUTOGEN(protoc_lib_srcs)
264 "src/google/protobuf/compiler/code_generator.cc",
265 "src/google/protobuf/compiler/command_line_interface.cc",
266 "src/google/protobuf/compiler/cpp/cpp_enum.cc",
267 "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
268 "src/google/protobuf/compiler/cpp/cpp_extension.cc",
269 "src/google/protobuf/compiler/cpp/cpp_field.cc",
270 "src/google/protobuf/compiler/cpp/cpp_file.cc",
271 "src/google/protobuf/compiler/cpp/cpp_generator.cc",
272 "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
273 "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
274 "src/google/protobuf/compiler/cpp/cpp_message.cc",
275 "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700276 "src/google/protobuf/compiler/cpp/cpp_padding_optimizer.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500277 "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
278 "src/google/protobuf/compiler/cpp/cpp_service.cc",
279 "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
280 "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
281 "src/google/protobuf/compiler/csharp/csharp_enum.cc",
282 "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
283 "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
284 "src/google/protobuf/compiler/csharp/csharp_generator.cc",
285 "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
286 "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
287 "src/google/protobuf/compiler/csharp/csharp_message.cc",
288 "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
289 "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
290 "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
291 "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
292 "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
293 "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
294 "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
295 "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
296 "src/google/protobuf/compiler/java/java_context.cc",
297 "src/google/protobuf/compiler/java/java_doc_comment.cc",
298 "src/google/protobuf/compiler/java/java_enum.cc",
299 "src/google/protobuf/compiler/java/java_enum_field.cc",
300 "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
301 "src/google/protobuf/compiler/java/java_enum_lite.cc",
302 "src/google/protobuf/compiler/java/java_extension.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700303 "src/google/protobuf/compiler/java/java_extension_lite.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500304 "src/google/protobuf/compiler/java/java_field.cc",
305 "src/google/protobuf/compiler/java/java_file.cc",
306 "src/google/protobuf/compiler/java/java_generator.cc",
307 "src/google/protobuf/compiler/java/java_generator_factory.cc",
308 "src/google/protobuf/compiler/java/java_helpers.cc",
309 "src/google/protobuf/compiler/java/java_lazy_message_field.cc",
310 "src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc",
311 "src/google/protobuf/compiler/java/java_map_field.cc",
312 "src/google/protobuf/compiler/java/java_map_field_lite.cc",
313 "src/google/protobuf/compiler/java/java_message.cc",
314 "src/google/protobuf/compiler/java/java_message_builder.cc",
315 "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
316 "src/google/protobuf/compiler/java/java_message_field.cc",
317 "src/google/protobuf/compiler/java/java_message_field_lite.cc",
318 "src/google/protobuf/compiler/java/java_message_lite.cc",
319 "src/google/protobuf/compiler/java/java_name_resolver.cc",
320 "src/google/protobuf/compiler/java/java_primitive_field.cc",
321 "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
322 "src/google/protobuf/compiler/java/java_service.cc",
323 "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
324 "src/google/protobuf/compiler/java/java_string_field.cc",
325 "src/google/protobuf/compiler/java/java_string_field_lite.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500326 "src/google/protobuf/compiler/js/js_generator.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700327 "src/google/protobuf/compiler/js/well_known_types_embed.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500328 "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
329 "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
330 "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
331 "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
332 "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
333 "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
334 "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
335 "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
336 "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
337 "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
338 "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
339 "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700340 "src/google/protobuf/compiler/php/php_generator.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500341 "src/google/protobuf/compiler/plugin.cc",
342 "src/google/protobuf/compiler/plugin.pb.cc",
343 "src/google/protobuf/compiler/python/python_generator.cc",
344 "src/google/protobuf/compiler/ruby/ruby_generator.cc",
345 "src/google/protobuf/compiler/subprocess.cc",
346 "src/google/protobuf/compiler/zip_writer.cc",
347 ],
348 copts = COPTS,
349 includes = ["src/"],
350 linkopts = LINK_OPTS,
351 visibility = ["//visibility:public"],
352 deps = [":protobuf"],
353)
354
355cc_binary(
356 name = "protoc",
357 srcs = ["src/google/protobuf/compiler/main.cc"],
358 linkopts = LINK_OPTS,
359 visibility = ["//visibility:public"],
360 deps = [":protoc_lib"],
361)
362
363################################################################################
364# Tests
365################################################################################
366
367RELATIVE_LITE_TEST_PROTOS = [
368 # AUTOGEN(lite_test_protos)
369 "google/protobuf/map_lite_unittest.proto",
370 "google/protobuf/unittest_import_lite.proto",
371 "google/protobuf/unittest_import_public_lite.proto",
372 "google/protobuf/unittest_lite.proto",
373 "google/protobuf/unittest_no_arena_lite.proto",
374]
375
376LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
377
378RELATIVE_TEST_PROTOS = [
379 # AUTOGEN(test_protos)
380 "google/protobuf/any_test.proto",
381 "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
382 "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
383 "google/protobuf/map_proto2_unittest.proto",
384 "google/protobuf/map_unittest.proto",
385 "google/protobuf/unittest.proto",
386 "google/protobuf/unittest_arena.proto",
387 "google/protobuf/unittest_custom_options.proto",
388 "google/protobuf/unittest_drop_unknown_fields.proto",
389 "google/protobuf/unittest_embed_optimize_for.proto",
390 "google/protobuf/unittest_empty.proto",
391 "google/protobuf/unittest_enormous_descriptor.proto",
392 "google/protobuf/unittest_import.proto",
393 "google/protobuf/unittest_import_public.proto",
Austin Schuhf9724442018-10-28 20:30:21 -0700394 "google/protobuf/unittest_lazy_dependencies.proto",
395 "google/protobuf/unittest_lazy_dependencies_custom_option.proto",
396 "google/protobuf/unittest_lazy_dependencies_enum.proto",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500397 "google/protobuf/unittest_lite_imports_nonlite.proto",
398 "google/protobuf/unittest_mset.proto",
399 "google/protobuf/unittest_mset_wire_format.proto",
400 "google/protobuf/unittest_no_arena.proto",
401 "google/protobuf/unittest_no_arena_import.proto",
402 "google/protobuf/unittest_no_field_presence.proto",
403 "google/protobuf/unittest_no_generic_services.proto",
404 "google/protobuf/unittest_optimize_for.proto",
405 "google/protobuf/unittest_preserve_unknown_enum.proto",
406 "google/protobuf/unittest_preserve_unknown_enum2.proto",
407 "google/protobuf/unittest_proto3_arena.proto",
Austin Schuhf9724442018-10-28 20:30:21 -0700408 "google/protobuf/unittest_proto3_arena_lite.proto",
409 "google/protobuf/unittest_proto3_lite.proto",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500410 "google/protobuf/unittest_well_known_types.proto",
411 "google/protobuf/util/internal/testdata/anys.proto",
412 "google/protobuf/util/internal/testdata/books.proto",
413 "google/protobuf/util/internal/testdata/default_value.proto",
414 "google/protobuf/util/internal/testdata/default_value_test.proto",
415 "google/protobuf/util/internal/testdata/field_mask.proto",
416 "google/protobuf/util/internal/testdata/maps.proto",
417 "google/protobuf/util/internal/testdata/oneofs.proto",
Austin Schuhf9724442018-10-28 20:30:21 -0700418 "google/protobuf/util/internal/testdata/proto3.proto",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500419 "google/protobuf/util/internal/testdata/struct.proto",
420 "google/protobuf/util/internal/testdata/timestamp_duration.proto",
Austin Schuhf9724442018-10-28 20:30:21 -0700421 "google/protobuf/util/internal/testdata/wrappers.proto",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500422 "google/protobuf/util/json_format_proto3.proto",
423 "google/protobuf/util/message_differencer_unittest.proto",
424]
425
426TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
427
428cc_proto_library(
429 name = "cc_test_protos",
430 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
431 include = "src",
432 default_runtime = ":protobuf",
433 protoc = ":protoc",
434 deps = [":cc_wkt_protos"],
435)
436
437COMMON_TEST_SRCS = [
438 # AUTOGEN(common_test_srcs)
439 "src/google/protobuf/arena_test_util.cc",
440 "src/google/protobuf/map_test_util.cc",
441 "src/google/protobuf/test_util.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700442 "src/google/protobuf/test_util.inc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500443 "src/google/protobuf/testing/file.cc",
444 "src/google/protobuf/testing/googletest.cc",
445]
446
447cc_binary(
448 name = "test_plugin",
449 srcs = [
450 # AUTOGEN(test_plugin_srcs)
451 "src/google/protobuf/compiler/mock_code_generator.cc",
452 "src/google/protobuf/compiler/test_plugin.cc",
453 "src/google/protobuf/testing/file.cc",
454 ],
Brian Silverman7b8899e2018-06-30 19:19:24 -0700455 copts = COPTS,
Brian Silverman9c614bc2016-02-15 20:20:02 -0500456 deps = [
457 ":protobuf",
458 ":protoc_lib",
459 "//external:gtest",
460 ],
461)
462
463cc_test(
Austin Schuhf9724442018-10-28 20:30:21 -0700464 name = "win32_test",
465 srcs = ["src/google/protobuf/stubs/io_win32_unittest.cc"],
466 tags = [
467 "manual",
468 "windows",
469 ],
470 deps = [
471 ":protobuf_lite",
472 "//external:gtest_main",
473 ],
474)
475
476cc_test(
Brian Silverman9c614bc2016-02-15 20:20:02 -0500477 name = "protobuf_test",
478 srcs = COMMON_TEST_SRCS + [
479 # AUTOGEN(test_srcs)
480 "src/google/protobuf/any_test.cc",
481 "src/google/protobuf/arena_unittest.cc",
482 "src/google/protobuf/arenastring_unittest.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700483 "src/google/protobuf/compiler/annotation_test_util.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500484 "src/google/protobuf/compiler/command_line_interface_unittest.cc",
485 "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700486 "src/google/protobuf/compiler/cpp/cpp_move_unittest.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500487 "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
488 "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700489 "src/google/protobuf/compiler/cpp/cpp_unittest.inc",
490 "src/google/protobuf/compiler/cpp/metadata_test.cc",
491 "src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500492 "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
493 "src/google/protobuf/compiler/importer_unittest.cc",
494 "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
495 "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
496 "src/google/protobuf/compiler/mock_code_generator.cc",
497 "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
498 "src/google/protobuf/compiler/parser_unittest.cc",
499 "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
500 "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
501 "src/google/protobuf/descriptor_database_unittest.cc",
502 "src/google/protobuf/descriptor_unittest.cc",
503 "src/google/protobuf/drop_unknown_fields_test.cc",
504 "src/google/protobuf/dynamic_message_unittest.cc",
505 "src/google/protobuf/extension_set_unittest.cc",
506 "src/google/protobuf/generated_message_reflection_unittest.cc",
507 "src/google/protobuf/io/coded_stream_unittest.cc",
508 "src/google/protobuf/io/printer_unittest.cc",
509 "src/google/protobuf/io/tokenizer_unittest.cc",
510 "src/google/protobuf/io/zero_copy_stream_unittest.cc",
511 "src/google/protobuf/map_field_test.cc",
512 "src/google/protobuf/map_test.cc",
513 "src/google/protobuf/message_unittest.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700514 "src/google/protobuf/message_unittest.inc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500515 "src/google/protobuf/no_field_presence_test.cc",
516 "src/google/protobuf/preserve_unknown_enum_test.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700517 "src/google/protobuf/proto3_arena_lite_unittest.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500518 "src/google/protobuf/proto3_arena_unittest.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700519 "src/google/protobuf/proto3_lite_unittest.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500520 "src/google/protobuf/reflection_ops_unittest.cc",
521 "src/google/protobuf/repeated_field_reflection_unittest.cc",
522 "src/google/protobuf/repeated_field_unittest.cc",
523 "src/google/protobuf/stubs/bytestream_unittest.cc",
524 "src/google/protobuf/stubs/common_unittest.cc",
525 "src/google/protobuf/stubs/int128_unittest.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700526 "src/google/protobuf/stubs/io_win32_unittest.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500527 "src/google/protobuf/stubs/status_test.cc",
528 "src/google/protobuf/stubs/statusor_test.cc",
529 "src/google/protobuf/stubs/stringpiece_unittest.cc",
530 "src/google/protobuf/stubs/stringprintf_unittest.cc",
531 "src/google/protobuf/stubs/structurally_valid_unittest.cc",
532 "src/google/protobuf/stubs/strutil_unittest.cc",
533 "src/google/protobuf/stubs/template_util_unittest.cc",
534 "src/google/protobuf/stubs/time_test.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500535 "src/google/protobuf/text_format_unittest.cc",
536 "src/google/protobuf/unknown_field_set_unittest.cc",
Austin Schuhf9724442018-10-28 20:30:21 -0700537 "src/google/protobuf/util/delimited_message_util_test.cc",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500538 "src/google/protobuf/util/field_comparator_test.cc",
539 "src/google/protobuf/util/field_mask_util_test.cc",
540 "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
541 "src/google/protobuf/util/internal/json_objectwriter_test.cc",
542 "src/google/protobuf/util/internal/json_stream_parser_test.cc",
543 "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
544 "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
545 "src/google/protobuf/util/internal/type_info_test_helper.cc",
546 "src/google/protobuf/util/json_util_test.cc",
547 "src/google/protobuf/util/message_differencer_unittest.cc",
548 "src/google/protobuf/util/time_util_test.cc",
549 "src/google/protobuf/util/type_resolver_util_test.cc",
550 "src/google/protobuf/well_known_types_unittest.cc",
551 "src/google/protobuf/wire_format_unittest.cc",
552 ],
553 copts = COPTS,
554 data = [
555 ":test_plugin",
556 ] + glob([
557 "src/google/protobuf/**/*",
Austin Schuhf9724442018-10-28 20:30:21 -0700558 # Files for csharp_bootstrap_unittest.cc.
559 "conformance/**/*",
560 "csharp/src/**/*",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500561 ]),
562 includes = [
563 "src/",
564 ],
565 linkopts = LINK_OPTS,
566 deps = [
567 ":cc_test_protos",
568 ":protobuf",
569 ":protoc_lib",
570 "//external:gtest_main",
571 ],
572)
573
574################################################################################
575# Java support
576################################################################################
Austin Schuhf9724442018-10-28 20:30:21 -0700577internal_gen_well_known_protos_java(
Brian Silverman9c614bc2016-02-15 20:20:02 -0500578 srcs = WELL_KNOWN_PROTOS,
Brian Silverman9c614bc2016-02-15 20:20:02 -0500579)
580
581java_library(
582 name = "protobuf_java",
583 srcs = glob([
584 "java/core/src/main/java/com/google/protobuf/*.java",
585 ]) + [
586 ":gen_well_known_protos_java",
587 ],
Austin Schuhf9724442018-10-28 20:30:21 -0700588 javacopts = select({
589 "//:jdk9": ["--add-modules=jdk.unsupported"],
590 "//conditions:default": [
591 "-source 7",
592 "-target 7",
593 ],
594 }),
Brian Silverman9c614bc2016-02-15 20:20:02 -0500595 visibility = ["//visibility:public"],
596)
Austin Schuhf9724442018-10-28 20:30:21 -0700597
598java_library(
599 name = "protobuf_java_util",
600 srcs = glob([
601 "java/util/src/main/java/com/google/protobuf/util/*.java",
602 ]),
603 javacopts = [
604 "-source 7",
605 "-target 7",
606 ],
607 visibility = ["//visibility:public"],
608 deps = [
609 "protobuf_java",
610 "//external:gson",
611 "//external:guava",
612 ],
613)
Brian Silverman9c614bc2016-02-15 20:20:02 -0500614
615################################################################################
616# Python support
617################################################################################
618
Austin Schuhf9724442018-10-28 20:30:21 -0700619py_library(
Brian Silverman9c614bc2016-02-15 20:20:02 -0500620 name = "python_srcs",
621 srcs = glob(
622 [
623 "python/google/protobuf/*.py",
624 "python/google/protobuf/**/*.py",
625 ],
626 exclude = [
Austin Schuhf9724442018-10-28 20:30:21 -0700627 "python/google/protobuf/__init__.py",
628 "python/google/protobuf/**/__init__.py",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500629 "python/google/protobuf/internal/*_test.py",
630 "python/google/protobuf/internal/test_util.py",
631 ],
632 ),
Austin Schuhf9724442018-10-28 20:30:21 -0700633 imports = ["python"],
634 srcs_version = "PY2AND3",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500635)
636
Brian Silverman7b8899e2018-06-30 19:19:24 -0700637"""
Brian Silverman9c614bc2016-02-15 20:20:02 -0500638cc_binary(
Austin Schuhf9724442018-10-28 20:30:21 -0700639 name = "python/google/protobuf/internal/_api_implementation.so",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500640 srcs = ["python/google/protobuf/internal/api_implementation.cc"],
641 copts = COPTS + [
642 "-DPYTHON_PROTO2_CPP_IMPL_V2",
643 ],
644 linkshared = 1,
645 linkstatic = 1,
646 deps = select({
647 "//conditions:default": [],
Brian Silverman3fca9d72016-02-20 02:32:51 -0500648 ":use_fast_cpp_protos": ["//third_party/protobuf/util/python:python_headers"],
Brian Silverman9c614bc2016-02-15 20:20:02 -0500649 }),
650)
651
652cc_binary(
Austin Schuhf9724442018-10-28 20:30:21 -0700653 name = "python/google/protobuf/pyext/_message.so",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500654 srcs = glob([
655 "python/google/protobuf/pyext/*.cc",
656 "python/google/protobuf/pyext/*.h",
657 ]),
658 copts = COPTS + [
659 "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
Austin Schuhf9724442018-10-28 20:30:21 -0700660 ] + select({
661 "//conditions:default": [],
662 ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
663 }),
Brian Silverman9c614bc2016-02-15 20:20:02 -0500664 includes = [
665 "python/",
666 "src/",
667 ],
668 linkshared = 1,
669 linkstatic = 1,
670 deps = [
671 ":protobuf",
672 ] + select({
673 "//conditions:default": [],
Brian Silverman3fca9d72016-02-20 02:32:51 -0500674 ":use_fast_cpp_protos": ["//third_party/protobuf/util/python:python_headers"],
Brian Silverman9c614bc2016-02-15 20:20:02 -0500675 }),
676)
Brian Silverman7b8899e2018-06-30 19:19:24 -0700677"""
Brian Silverman9c614bc2016-02-15 20:20:02 -0500678
679config_setting(
680 name = "use_fast_cpp_protos",
681 values = {
682 "define": "use_fast_cpp_protos=true",
683 },
684)
685
Austin Schuhf9724442018-10-28 20:30:21 -0700686config_setting(
687 name = "allow_oversize_protos",
688 values = {
689 "define": "allow_oversize_protos=true",
690 },
691)
692
693# Copy the builtin proto files from src/google/protobuf to
694# python/google/protobuf. This way, the generated Python sources will be in the
695# same directory as the Python runtime sources. This is necessary for the
696# modules to be imported correctly since they are all part of the same Python
697# package.
698internal_copied_filegroup(
699 name = "protos_python",
700 srcs = WELL_KNOWN_PROTOS,
701 dest = "python",
702 strip_prefix = "src",
703)
704
705# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
706# which case we can simply add :protos_python in srcs.
707COPIED_WELL_KNOWN_PROTOS = ["python/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
708
Brian Silverman9c614bc2016-02-15 20:20:02 -0500709py_proto_library(
710 name = "protobuf_python",
Austin Schuhf9724442018-10-28 20:30:21 -0700711 srcs = COPIED_WELL_KNOWN_PROTOS,
712 include = "python",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500713 data = select({
714 "//conditions:default": [],
715 ":use_fast_cpp_protos": [
Austin Schuhf9724442018-10-28 20:30:21 -0700716 ":python/google/protobuf/internal/_api_implementation.so",
717 ":python/google/protobuf/pyext/_message.so",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500718 ],
719 }),
720 default_runtime = "",
721 protoc = ":protoc",
Austin Schuhf9724442018-10-28 20:30:21 -0700722 py_extra_srcs = glob(["python/**/__init__.py"]),
723 py_libs = [
724 ":python_srcs",
725 "//external:six",
726 ],
Brian Silverman9c614bc2016-02-15 20:20:02 -0500727 srcs_version = "PY2AND3",
728 visibility = ["//visibility:public"],
729)
730
Austin Schuhf9724442018-10-28 20:30:21 -0700731# Copy the test proto files from src/google/protobuf to
732# python/google/protobuf. This way, the generated Python sources will be in the
733# same directory as the Python runtime sources. This is necessary for the
734# modules to be imported correctly by the tests since they are all part of the
735# same Python package.
Brian Silverman9c614bc2016-02-15 20:20:02 -0500736internal_copied_filegroup(
Austin Schuhf9724442018-10-28 20:30:21 -0700737 name = "protos_python_test",
738 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
739 dest = "python",
740 strip_prefix = "src",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500741)
742
Austin Schuhf9724442018-10-28 20:30:21 -0700743# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
744# which case we can simply add :protos_python_test in srcs.
745COPIED_LITE_TEST_PROTOS = ["python/" + s for s in RELATIVE_LITE_TEST_PROTOS]
746
747COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]
748
Brian Silverman9c614bc2016-02-15 20:20:02 -0500749py_proto_library(
750 name = "python_common_test_protos",
Austin Schuhf9724442018-10-28 20:30:21 -0700751 srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
752 include = "python",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500753 default_runtime = "",
754 protoc = ":protoc",
Austin Schuhf9724442018-10-28 20:30:21 -0700755 srcs_version = "PY2AND3",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500756 deps = [":protobuf_python"],
757)
758
759py_proto_library(
760 name = "python_specific_test_protos",
761 srcs = glob([
762 "python/google/protobuf/internal/*.proto",
763 "python/google/protobuf/internal/import_test_package/*.proto",
764 ]),
765 include = "python",
766 default_runtime = ":protobuf_python",
767 protoc = ":protoc",
Austin Schuhf9724442018-10-28 20:30:21 -0700768 srcs_version = "PY2AND3",
Brian Silverman9c614bc2016-02-15 20:20:02 -0500769 deps = [":python_common_test_protos"],
770)
771
772py_library(
773 name = "python_tests",
Austin Schuhf9724442018-10-28 20:30:21 -0700774 srcs = glob(
775 [
776 "python/google/protobuf/internal/*_test.py",
777 "python/google/protobuf/internal/test_util.py",
778 "python/google/protobuf/internal/import_test_package/__init__.py",
779 ],
780 ),
781 imports = ["python"],
Brian Silverman9c614bc2016-02-15 20:20:02 -0500782 srcs_version = "PY2AND3",
783 deps = [
784 ":protobuf_python",
785 ":python_common_test_protos",
786 ":python_specific_test_protos",
787 ],
788)
789
790internal_protobuf_py_tests(
791 name = "python_tests_batch",
792 data = glob([
793 "src/google/protobuf/**/*",
794 ]),
795 modules = [
796 "descriptor_database_test",
797 "descriptor_pool_test",
798 "descriptor_test",
799 "generator_test",
800 "json_format_test",
801 "message_factory_test",
802 "message_test",
803 "proto_builder_test",
804 "reflection_test",
805 "service_reflection_test",
806 "symbol_database_test",
807 "text_encoding_test",
808 "text_format_test",
809 "unknown_fields_test",
810 "wire_format_test",
811 ],
812 deps = [":python_tests"],
813)
Austin Schuhf9724442018-10-28 20:30:21 -0700814
815proto_lang_toolchain(
816 name = "cc_toolchain",
817 blacklisted_protos = [":_internal_wkt_protos_genrule"],
818 command_line = "--cpp_out=$(OUT)",
819 runtime = ":protobuf",
820 visibility = ["//visibility:public"],
821)
822
823proto_lang_toolchain(
824 name = "java_toolchain",
825 command_line = "--java_out=$(OUT)",
826 runtime = ":protobuf_java",
827 visibility = ["//visibility:public"],
828)
829
830OBJC_HDRS = [
831 "objectivec/GPBArray.h",
832 "objectivec/GPBBootstrap.h",
833 "objectivec/GPBCodedInputStream.h",
834 "objectivec/GPBCodedOutputStream.h",
835 "objectivec/GPBDescriptor.h",
836 "objectivec/GPBDictionary.h",
837 "objectivec/GPBExtensionInternals.h",
838 "objectivec/GPBExtensionRegistry.h",
839 "objectivec/GPBMessage.h",
840 "objectivec/GPBProtocolBuffers.h",
841 "objectivec/GPBProtocolBuffers_RuntimeSupport.h",
842 "objectivec/GPBRootObject.h",
843 "objectivec/GPBRuntimeTypes.h",
844 "objectivec/GPBUnknownField.h",
845 "objectivec/GPBUnknownFieldSet.h",
846 "objectivec/GPBUtilities.h",
847 "objectivec/GPBWellKnownTypes.h",
848 "objectivec/GPBWireFormat.h",
849 "objectivec/google/protobuf/Any.pbobjc.h",
850 "objectivec/google/protobuf/Api.pbobjc.h",
851 "objectivec/google/protobuf/Duration.pbobjc.h",
852 "objectivec/google/protobuf/Empty.pbobjc.h",
853 "objectivec/google/protobuf/FieldMask.pbobjc.h",
854 "objectivec/google/protobuf/SourceContext.pbobjc.h",
855 "objectivec/google/protobuf/Struct.pbobjc.h",
856 "objectivec/google/protobuf/Timestamp.pbobjc.h",
857 "objectivec/google/protobuf/Type.pbobjc.h",
858 "objectivec/google/protobuf/Wrappers.pbobjc.h",
859]
860
861OBJC_PRIVATE_HDRS = [
862 "objectivec/GPBArray_PackagePrivate.h",
863 "objectivec/GPBCodedInputStream_PackagePrivate.h",
864 "objectivec/GPBCodedOutputStream_PackagePrivate.h",
865 "objectivec/GPBDescriptor_PackagePrivate.h",
866 "objectivec/GPBDictionary_PackagePrivate.h",
867 "objectivec/GPBMessage_PackagePrivate.h",
868 "objectivec/GPBRootObject_PackagePrivate.h",
869 "objectivec/GPBUnknownFieldSet_PackagePrivate.h",
870 "objectivec/GPBUnknownField_PackagePrivate.h",
871 "objectivec/GPBUtilities_PackagePrivate.h",
872]
873
874OBJC_SRCS = [
875 "objectivec/GPBArray.m",
876 "objectivec/GPBCodedInputStream.m",
877 "objectivec/GPBCodedOutputStream.m",
878 "objectivec/GPBDescriptor.m",
879 "objectivec/GPBDictionary.m",
880 "objectivec/GPBExtensionInternals.m",
881 "objectivec/GPBExtensionRegistry.m",
882 "objectivec/GPBMessage.m",
883 "objectivec/GPBRootObject.m",
884 "objectivec/GPBUnknownField.m",
885 "objectivec/GPBUnknownFieldSet.m",
886 "objectivec/GPBUtilities.m",
887 "objectivec/GPBWellKnownTypes.m",
888 "objectivec/GPBWireFormat.m",
889 "objectivec/google/protobuf/Any.pbobjc.m",
890 "objectivec/google/protobuf/Api.pbobjc.m",
891 "objectivec/google/protobuf/Duration.pbobjc.m",
892 "objectivec/google/protobuf/Empty.pbobjc.m",
893 "objectivec/google/protobuf/FieldMask.pbobjc.m",
894 "objectivec/google/protobuf/SourceContext.pbobjc.m",
895 "objectivec/google/protobuf/Struct.pbobjc.m",
896 "objectivec/google/protobuf/Timestamp.pbobjc.m",
897 "objectivec/google/protobuf/Type.pbobjc.m",
898 "objectivec/google/protobuf/Wrappers.pbobjc.m",
899]
900
901objc_library(
902 name = "objectivec",
903 hdrs = OBJC_HDRS + OBJC_PRIVATE_HDRS,
904 includes = [
905 "objectivec",
906 ],
907 non_arc_srcs = OBJC_SRCS,
908 visibility = ["//visibility:public"],
909)