BUILD 47 KB
Newer Older
1
# Bazel (https://bazel.build/) BUILD file for Protobuf.
2

3 4 5
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library")
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
6
load("@rules_python//python:defs.bzl", "py_library")
7

8 9
licenses(["notice"])

10 11
exports_files(["LICENSE"])

12 13 14 15 16 17 18 19 20 21 22
################################################################################
# Java 9 configuration
################################################################################

config_setting(
    name = "jdk9",
    values = {
        "java_toolchain": "@bazel_tools//tools/jdk:toolchain_jdk9",
    },
)

23 24 25 26
################################################################################
# ZLIB configuration
################################################################################

27
ZLIB_DEPS = ["@zlib//:zlib"]
28

29 30 31 32
################################################################################
# Protobuf Runtime Library
################################################################################

33
MSVC_COPTS = [
34
    "/DHAVE_PTHREAD",
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
    "/wd4018",  # -Wno-sign-compare
    "/wd4065",  # switch statement contains 'default' but no 'case' labels
    "/wd4146",  # unary minus operator applied to unsigned type, result still unsigned
    "/wd4244",  # 'conversion' conversion from 'type1' to 'type2', possible loss of data
    "/wd4251",  # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
    "/wd4267",  # 'var' : conversion from 'size_t' to 'type', possible loss of data
    "/wd4305",  # 'identifier' : truncation from 'type1' to 'type2'
    "/wd4307",  # 'operator' : integral constant overflow
    "/wd4309",  # 'conversion' : truncation of constant value
    "/wd4334",  # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
    "/wd4355",  # 'this' : used in base member initializer list
    "/wd4506",  # no definition for inline function 'function'
    "/wd4514",  # -Wno-unused-function
    "/wd4800",  # 'type' : forcing value to bool 'true' or 'false' (performance warning)
    "/wd4996",  # The compiler encountered a deprecated declaration.
50 51
]

52
COPTS = select({
53
    ":msvc": MSVC_COPTS,
54 55
    "//conditions:default": [
        "-DHAVE_PTHREAD",
56
        "-DHAVE_ZLIB",
57 58 59
        "-Woverloaded-virtual",
        "-Wno-sign-compare",
        "-Wno-unused-function",
60
        # Prevents ISO C++ const string assignment warnings for pyext sources.
61
        "-Wno-write-strings",
62
        "-Wno-deprecated-declarations",
63 64 65
    ],
})

66 67
load(":compiler_config_setting.bzl", "create_compiler_config_setting")

68
create_compiler_config_setting(
69
    name = "msvc",
70
    value = "msvc-cl",
71 72
)

73 74 75 76 77 78 79
config_setting(
    name = "android",
    values = {
        "crosstool_top": "//external:android/crosstool",
    },
)

80 81 82 83 84 85 86 87 88 89 90 91 92 93
config_setting(
    name = "android-libcpp",
    values = {
        "crosstool_top": "@androidndk//:toolchain-libcpp",
    },
)

config_setting(
    name = "android-gnu-libstdcpp",
    values = {
        "crosstool_top": "@androidndk//:toolchain-gnu-libstdcpp",
    },
)

94
# Android and MSVC builds do not need to link in a separate pthread library.
95
LINK_OPTS = select({
Andrew Harp's avatar
Andrew Harp committed
96
    ":android": [],
97 98
    ":android-libcpp": [],
    ":android-gnu-libstdcpp": [],
99
    ":msvc": [
100 101
        # Suppress linker warnings about files with no symbols defined.
        "-ignore:4221",
102
    ],
103 104 105 106
    "//conditions:default": [
        "-lpthread",
        "-lm",
    ],
107
})
108

109
load(
110
    ":protobuf.bzl",
111
    "cc_proto_library",
112
    "internal_copied_filegroup",
113
    "internal_gen_well_known_protos_java",
114
    "internal_protobuf_py_tests",
115
    "py_proto_library",
116
)
117

118 119 120 121
cc_library(
    name = "protobuf_lite",
    srcs = [
        # AUTOGEN(protobuf_lite_srcs)
122
        "src/google/protobuf/any_lite.cc",
123 124
        "src/google/protobuf/arena.cc",
        "src/google/protobuf/extension_set.cc",
125
        "src/google/protobuf/generated_enum_util.cc",
Jisi Liu's avatar
Jisi Liu committed
126
        "src/google/protobuf/generated_message_table_driven_lite.cc",
127
        "src/google/protobuf/generated_message_util.cc",
128
        "src/google/protobuf/implicit_weak_message.cc",
129
        "src/google/protobuf/io/coded_stream.cc",
130
        "src/google/protobuf/io/io_win32.cc",
131
        "src/google/protobuf/io/strtod.cc",
132
        "src/google/protobuf/io/zero_copy_stream.cc",
133
        "src/google/protobuf/io/zero_copy_stream_impl.cc",
134 135
        "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
        "src/google/protobuf/message_lite.cc",
136
        "src/google/protobuf/parse_context.cc",
137
        "src/google/protobuf/repeated_field.cc",
138
        "src/google/protobuf/stubs/bytestream.cc",
139
        "src/google/protobuf/stubs/common.cc",
140
        "src/google/protobuf/stubs/int128.cc",
141 142 143
        "src/google/protobuf/stubs/status.cc",
        "src/google/protobuf/stubs/statusor.cc",
        "src/google/protobuf/stubs/stringpiece.cc",
144
        "src/google/protobuf/stubs/stringprintf.cc",
145
        "src/google/protobuf/stubs/structurally_valid.cc",
146 147
        "src/google/protobuf/stubs/strutil.cc",
        "src/google/protobuf/stubs/time.cc",
148 149
        "src/google/protobuf/wire_format_lite.cc",
    ],
150 151 152 153
    hdrs = glob([
        "src/google/protobuf/**/*.h",
        "src/google/protobuf/**/*.inc",
    ]),
154
    copts = COPTS,
155 156 157 158 159
    includes = ["src/"],
    linkopts = LINK_OPTS,
    visibility = ["//visibility:public"],
)

160 161 162 163 164
PROTOBUF_DEPS = select({
    ":msvc": [],
    "//conditions:default": ZLIB_DEPS,
})

165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
cc_library(
    name = "protobuf",
    srcs = [
        # AUTOGEN(protobuf_srcs)
        "src/google/protobuf/any.cc",
        "src/google/protobuf/any.pb.cc",
        "src/google/protobuf/api.pb.cc",
        "src/google/protobuf/compiler/importer.cc",
        "src/google/protobuf/compiler/parser.cc",
        "src/google/protobuf/descriptor.cc",
        "src/google/protobuf/descriptor.pb.cc",
        "src/google/protobuf/descriptor_database.cc",
        "src/google/protobuf/duration.pb.cc",
        "src/google/protobuf/dynamic_message.cc",
        "src/google/protobuf/empty.pb.cc",
        "src/google/protobuf/extension_set_heavy.cc",
        "src/google/protobuf/field_mask.pb.cc",
        "src/google/protobuf/generated_message_reflection.cc",
Jisi Liu's avatar
Jisi Liu committed
183
        "src/google/protobuf/generated_message_table_driven.cc",
184 185 186 187 188 189 190 191 192 193 194 195 196 197
        "src/google/protobuf/io/gzip_stream.cc",
        "src/google/protobuf/io/printer.cc",
        "src/google/protobuf/io/tokenizer.cc",
        "src/google/protobuf/map_field.cc",
        "src/google/protobuf/message.cc",
        "src/google/protobuf/reflection_ops.cc",
        "src/google/protobuf/service.cc",
        "src/google/protobuf/source_context.pb.cc",
        "src/google/protobuf/struct.pb.cc",
        "src/google/protobuf/stubs/substitute.cc",
        "src/google/protobuf/text_format.cc",
        "src/google/protobuf/timestamp.pb.cc",
        "src/google/protobuf/type.pb.cc",
        "src/google/protobuf/unknown_field_set.cc",
Bairen Yi's avatar
Bairen Yi committed
198
        "src/google/protobuf/util/delimited_message_util.cc",
199
        "src/google/protobuf/util/field_comparator.cc",
200
        "src/google/protobuf/util/field_mask_util.cc",
201 202 203 204 205 206 207 208
        "src/google/protobuf/util/internal/datapiece.cc",
        "src/google/protobuf/util/internal/default_value_objectwriter.cc",
        "src/google/protobuf/util/internal/error_listener.cc",
        "src/google/protobuf/util/internal/field_mask_utility.cc",
        "src/google/protobuf/util/internal/json_escaping.cc",
        "src/google/protobuf/util/internal/json_objectwriter.cc",
        "src/google/protobuf/util/internal/json_stream_parser.cc",
        "src/google/protobuf/util/internal/object_writer.cc",
Feng Xiao's avatar
Feng Xiao committed
209
        "src/google/protobuf/util/internal/proto_writer.cc",
210 211 212 213 214 215 216
        "src/google/protobuf/util/internal/protostream_objectsource.cc",
        "src/google/protobuf/util/internal/protostream_objectwriter.cc",
        "src/google/protobuf/util/internal/type_info.cc",
        "src/google/protobuf/util/internal/type_info_test_helper.cc",
        "src/google/protobuf/util/internal/utility.cc",
        "src/google/protobuf/util/json_util.cc",
        "src/google/protobuf/util/message_differencer.cc",
217
        "src/google/protobuf/util/time_util.cc",
218
        "src/google/protobuf/util/type_resolver_util.cc",
219 220 221
        "src/google/protobuf/wire_format.cc",
        "src/google/protobuf/wrappers.pb.cc",
    ],
222 223 224 225
    hdrs = glob([
        "src/**/*.h",
        "src/**/*.inc",
    ]),
226
    copts = COPTS,
227 228 229
    includes = ["src/"],
    linkopts = LINK_OPTS,
    visibility = ["//visibility:public"],
230
    deps = [":protobuf_lite"] + PROTOBUF_DEPS,
231 232
)

233 234 235 236
# This provides just the header files for use in projects that need to build
# shared libraries for dynamic loading. This target is available until Bazel
# adds native support for such use cases.
# TODO(keveman): Remove this target once the support gets added to Bazel.
237 238
cc_library(
    name = "protobuf_headers",
239 240 241 242
    hdrs = glob([
        "src/**/*.h",
        "src/**/*.inc",
    ]),
243 244 245 246
    includes = ["src/"],
    visibility = ["//visibility:public"],
)

247 248 249
# Map of all well known protos.
# name => (include path, imports)
WELL_KNOWN_PROTO_MAP = {
250
    "any": ("src/google/protobuf/any.proto", []),
251
    "api": (
252
        "src/google/protobuf/api.proto",
253 254 255 256 257 258
        [
            "source_context",
            "type",
        ],
    ),
    "compiler_plugin": (
259
        "src/google/protobuf/compiler/plugin.proto",
260 261
        ["descriptor"],
    ),
262 263 264 265 266 267 268
    "descriptor": ("src/google/protobuf/descriptor.proto", []),
    "duration": ("src/google/protobuf/duration.proto", []),
    "empty": ("src/google/protobuf/empty.proto", []),
    "field_mask": ("src/google/protobuf/field_mask.proto", []),
    "source_context": ("src/google/protobuf/source_context.proto", []),
    "struct": ("src/google/protobuf/struct.proto", []),
    "timestamp": ("src/google/protobuf/timestamp.proto", []),
269
    "type": (
270
        "src/google/protobuf/type.proto",
271 272 273 274 275
        [
            "any",
            "source_context",
        ],
    ),
276
    "wrappers": ("src/google/protobuf/wrappers.proto", []),
277 278
}

279
WELL_KNOWN_PROTOS = [value[0] for value in WELL_KNOWN_PROTO_MAP.values()]
Jisi Liu's avatar
Jisi Liu committed
280

281 282 283 284 285 286
filegroup(
    name = "well_known_protos",
    srcs = WELL_KNOWN_PROTOS,
    visibility = ["//visibility:public"],
)

287 288
cc_proto_library(
    name = "cc_wkt_protos",
Jisi Liu's avatar
Jisi Liu committed
289
    srcs = WELL_KNOWN_PROTOS,
290
    include = "src",
291
    default_runtime = ":protobuf",
Jisi Liu's avatar
Jisi Liu committed
292
    internal_bootstrap_hack = 1,
293
    protoc = ":protoc",
294
    visibility = ["//visibility:public"],
295 296
)

297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
################################################################################
# Well Known Types Proto Library Rules
#
# These proto_library rules can be used with one of the language specific proto
# library rules i.e. java_proto_library:
#
# java_proto_library(
#   name = "any_java_proto",
#   deps = ["@com_google_protobuf//:any_proto],
# )
################################################################################

[proto_library(
    name = proto[0] + "_proto",
    srcs = [proto[1][0]],
312
    strip_import_prefix = "src",
313
    visibility = ["//visibility:public"],
314 315
    deps = [dep + "_proto" for dep in proto[1][1]],
) for proto in WELL_KNOWN_PROTO_MAP.items()]
316

317 318 319 320
################################################################################
# Protocol Buffers Compiler
################################################################################

321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
cc_library(
    name = "protoc_lib",
    srcs = [
        # AUTOGEN(protoc_lib_srcs)
        "src/google/protobuf/compiler/code_generator.cc",
        "src/google/protobuf/compiler/command_line_interface.cc",
        "src/google/protobuf/compiler/cpp/cpp_enum.cc",
        "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
        "src/google/protobuf/compiler/cpp/cpp_extension.cc",
        "src/google/protobuf/compiler/cpp/cpp_field.cc",
        "src/google/protobuf/compiler/cpp/cpp_file.cc",
        "src/google/protobuf/compiler/cpp/cpp_generator.cc",
        "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
        "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
        "src/google/protobuf/compiler/cpp/cpp_message.cc",
        "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
337
        "src/google/protobuf/compiler/cpp/cpp_padding_optimizer.cc",
338 339 340
        "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
        "src/google/protobuf/compiler/cpp/cpp_service.cc",
        "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
341
        "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
342 343 344 345 346
        "src/google/protobuf/compiler/csharp/csharp_enum.cc",
        "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
        "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
        "src/google/protobuf/compiler/csharp/csharp_generator.cc",
        "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
347
        "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
348 349 350
        "src/google/protobuf/compiler/csharp/csharp_message.cc",
        "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
        "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
351
        "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
352 353 354 355
        "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
        "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
        "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
        "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
356
        "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
357 358 359 360 361
        "src/google/protobuf/compiler/java/java_context.cc",
        "src/google/protobuf/compiler/java/java_doc_comment.cc",
        "src/google/protobuf/compiler/java/java_enum.cc",
        "src/google/protobuf/compiler/java/java_enum_field.cc",
        "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
362
        "src/google/protobuf/compiler/java/java_enum_lite.cc",
363
        "src/google/protobuf/compiler/java/java_extension.cc",
364
        "src/google/protobuf/compiler/java/java_extension_lite.cc",
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
        "src/google/protobuf/compiler/java/java_field.cc",
        "src/google/protobuf/compiler/java/java_file.cc",
        "src/google/protobuf/compiler/java/java_generator.cc",
        "src/google/protobuf/compiler/java/java_generator_factory.cc",
        "src/google/protobuf/compiler/java/java_helpers.cc",
        "src/google/protobuf/compiler/java/java_map_field.cc",
        "src/google/protobuf/compiler/java/java_map_field_lite.cc",
        "src/google/protobuf/compiler/java/java_message.cc",
        "src/google/protobuf/compiler/java/java_message_builder.cc",
        "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
        "src/google/protobuf/compiler/java/java_message_field.cc",
        "src/google/protobuf/compiler/java/java_message_field_lite.cc",
        "src/google/protobuf/compiler/java/java_message_lite.cc",
        "src/google/protobuf/compiler/java/java_name_resolver.cc",
        "src/google/protobuf/compiler/java/java_primitive_field.cc",
        "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
        "src/google/protobuf/compiler/java/java_service.cc",
        "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
        "src/google/protobuf/compiler/java/java_string_field.cc",
        "src/google/protobuf/compiler/java/java_string_field_lite.cc",
Feng Xiao's avatar
Feng Xiao committed
385
        "src/google/protobuf/compiler/js/js_generator.cc",
Jisi Liu's avatar
Jisi Liu committed
386
        "src/google/protobuf/compiler/js/well_known_types_embed.cc",
387 388 389 390 391 392 393 394 395 396 397 398
        "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
399
        "src/google/protobuf/compiler/php/php_generator.cc",
400
        "src/google/protobuf/compiler/plugin.cc",
401
        "src/google/protobuf/compiler/plugin.pb.cc",
402 403 404 405 406 407 408
        "src/google/protobuf/compiler/python/python_generator.cc",
        "src/google/protobuf/compiler/ruby/ruby_generator.cc",
        "src/google/protobuf/compiler/subprocess.cc",
        "src/google/protobuf/compiler/zip_writer.cc",
    ],
    copts = COPTS,
    includes = ["src/"],
409
    linkopts = LINK_OPTS,
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
    visibility = ["//visibility:public"],
    deps = [":protobuf"],
)

cc_binary(
    name = "protoc",
    srcs = ["src/google/protobuf/compiler/main.cc"],
    linkopts = LINK_OPTS,
    visibility = ["//visibility:public"],
    deps = [":protoc_lib"],
)

################################################################################
# Tests
################################################################################

Jisi Liu's avatar
Jisi Liu committed
426
RELATIVE_LITE_TEST_PROTOS = [
427 428 429 430 431
    # AUTOGEN(lite_test_protos)
    "google/protobuf/map_lite_unittest.proto",
    "google/protobuf/unittest_import_lite.proto",
    "google/protobuf/unittest_import_public_lite.proto",
    "google/protobuf/unittest_lite.proto",
432
    "google/protobuf/unittest_no_arena_lite.proto",
433 434
]

Jisi Liu's avatar
Jisi Liu committed
435 436 437
LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]

RELATIVE_TEST_PROTOS = [
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
    # AUTOGEN(test_protos)
    "google/protobuf/any_test.proto",
    "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
    "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
    "google/protobuf/map_proto2_unittest.proto",
    "google/protobuf/map_unittest.proto",
    "google/protobuf/unittest.proto",
    "google/protobuf/unittest_arena.proto",
    "google/protobuf/unittest_custom_options.proto",
    "google/protobuf/unittest_drop_unknown_fields.proto",
    "google/protobuf/unittest_embed_optimize_for.proto",
    "google/protobuf/unittest_empty.proto",
    "google/protobuf/unittest_enormous_descriptor.proto",
    "google/protobuf/unittest_import.proto",
    "google/protobuf/unittest_import_public.proto",
453 454 455
    "google/protobuf/unittest_lazy_dependencies.proto",
    "google/protobuf/unittest_lazy_dependencies_custom_option.proto",
    "google/protobuf/unittest_lazy_dependencies_enum.proto",
456 457
    "google/protobuf/unittest_lite_imports_nonlite.proto",
    "google/protobuf/unittest_mset.proto",
458
    "google/protobuf/unittest_mset_wire_format.proto",
459 460 461 462 463 464 465
    "google/protobuf/unittest_no_arena.proto",
    "google/protobuf/unittest_no_arena_import.proto",
    "google/protobuf/unittest_no_field_presence.proto",
    "google/protobuf/unittest_no_generic_services.proto",
    "google/protobuf/unittest_optimize_for.proto",
    "google/protobuf/unittest_preserve_unknown_enum.proto",
    "google/protobuf/unittest_preserve_unknown_enum2.proto",
Feng Xiao's avatar
Feng Xiao committed
466
    "google/protobuf/unittest_proto3.proto",
467
    "google/protobuf/unittest_proto3_arena.proto",
468 469
    "google/protobuf/unittest_proto3_arena_lite.proto",
    "google/protobuf/unittest_proto3_lite.proto",
470
    "google/protobuf/unittest_well_known_types.proto",
471 472 473 474 475 476
    "google/protobuf/util/internal/testdata/anys.proto",
    "google/protobuf/util/internal/testdata/books.proto",
    "google/protobuf/util/internal/testdata/default_value.proto",
    "google/protobuf/util/internal/testdata/default_value_test.proto",
    "google/protobuf/util/internal/testdata/field_mask.proto",
    "google/protobuf/util/internal/testdata/maps.proto",
477
    "google/protobuf/util/internal/testdata/oneofs.proto",
478
    "google/protobuf/util/internal/testdata/proto3.proto",
479 480
    "google/protobuf/util/internal/testdata/struct.proto",
    "google/protobuf/util/internal/testdata/timestamp_duration.proto",
481
    "google/protobuf/util/internal/testdata/wrappers.proto",
Feng Xiao's avatar
Feng Xiao committed
482
    "google/protobuf/util/json_format.proto",
483
    "google/protobuf/util/json_format_proto3.proto",
Feng Xiao's avatar
Feng Xiao committed
484
    "google/protobuf/util/message_differencer_unittest.proto",
485 486
]

Jisi Liu's avatar
Jisi Liu committed
487 488
TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]

489 490
cc_proto_library(
    name = "cc_test_protos",
Jisi Liu's avatar
Jisi Liu committed
491
    srcs = LITE_TEST_PROTOS + TEST_PROTOS,
492
    include = "src",
493
    default_runtime = ":protobuf",
494
    protoc = ":protoc",
495
    deps = [":cc_wkt_protos"],
496 497 498 499 500
)

COMMON_TEST_SRCS = [
    # AUTOGEN(common_test_srcs)
    "src/google/protobuf/arena_test_util.cc",
501
    "src/google/protobuf/map_test_util.inc",
502
    "src/google/protobuf/test_util.cc",
503
    "src/google/protobuf/test_util.inc",
504 505 506 507
    "src/google/protobuf/testing/file.cc",
    "src/google/protobuf/testing/googletest.cc",
]

508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
cc_binary(
    name = "test_plugin",
    srcs = [
        # AUTOGEN(test_plugin_srcs)
        "src/google/protobuf/compiler/mock_code_generator.cc",
        "src/google/protobuf/compiler/test_plugin.cc",
        "src/google/protobuf/testing/file.cc",
    ],
    deps = [
        ":protobuf",
        ":protoc_lib",
        "//external:gtest",
    ],
)

Jisi Liu's avatar
Jisi Liu committed
523 524
cc_test(
    name = "win32_test",
525
    srcs = ["src/google/protobuf/io/io_win32_unittest.cc"],
526 527 528 529
    tags = [
        "manual",
        "windows",
    ],
Jisi Liu's avatar
Jisi Liu committed
530 531 532 533 534 535
    deps = [
        ":protobuf_lite",
        "//external:gtest_main",
    ],
)

536 537
cc_test(
    name = "protobuf_test",
538
    srcs = COMMON_TEST_SRCS + [
539 540 541 542
        # AUTOGEN(test_srcs)
        "src/google/protobuf/any_test.cc",
        "src/google/protobuf/arena_unittest.cc",
        "src/google/protobuf/arenastring_unittest.cc",
Jisi Liu's avatar
Jisi Liu committed
543
        "src/google/protobuf/compiler/annotation_test_util.cc",
544
        "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
Jisi Liu's avatar
Jisi Liu committed
545
        "src/google/protobuf/compiler/cpp/cpp_move_unittest.cc",
546 547
        "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
        "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
548
        "src/google/protobuf/compiler/cpp/cpp_unittest.inc",
549
        "src/google/protobuf/compiler/cpp/metadata_test.cc",
550
        "src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc",
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
        "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
        "src/google/protobuf/compiler/importer_unittest.cc",
        "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
        "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
        "src/google/protobuf/compiler/mock_code_generator.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
        "src/google/protobuf/compiler/parser_unittest.cc",
        "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
        "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
        "src/google/protobuf/descriptor_database_unittest.cc",
        "src/google/protobuf/descriptor_unittest.cc",
        "src/google/protobuf/drop_unknown_fields_test.cc",
        "src/google/protobuf/dynamic_message_unittest.cc",
        "src/google/protobuf/extension_set_unittest.cc",
        "src/google/protobuf/generated_message_reflection_unittest.cc",
        "src/google/protobuf/io/coded_stream_unittest.cc",
567
        "src/google/protobuf/io/io_win32_unittest.cc",
568 569 570 571 572 573
        "src/google/protobuf/io/printer_unittest.cc",
        "src/google/protobuf/io/tokenizer_unittest.cc",
        "src/google/protobuf/io/zero_copy_stream_unittest.cc",
        "src/google/protobuf/map_field_test.cc",
        "src/google/protobuf/map_test.cc",
        "src/google/protobuf/message_unittest.cc",
574
        "src/google/protobuf/message_unittest.inc",
575 576
        "src/google/protobuf/no_field_presence_test.cc",
        "src/google/protobuf/preserve_unknown_enum_test.cc",
577
        "src/google/protobuf/proto3_arena_lite_unittest.cc",
Jisi Liu's avatar
Jisi Liu committed
578
        "src/google/protobuf/proto3_arena_unittest.cc",
579
        "src/google/protobuf/proto3_lite_unittest.cc",
Feng Xiao's avatar
Feng Xiao committed
580
        "src/google/protobuf/proto3_lite_unittest.inc",
581 582 583 584 585
        "src/google/protobuf/reflection_ops_unittest.cc",
        "src/google/protobuf/repeated_field_reflection_unittest.cc",
        "src/google/protobuf/repeated_field_unittest.cc",
        "src/google/protobuf/stubs/bytestream_unittest.cc",
        "src/google/protobuf/stubs/common_unittest.cc",
586
        "src/google/protobuf/stubs/int128_unittest.cc",
587 588 589 590 591 592 593 594 595 596
        "src/google/protobuf/stubs/status_test.cc",
        "src/google/protobuf/stubs/statusor_test.cc",
        "src/google/protobuf/stubs/stringpiece_unittest.cc",
        "src/google/protobuf/stubs/stringprintf_unittest.cc",
        "src/google/protobuf/stubs/structurally_valid_unittest.cc",
        "src/google/protobuf/stubs/strutil_unittest.cc",
        "src/google/protobuf/stubs/template_util_unittest.cc",
        "src/google/protobuf/stubs/time_test.cc",
        "src/google/protobuf/text_format_unittest.cc",
        "src/google/protobuf/unknown_field_set_unittest.cc",
597
        "src/google/protobuf/util/delimited_message_util_test.cc",
598
        "src/google/protobuf/util/field_comparator_test.cc",
599
        "src/google/protobuf/util/field_mask_util_test.cc",
600 601 602 603 604 605 606
        "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
        "src/google/protobuf/util/internal/json_objectwriter_test.cc",
        "src/google/protobuf/util/internal/json_stream_parser_test.cc",
        "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
        "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
        "src/google/protobuf/util/internal/type_info_test_helper.cc",
        "src/google/protobuf/util/json_util_test.cc",
Feng Xiao's avatar
Feng Xiao committed
607
        "src/google/protobuf/util/message_differencer_unittest.cc",
608
        "src/google/protobuf/util/time_util_test.cc",
609 610 611
        "src/google/protobuf/util/type_resolver_util_test.cc",
        "src/google/protobuf/well_known_types_unittest.cc",
        "src/google/protobuf/wire_format_unittest.cc",
612
    ] + select({
613
        "//conditions:default": [
614
            # AUTOGEN(non_msvc_test_srcs)
615 616
            "src/google/protobuf/compiler/command_line_interface_unittest.cc",
        ],
617
        ":msvc": [],
618
    }),
619 620 621
    copts = COPTS,
    data = [
        ":test_plugin",
622 623
    ] + glob([
        "src/google/protobuf/**/*",
624 625 626
        # Files for csharp_bootstrap_unittest.cc.
        "conformance/**/*",
        "csharp/src/**/*",
627
    ]),
628 629 630 631 632
    includes = [
        "src/",
    ],
    linkopts = LINK_OPTS,
    deps = [
Jisi Liu's avatar
Jisi Liu committed
633
        ":cc_test_protos",
634 635 636
        ":protobuf",
        ":protoc_lib",
        "//external:gtest_main",
637
    ] + PROTOBUF_DEPS,
638
)
Jisi Liu's avatar
Jisi Liu committed
639 640 641 642

################################################################################
# Java support
################################################################################
643
internal_gen_well_known_protos_java(
Ming Zhao's avatar
Ming Zhao committed
644
    srcs = WELL_KNOWN_PROTOS,
Jisi Liu's avatar
Jisi Liu committed
645 646 647
)

java_library(
648
    name = "protobuf_java",
Jisi Liu's avatar
Jisi Liu committed
649
    srcs = glob([
Ming Zhao's avatar
Ming Zhao committed
650
        "java/core/src/main/java/com/google/protobuf/*.java",
Jisi Liu's avatar
Jisi Liu committed
651
    ]) + [
Ming Zhao's avatar
Ming Zhao committed
652
        ":gen_well_known_protos_java",
Jisi Liu's avatar
Jisi Liu committed
653
    ],
654
    javacopts = select({
655 656 657 658 659
        "//:jdk9": ["--add-modules=jdk.unsupported"],
        "//conditions:default": [
            "-source 7",
            "-target 7",
        ],
660
    }),
Jisi Liu's avatar
Jisi Liu committed
661 662 663
    visibility = ["//visibility:public"],
)

664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
java_library(
    name = "protobuf_javalite",
    srcs = [
        # Keep in sync with java/lite/pom.xml
        "java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java",
        "java/core/src/main/java/com/google/protobuf/AbstractParser.java",
        "java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java",
        "java/core/src/main/java/com/google/protobuf/AllocatedBuffer.java",
        "java/core/src/main/java/com/google/protobuf/Android.java",
        "java/core/src/main/java/com/google/protobuf/ArrayDecoders.java",
        "java/core/src/main/java/com/google/protobuf/BinaryReader.java",
        "java/core/src/main/java/com/google/protobuf/BinaryWriter.java",
        "java/core/src/main/java/com/google/protobuf/BooleanArrayList.java",
        "java/core/src/main/java/com/google/protobuf/BufferAllocator.java",
        "java/core/src/main/java/com/google/protobuf/ByteBufferWriter.java",
        "java/core/src/main/java/com/google/protobuf/ByteOutput.java",
        "java/core/src/main/java/com/google/protobuf/ByteString.java",
        "java/core/src/main/java/com/google/protobuf/CodedInputStream.java",
        "java/core/src/main/java/com/google/protobuf/CodedInputStreamReader.java",
        "java/core/src/main/java/com/google/protobuf/CodedOutputStream.java",
        "java/core/src/main/java/com/google/protobuf/CodedOutputStreamWriter.java",
        "java/core/src/main/java/com/google/protobuf/DoubleArrayList.java",
        "java/core/src/main/java/com/google/protobuf/ExperimentalApi.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionLite.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionSchema.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionSchemaLite.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionSchemas.java",
        "java/core/src/main/java/com/google/protobuf/FieldInfo.java",
        "java/core/src/main/java/com/google/protobuf/FieldSet.java",
        "java/core/src/main/java/com/google/protobuf/FieldType.java",
        "java/core/src/main/java/com/google/protobuf/FloatArrayList.java",
        "java/core/src/main/java/com/google/protobuf/GeneratedMessageInfoFactory.java",
        "java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java",
        "java/core/src/main/java/com/google/protobuf/IntArrayList.java",
        "java/core/src/main/java/com/google/protobuf/Internal.java",
        "java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java",
        "java/core/src/main/java/com/google/protobuf/IterableByteBufferInputStream.java",
        "java/core/src/main/java/com/google/protobuf/JavaType.java",
        "java/core/src/main/java/com/google/protobuf/LazyField.java",
        "java/core/src/main/java/com/google/protobuf/LazyFieldLite.java",
        "java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java",
        "java/core/src/main/java/com/google/protobuf/LazyStringList.java",
        "java/core/src/main/java/com/google/protobuf/ListFieldSchema.java",
        "java/core/src/main/java/com/google/protobuf/LongArrayList.java",
        "java/core/src/main/java/com/google/protobuf/ManifestSchemaFactory.java",
        "java/core/src/main/java/com/google/protobuf/MapEntryLite.java",
        "java/core/src/main/java/com/google/protobuf/MapFieldLite.java",
        "java/core/src/main/java/com/google/protobuf/MapFieldSchema.java",
        "java/core/src/main/java/com/google/protobuf/MapFieldSchemaLite.java",
        "java/core/src/main/java/com/google/protobuf/MapFieldSchemas.java",
        "java/core/src/main/java/com/google/protobuf/MessageInfo.java",
        "java/core/src/main/java/com/google/protobuf/MessageInfoFactory.java",
        "java/core/src/main/java/com/google/protobuf/MessageLite.java",
        "java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java",
        "java/core/src/main/java/com/google/protobuf/MessageLiteToString.java",
        "java/core/src/main/java/com/google/protobuf/MessageSchema.java",
        "java/core/src/main/java/com/google/protobuf/MessageSetSchema.java",
        "java/core/src/main/java/com/google/protobuf/MutabilityOracle.java",
        "java/core/src/main/java/com/google/protobuf/NewInstanceSchema.java",
        "java/core/src/main/java/com/google/protobuf/NewInstanceSchemaLite.java",
        "java/core/src/main/java/com/google/protobuf/NewInstanceSchemas.java",
        "java/core/src/main/java/com/google/protobuf/NioByteString.java",
        "java/core/src/main/java/com/google/protobuf/OneofInfo.java",
        "java/core/src/main/java/com/google/protobuf/Parser.java",
        "java/core/src/main/java/com/google/protobuf/PrimitiveNonBoxingCollection.java",
        "java/core/src/main/java/com/google/protobuf/ProtoSyntax.java",
        "java/core/src/main/java/com/google/protobuf/Protobuf.java",
        "java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java",
        "java/core/src/main/java/com/google/protobuf/ProtobufLists.java",
        "java/core/src/main/java/com/google/protobuf/ProtocolStringList.java",
        "java/core/src/main/java/com/google/protobuf/RawMessageInfo.java",
        "java/core/src/main/java/com/google/protobuf/Reader.java",
        "java/core/src/main/java/com/google/protobuf/RopeByteString.java",
        "java/core/src/main/java/com/google/protobuf/Schema.java",
        "java/core/src/main/java/com/google/protobuf/SchemaFactory.java",
        "java/core/src/main/java/com/google/protobuf/SchemaUtil.java",
        "java/core/src/main/java/com/google/protobuf/SmallSortedMap.java",
        "java/core/src/main/java/com/google/protobuf/StructuralMessageInfo.java",
        "java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java",
        "java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java",
        "java/core/src/main/java/com/google/protobuf/UnknownFieldSchema.java",
        "java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java",
        "java/core/src/main/java/com/google/protobuf/UnknownFieldSetLiteSchema.java",
        "java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java",
        "java/core/src/main/java/com/google/protobuf/UnsafeUtil.java",
        "java/core/src/main/java/com/google/protobuf/Utf8.java",
        "java/core/src/main/java/com/google/protobuf/WireFormat.java",
        "java/core/src/main/java/com/google/protobuf/Writer.java",
    ],
    javacopts = select({
        "//:jdk9": ["--add-modules=jdk.unsupported"],
        "//conditions:default": [
            "-source 7",
            "-target 7",
        ],
761
    }),
Jisi Liu's avatar
Jisi Liu committed
762 763 764
    visibility = ["//visibility:public"],
)

765 766 767 768 769
java_library(
    name = "protobuf_java_util",
    srcs = glob([
        "java/util/src/main/java/com/google/protobuf/util/*.java",
    ]),
770 771 772 773
    javacopts = [
        "-source 7",
        "-target 7",
    ],
774
    visibility = ["//visibility:public"],
775
    deps = [
776
        "protobuf_java",
777
        "//external:error_prone_annotations",
778 779
        "//external:gson",
        "//external:guava",
780 781 782
    ],
)

Jisi Liu's avatar
Jisi Liu committed
783 784 785 786
################################################################################
# Python support
################################################################################

787
py_library(
Jisi Liu's avatar
Jisi Liu committed
788 789 790
    name = "python_srcs",
    srcs = glob(
        [
791
            "python/google/**/*.py",
Jisi Liu's avatar
Jisi Liu committed
792 793
        ],
        exclude = [
794
            "python/google/protobuf/**/__init__.py",
Jisi Liu's avatar
Jisi Liu committed
795 796 797 798
            "python/google/protobuf/internal/*_test.py",
            "python/google/protobuf/internal/test_util.py",
        ],
    ),
799
    imports = ["python"],
800
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
801 802
)

803
cc_binary(
804
    name = "python/google/protobuf/internal/_api_implementation.so",
805 806 807 808 809 810
    srcs = ["python/google/protobuf/internal/api_implementation.cc"],
    copts = COPTS + [
        "-DPYTHON_PROTO2_CPP_IMPL_V2",
    ],
    linkshared = 1,
    linkstatic = 1,
811 812
    deps = select({
        "//conditions:default": [],
813
        ":use_fast_cpp_protos": ["//external:python_headers"],
814
    }),
815 816 817
)

cc_binary(
818
    name = "python/google/protobuf/pyext/_message.so",
819 820 821 822 823 824
    srcs = glob([
        "python/google/protobuf/pyext/*.cc",
        "python/google/protobuf/pyext/*.h",
    ]),
    copts = COPTS + [
        "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
825 826 827 828
    ] + select({
        "//conditions:default": [],
        ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
    }),
829 830 831 832 833 834
    includes = [
        "python/",
        "src/",
    ],
    linkshared = 1,
    linkstatic = 1,
835 836
    deps = [
        ":protobuf",
837
        ":proto_api",
838 839
    ] + select({
        "//conditions:default": [],
840
        ":use_fast_cpp_protos": ["//external:python_headers"],
841 842 843 844 845 846 847 848
    }),
)

config_setting(
    name = "use_fast_cpp_protos",
    values = {
        "define": "use_fast_cpp_protos=true",
    },
849 850
)

851 852 853 854 855 856 857
config_setting(
    name = "allow_oversize_protos",
    values = {
        "define": "allow_oversize_protos=true",
    },
)

858 859 860 861 862 863 864 865 866
# Copy the builtin proto files from src/google/protobuf to
# python/google/protobuf. This way, the generated Python sources will be in the
# same directory as the Python runtime sources. This is necessary for the
# modules to be imported correctly since they are all part of the same Python
# package.
internal_copied_filegroup(
    name = "protos_python",
    srcs = WELL_KNOWN_PROTOS,
    dest = "python",
867
    strip_prefix = "src",
868 869 870 871
)

# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
# which case we can simply add :protos_python in srcs.
872
COPIED_WELL_KNOWN_PROTOS = ["python/" + s[4:] for s in WELL_KNOWN_PROTOS]
873

Jisi Liu's avatar
Jisi Liu committed
874
py_proto_library(
875
    name = "protobuf_python",
876 877
    srcs = COPIED_WELL_KNOWN_PROTOS,
    include = "python",
878 879 880
    data = select({
        "//conditions:default": [],
        ":use_fast_cpp_protos": [
881 882
            ":python/google/protobuf/internal/_api_implementation.so",
            ":python/google/protobuf/pyext/_message.so",
883 884
        ],
    }),
885
    default_runtime = "",
886
    protoc = ":protoc",
887
    py_extra_srcs = glob(["python/**/__init__.py"]),
888 889
    py_libs = [
        ":python_srcs",
890
        "@six//:six",
891
    ],
892
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
893 894 895
    visibility = ["//visibility:public"],
)

896 897 898 899 900 901 902 903 904
# Copy the test proto files from src/google/protobuf to
# python/google/protobuf. This way, the generated Python sources will be in the
# same directory as the Python runtime sources. This is necessary for the
# modules to be imported correctly by the tests since they are all part of the
# same Python package.
internal_copied_filegroup(
    name = "protos_python_test",
    srcs = LITE_TEST_PROTOS + TEST_PROTOS,
    dest = "python",
905
    strip_prefix = "src",
906 907 908 909 910
)

# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
# which case we can simply add :protos_python_test in srcs.
COPIED_LITE_TEST_PROTOS = ["python/" + s for s in RELATIVE_LITE_TEST_PROTOS]
911

912 913
COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]

Jisi Liu's avatar
Jisi Liu committed
914 915
py_proto_library(
    name = "python_common_test_protos",
916 917
    srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
    include = "python",
918
    default_runtime = "",
919
    protoc = ":protoc",
920
    srcs_version = "PY2AND3",
921
    deps = [":protobuf_python"],
Jisi Liu's avatar
Jisi Liu committed
922 923 924 925
)

py_proto_library(
    name = "python_specific_test_protos",
926 927 928 929
    srcs = glob([
        "python/google/protobuf/internal/*.proto",
        "python/google/protobuf/internal/import_test_package/*.proto",
    ]),
Jisi Liu's avatar
Jisi Liu committed
930
    include = "python",
931
    default_runtime = ":protobuf_python",
932
    protoc = ":protoc",
933
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
934 935 936 937 938
    deps = [":python_common_test_protos"],
)

py_library(
    name = "python_tests",
939 940 941 942
    srcs = glob(
        [
            "python/google/protobuf/internal/*_test.py",
            "python/google/protobuf/internal/test_util.py",
943
            "python/google/protobuf/internal/import_test_package/__init__.py",
944 945 946
        ],
    ),
    imports = ["python"],
947
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
948
    deps = [
949
        ":protobuf_python",
950
        ":python_common_test_protos",
Jisi Liu's avatar
Jisi Liu committed
951 952 953 954 955
        ":python_specific_test_protos",
    ],
)

internal_protobuf_py_tests(
Jisi Liu's avatar
Jisi Liu committed
956
    name = "python_tests_batch",
957 958 959
    data = glob([
        "src/google/protobuf/**/*",
    ]),
Jisi Liu's avatar
Jisi Liu committed
960 961 962 963 964 965 966
    modules = [
        "descriptor_database_test",
        "descriptor_pool_test",
        "descriptor_test",
        "generator_test",
        "json_format_test",
        "message_factory_test",
967
        "message_test",
Jisi Liu's avatar
Jisi Liu committed
968
        "proto_builder_test",
969
        "reflection_test",
Jisi Liu's avatar
Jisi Liu committed
970 971 972
        "service_reflection_test",
        "symbol_database_test",
        "text_encoding_test",
973
        "text_format_test",
Jisi Liu's avatar
Jisi Liu committed
974 975 976 977 978
        "unknown_fields_test",
        "wire_format_test",
    ],
    deps = [":python_tests"],
)
979

980 981 982
cc_library(
    name = "proto_api",
    hdrs = ["python/google/protobuf/proto_api.h"],
983
    visibility = ["//visibility:public"],
984 985 986 987 988
    deps = [
        "//external:python_headers",
    ],
)

989
proto_lang_toolchain(
990
    name = "cc_toolchain",
991
    blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
992 993 994
    command_line = "--cpp_out=$(OUT)",
    runtime = ":protobuf",
    visibility = ["//visibility:public"],
995
)
996 997 998 999 1000 1001 1002

proto_lang_toolchain(
    name = "java_toolchain",
    command_line = "--java_out=$(OUT)",
    runtime = ":protobuf_java",
    visibility = ["//visibility:public"],
)
1003

1004 1005 1006 1007 1008 1009 1010
proto_lang_toolchain(
    name = "javalite_toolchain",
    command_line = "--java_out=lite:$(OUT)",
    runtime = ":protobuf_javalite",
    visibility = ["//visibility:public"],
)

1011 1012 1013 1014 1015
alias(
    name = "objectivec",
    actual = ":protobuf_objc",
    visibility = ["//visibility:public"],
)
1016 1017

objc_library(
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
    name = "protobuf_objc",
    hdrs = [
        "objectivec/GPBArray.h",
        "objectivec/GPBBootstrap.h",
        "objectivec/GPBCodedInputStream.h",
        "objectivec/GPBCodedOutputStream.h",
        "objectivec/GPBDescriptor.h",
        "objectivec/GPBDictionary.h",
        "objectivec/GPBExtensionInternals.h",
        "objectivec/GPBExtensionRegistry.h",
        "objectivec/GPBMessage.h",
        "objectivec/GPBProtocolBuffers.h",
        "objectivec/GPBProtocolBuffers_RuntimeSupport.h",
        "objectivec/GPBRootObject.h",
        "objectivec/GPBRuntimeTypes.h",
        "objectivec/GPBUnknownField.h",
        "objectivec/GPBUnknownFieldSet.h",
        "objectivec/GPBUtilities.h",
        "objectivec/GPBWellKnownTypes.h",
        "objectivec/GPBWireFormat.h",
        "objectivec/google/protobuf/Any.pbobjc.h",
        "objectivec/google/protobuf/Api.pbobjc.h",
        "objectivec/google/protobuf/Duration.pbobjc.h",
        "objectivec/google/protobuf/Empty.pbobjc.h",
        "objectivec/google/protobuf/FieldMask.pbobjc.h",
        "objectivec/google/protobuf/SourceContext.pbobjc.h",
        "objectivec/google/protobuf/Struct.pbobjc.h",
        "objectivec/google/protobuf/Timestamp.pbobjc.h",
        "objectivec/google/protobuf/Type.pbobjc.h",
        "objectivec/google/protobuf/Wrappers.pbobjc.h",
        # Package private headers, but exposed because the generated sources
        # need to use them.
        "objectivec/GPBArray_PackagePrivate.h",
        "objectivec/GPBCodedInputStream_PackagePrivate.h",
        "objectivec/GPBCodedOutputStream_PackagePrivate.h",
        "objectivec/GPBDescriptor_PackagePrivate.h",
        "objectivec/GPBDictionary_PackagePrivate.h",
        "objectivec/GPBMessage_PackagePrivate.h",
        "objectivec/GPBRootObject_PackagePrivate.h",
        "objectivec/GPBUnknownFieldSet_PackagePrivate.h",
        "objectivec/GPBUnknownField_PackagePrivate.h",
        "objectivec/GPBUtilities_PackagePrivate.h",
    ],
1061 1062 1063
    copts = [
        "-Wno-vla",
    ],
1064 1065 1066
    includes = [
        "objectivec",
    ],
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
    non_arc_srcs = [
        "objectivec/GPBArray.m",
        "objectivec/GPBCodedInputStream.m",
        "objectivec/GPBCodedOutputStream.m",
        "objectivec/GPBDescriptor.m",
        "objectivec/GPBDictionary.m",
        "objectivec/GPBExtensionInternals.m",
        "objectivec/GPBExtensionRegistry.m",
        "objectivec/GPBMessage.m",
        "objectivec/GPBRootObject.m",
        "objectivec/GPBUnknownField.m",
        "objectivec/GPBUnknownFieldSet.m",
        "objectivec/GPBUtilities.m",
        "objectivec/GPBWellKnownTypes.m",
        "objectivec/GPBWireFormat.m",
        "objectivec/google/protobuf/Any.pbobjc.m",
        "objectivec/google/protobuf/Api.pbobjc.m",
        "objectivec/google/protobuf/Duration.pbobjc.m",
        "objectivec/google/protobuf/Empty.pbobjc.m",
        "objectivec/google/protobuf/FieldMask.pbobjc.m",
        "objectivec/google/protobuf/SourceContext.pbobjc.m",
        "objectivec/google/protobuf/Struct.pbobjc.m",
        "objectivec/google/protobuf/Timestamp.pbobjc.m",
        "objectivec/google/protobuf/Type.pbobjc.m",
        "objectivec/google/protobuf/Wrappers.pbobjc.m",
    ],
1093 1094
    visibility = ["//visibility:public"],
)
1095 1096 1097 1098 1099 1100 1101 1102 1103

################################################################################
# Test generated proto support
################################################################################

genrule(
    name = "generated_protos",
    srcs = ["src/google/protobuf/unittest_import.proto"],
    outs = ["unittest_gen.proto"],
1104
    cmd = "cat $(SRCS) | sed 's|google/|src/google/|' >  $(OUTS)",
1105 1106 1107 1108
)

proto_library(
    name = "generated_protos_proto",
1109 1110
    srcs = [
        "src/google/protobuf/unittest_import_public.proto",
1111
        "unittest_gen.proto",
1112
    ],
1113 1114 1115 1116 1117 1118
)

py_proto_library(
    name = "generated_protos_py",
    srcs = [
        "src/google/protobuf/unittest_import_public.proto",
1119
        "unittest_gen.proto",
1120 1121 1122 1123
    ],
    default_runtime = "",
    protoc = ":protoc",
)
1124 1125 1126 1127 1128 1129 1130

################################################################################
# Conformance tests
################################################################################

proto_library(
    name = "test_messages_proto2_proto",
1131
    srcs = ["src/google/protobuf/test_messages_proto2.proto"],
Josh Haberman's avatar
Josh Haberman committed
1132
    visibility = ["//visibility:public"],
1133 1134 1135 1136
)

proto_library(
    name = "test_messages_proto3_proto",
1137
    srcs = ["src/google/protobuf/test_messages_proto3.proto"],
1138
    visibility = ["//visibility:public"],
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
    deps = [
        ":any_proto",
        ":duration_proto",
        ":field_mask_proto",
        ":struct_proto",
        ":timestamp_proto",
        ":wrappers_proto",
    ],
)

cc_proto_library(
    name = "test_messages_proto2_proto_cc",
1151
    srcs = ["src/google/protobuf/test_messages_proto2.proto"],
1152 1153 1154 1155
)

cc_proto_library(
    name = "test_messages_proto3_proto_cc",
1156
    srcs = ["src/google/protobuf/test_messages_proto3.proto"],
1157 1158 1159 1160 1161 1162 1163
    deps = [
        ":cc_wkt_protos",
    ],
)

proto_library(
    name = "conformance_proto",
1164
    srcs = ["conformance/conformance.proto"],
Josh Haberman's avatar
Josh Haberman committed
1165
    visibility = ["//visibility:public"],
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
)

cc_proto_library(
    name = "conformance_proto_cc",
    srcs = ["conformance/conformance.proto"],
)

cc_library(
    name = "jsoncpp",
    srcs = ["conformance/third_party/jsoncpp/jsoncpp.cpp"],
1176
    hdrs = ["conformance/third_party/jsoncpp/json.h"],
1177 1178 1179 1180 1181 1182 1183
    includes = ["conformance"],
)

cc_library(
    name = "conformance_test",
    srcs = [
        "conformance/conformance_test.cc",
1184
        "conformance/conformance_test_runner.cc",
1185 1186 1187 1188
    ],
    hdrs = [
        "conformance/conformance_test.h",
    ],
1189 1190 1191 1192
    includes = [
        "conformance",
        "src",
    ],
1193 1194 1195 1196 1197 1198 1199
    deps = [":conformance_proto_cc"],
)

cc_library(
    name = "binary_json_conformance_suite",
    srcs = ["conformance/binary_json_conformance_suite.cc"],
    hdrs = ["conformance/binary_json_conformance_suite.h"],
1200
    deps = [
1201
        ":conformance_test",
1202 1203 1204 1205 1206 1207
        ":jsoncpp",
        ":test_messages_proto2_proto_cc",
        ":test_messages_proto3_proto_cc",
    ],
)

1208 1209 1210 1211 1212 1213 1214 1215
cc_library(
    name = "text_format_conformance_suite",
    srcs = ["conformance/text_format_conformance_suite.cc"],
    hdrs = ["conformance/text_format_conformance_suite.h"],
    deps = [
        ":conformance_test",
        ":test_messages_proto2_proto_cc",
        ":test_messages_proto3_proto_cc",
1216
    ],
1217 1218
)

1219
cc_binary(
1220 1221
    name = "conformance_test_runner",
    srcs = ["conformance/conformance_test_main.cc"],
1222
    visibility = ["//visibility:public"],
1223
    deps = [
1224
        ":binary_json_conformance_suite",
1225
        ":conformance_test",
1226
        ":text_format_conformance_suite",
Josh Haberman's avatar
Josh Haberman committed
1227
    ],
1228
)
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245

sh_test(
    name = "build_files_updated_unittest",
    srcs = [
        "build_files_updated_unittest.sh",
    ],
    data = [
        "BUILD",
        "cmake/extract_includes.bat.in",
        "cmake/libprotobuf.cmake",
        "cmake/libprotobuf-lite.cmake",
        "cmake/libprotoc.cmake",
        "cmake/tests.cmake",
        "src/Makefile.am",
        "update_file_lists.sh",
    ],
)