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

licenses(["notice"])

5 6
exports_files(["LICENSE"])

7 8 9 10 11 12 13 14 15 16 17
################################################################################
# Java 9 configuration
################################################################################

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

18 19 20 21
################################################################################
# Protobuf Runtime Library
################################################################################

22
MSVC_COPTS = [
23 24
    "/DHAVE_PTHREAD",
    "/wd4018", # -Wno-sign-compare
25 26 27 28 29 30 31 32 33 34 35
    "/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'
36
    "/wd4514", # -Wno-unused-function
37 38
    "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning)
    "/wd4996", # The compiler encountered a deprecated declaration.
39 40
]

41
COPTS = select({
42
    ":msvc" : MSVC_COPTS,
43 44 45 46 47 48
    "//conditions:default": [
        "-DHAVE_PTHREAD",
        "-Wall",
        "-Woverloaded-virtual",
        "-Wno-sign-compare",
        "-Wno-unused-function",
49 50
        # Prevents ISO C++ const string assignment warnings for pyext sources.
        "-Wno-writable-strings",
51
        "-Wno-write-strings",
52 53 54 55
    ],
})

config_setting(
56 57
    name = "msvc",
    values = { "compiler": "msvc-cl" },
58 59
)

60 61 62 63 64 65 66
config_setting(
    name = "android",
    values = {
        "crosstool_top": "//external:android/crosstool",
    },
)

67
# Android and MSVC builds do not need to link in a separate pthread library.
68
LINK_OPTS = select({
Andrew Harp's avatar
Andrew Harp committed
69
    ":android": [],
70
    ":msvc": [
71 72
        # Suppress linker warnings about files with no symbols defined.
        "-ignore:4221",
73
    ],
Daniel Ylitalo's avatar
Daniel Ylitalo committed
74
    "//conditions:default": ["-lpthread", "-lm"],
75
})
76

77
load(
78
    ":protobuf.bzl",
79 80
    "cc_proto_library",
    "py_proto_library",
81
    "internal_copied_filegroup",
82
    "internal_gen_well_known_protos_java",
83 84
    "internal_protobuf_py_tests",
)
85

86 87 88 89 90 91 92
cc_library(
    name = "protobuf_lite",
    srcs = [
        # AUTOGEN(protobuf_lite_srcs)
        "src/google/protobuf/arena.cc",
        "src/google/protobuf/arenastring.cc",
        "src/google/protobuf/extension_set.cc",
Jisi Liu's avatar
Jisi Liu committed
93
        "src/google/protobuf/generated_message_table_driven_lite.cc",
94
        "src/google/protobuf/generated_message_util.cc",
95
        "src/google/protobuf/implicit_weak_message.cc",
96 97 98 99 100
        "src/google/protobuf/io/coded_stream.cc",
        "src/google/protobuf/io/zero_copy_stream.cc",
        "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
        "src/google/protobuf/message_lite.cc",
        "src/google/protobuf/repeated_field.cc",
101
        "src/google/protobuf/stubs/bytestream.cc",
102
        "src/google/protobuf/stubs/common.cc",
103
        "src/google/protobuf/stubs/int128.cc",
Jisi Liu's avatar
Jisi Liu committed
104
        "src/google/protobuf/stubs/io_win32.cc",
105 106 107
        "src/google/protobuf/stubs/status.cc",
        "src/google/protobuf/stubs/statusor.cc",
        "src/google/protobuf/stubs/stringpiece.cc",
108
        "src/google/protobuf/stubs/stringprintf.cc",
109
        "src/google/protobuf/stubs/structurally_valid.cc",
110 111
        "src/google/protobuf/stubs/strutil.cc",
        "src/google/protobuf/stubs/time.cc",
112 113
        "src/google/protobuf/wire_format_lite.cc",
    ],
114
    hdrs = glob(["src/google/protobuf/**/*.h"]),
115
    copts = COPTS,
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    includes = ["src/"],
    linkopts = LINK_OPTS,
    visibility = ["//visibility:public"],
)

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
139
        "src/google/protobuf/generated_message_table_driven.cc",
140 141 142 143 144 145 146 147 148 149 150
        "src/google/protobuf/io/gzip_stream.cc",
        "src/google/protobuf/io/printer.cc",
        "src/google/protobuf/io/strtod.cc",
        "src/google/protobuf/io/tokenizer.cc",
        "src/google/protobuf/io/zero_copy_stream_impl.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",
151
        "src/google/protobuf/stubs/mathlimits.cc",
152 153 154 155 156
        "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
157
        "src/google/protobuf/util/delimited_message_util.cc",
158
        "src/google/protobuf/util/field_comparator.cc",
159
        "src/google/protobuf/util/field_mask_util.cc",
160 161 162 163 164 165 166 167
        "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
168
        "src/google/protobuf/util/internal/proto_writer.cc",
169 170 171 172 173 174 175
        "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",
176
        "src/google/protobuf/util/time_util.cc",
177
        "src/google/protobuf/util/type_resolver_util.cc",
178 179 180
        "src/google/protobuf/wire_format.cc",
        "src/google/protobuf/wrappers.pb.cc",
    ],
Lukacs T. Berki's avatar
Lukacs T. Berki committed
181
    hdrs = glob(["src/**/*.h"]),
182
    copts = COPTS,
183 184 185 186 187 188
    includes = ["src/"],
    linkopts = LINK_OPTS,
    visibility = ["//visibility:public"],
    deps = [":protobuf_lite"],
)

189 190 191 192
# 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.
193 194 195 196 197 198 199
cc_library(
    name = "protobuf_headers",
    hdrs = glob(["src/**/*.h"]),
    includes = ["src/"],
    visibility = ["//visibility:public"],
)

Jisi Liu's avatar
Jisi Liu committed
200 201 202 203 204 205 206
objc_library(
    name = "protobuf_objc",
    hdrs = ["objectivec/GPBProtocolBuffers.h"],
    includes = ["objectivec"],
    non_arc_srcs = ["objectivec/GPBProtocolBuffers.m"],
    visibility = ["//visibility:public"],
)
207

208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
# Map of all well known protos.
# name => (include path, imports)
WELL_KNOWN_PROTO_MAP = {
    "any" : ("google/protobuf/any.proto", []),
    "api" : ("google/protobuf/api.proto", ["source_context", "type"]),
    "compiler_plugin" : ("google/protobuf/compiler/plugin.proto", ["descriptor"]),
    "descriptor" : ("google/protobuf/descriptor.proto", []),
    "duration" : ("google/protobuf/duration.proto", []),
    "empty" : ("google/protobuf/empty.proto", []),
    "field_mask" : ("google/protobuf/field_mask.proto", []),
    "source_context" : ("google/protobuf/source_context.proto", []),
    "struct" : ("google/protobuf/struct.proto", []),
    "timestamp" : ("google/protobuf/timestamp.proto", []),
    "type" : ("google/protobuf/type.proto", ["any", "source_context"]),
    "wrappers" : ("google/protobuf/wrappers.proto", []),
}

RELATIVE_WELL_KNOWN_PROTOS = [proto[1][0] for proto in WELL_KNOWN_PROTO_MAP.items()]
226

Jisi Liu's avatar
Jisi Liu committed
227 228
WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]

229 230 231 232 233 234
filegroup(
    name = "well_known_protos",
    srcs = WELL_KNOWN_PROTOS,
    visibility = ["//visibility:public"],
)

235 236
cc_proto_library(
    name = "cc_wkt_protos",
Jisi Liu's avatar
Jisi Liu committed
237
    srcs = WELL_KNOWN_PROTOS,
238
    include = "src",
239
    default_runtime = ":protobuf",
Jisi Liu's avatar
Jisi Liu committed
240
    internal_bootstrap_hack = 1,
241
    protoc = ":protoc",
242
    visibility = ["//visibility:public"],
243 244
)

245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
################################################################################
# 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],
# )
################################################################################

internal_copied_filegroup(
    name = "_internal_wkt_protos",
    srcs = WELL_KNOWN_PROTOS,
    dest = "",
    strip_prefix = "src",
262
    visibility = ["//visibility:private"],
263 264 265 266 267 268 269 270 271
)

[proto_library(
    name = proto[0] + "_proto",
    srcs = [proto[1][0]],
    deps = [dep + "_proto" for dep in proto[1][1]],
    visibility = ["//visibility:public"],
    ) for proto in WELL_KNOWN_PROTO_MAP.items()]

272 273 274 275
################################################################################
# Protocol Buffers Compiler
################################################################################

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
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",
292
        "src/google/protobuf/compiler/cpp/cpp_padding_optimizer.cc",
293 294 295
        "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",
296
        "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
297 298 299 300 301
        "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",
302
        "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
303 304 305
        "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",
306
        "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
307 308 309 310
        "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",
311
        "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
312 313 314 315 316
        "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",
317
        "src/google/protobuf/compiler/java/java_enum_lite.cc",
318
        "src/google/protobuf/compiler/java/java_extension.cc",
319
        "src/google/protobuf/compiler/java/java_extension_lite.cc",
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
        "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_lazy_message_field.cc",
        "src/google/protobuf/compiler/java/java_lazy_message_field_lite.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
342
        "src/google/protobuf/compiler/js/js_generator.cc",
Jisi Liu's avatar
Jisi Liu committed
343
        "src/google/protobuf/compiler/js/well_known_types_embed.cc",
344 345 346 347 348 349 350 351 352 353 354 355
        "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",
356
        "src/google/protobuf/compiler/php/php_generator.cc",
357
        "src/google/protobuf/compiler/plugin.cc",
358
        "src/google/protobuf/compiler/plugin.pb.cc",
359 360 361 362 363 364 365
        "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/"],
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
    linkopts = LINK_OPTS + select({
        ":msvc": [
            # Linking to setargv.obj makes the default command line argument
            # parser expand wildcards, so the main method's argv will contain the
            # expanded list instead of the wildcards.
            #
            # Adding dummy "-DEFAULTLIB:kernel32.lib", because:
            # - Microsoft ships this object file next to default libraries
            # - but this file is not a library, just a precompiled object
            # - "-WHOLEARCHIVE" and "-DEFAULTLIB" only accept library,
            #   not precompiled object.
            # - Bazel would assume linkopt that does not start with "-" or "$"
            #   as a label to a target, so we add a harmless "-DEFAULTLIB:kernel32.lib"
            #   before "setargv.obj".
            # See https://msdn.microsoft.com/en-us/library/8bch7bkk.aspx
            "-DEFAULTLIB:kernel32.lib setargv.obj",
        ],
        "//conditions:default": [],
    }),
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
    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
401
RELATIVE_LITE_TEST_PROTOS = [
402 403 404 405 406
    # 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",
407
    "google/protobuf/unittest_no_arena_lite.proto",
408 409
]

Jisi Liu's avatar
Jisi Liu committed
410 411 412
LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]

RELATIVE_TEST_PROTOS = [
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
    # 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",
428 429 430
    "google/protobuf/unittest_lazy_dependencies.proto",
    "google/protobuf/unittest_lazy_dependencies_custom_option.proto",
    "google/protobuf/unittest_lazy_dependencies_enum.proto",
431 432
    "google/protobuf/unittest_lite_imports_nonlite.proto",
    "google/protobuf/unittest_mset.proto",
433
    "google/protobuf/unittest_mset_wire_format.proto",
434 435 436 437 438 439 440 441
    "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",
    "google/protobuf/unittest_proto3_arena.proto",
442 443
    "google/protobuf/unittest_proto3_arena_lite.proto",
    "google/protobuf/unittest_proto3_lite.proto",
444
    "google/protobuf/unittest_well_known_types.proto",
445 446 447 448 449 450
    "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",
451
    "google/protobuf/util/internal/testdata/oneofs.proto",
452
    "google/protobuf/util/internal/testdata/proto3.proto",
453 454
    "google/protobuf/util/internal/testdata/struct.proto",
    "google/protobuf/util/internal/testdata/timestamp_duration.proto",
455
    "google/protobuf/util/internal/testdata/wrappers.proto",
456
    "google/protobuf/util/json_format_proto3.proto",
Feng Xiao's avatar
Feng Xiao committed
457
    "google/protobuf/util/message_differencer_unittest.proto",
458 459
]

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

462 463
cc_proto_library(
    name = "cc_test_protos",
Jisi Liu's avatar
Jisi Liu committed
464
    srcs = LITE_TEST_PROTOS + TEST_PROTOS,
465
    include = "src",
466
    default_runtime = ":protobuf",
467
    protoc = ":protoc",
468
    deps = [":cc_wkt_protos"],
469 470 471 472 473 474 475
)

COMMON_TEST_SRCS = [
    # AUTOGEN(common_test_srcs)
    "src/google/protobuf/arena_test_util.cc",
    "src/google/protobuf/map_test_util.cc",
    "src/google/protobuf/test_util.cc",
476
    "src/google/protobuf/test_util.inc",
477 478 479 480
    "src/google/protobuf/testing/file.cc",
    "src/google/protobuf/testing/googletest.cc",
]

481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
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
496 497 498 499 500 501 502 503 504 505
cc_test(
    name = "win32_test",
    srcs = ["src/google/protobuf/stubs/io_win32_unittest.cc"],
    deps = [
        ":protobuf_lite",
        "//external:gtest_main",
    ],
    tags = ["manual", "windows"],
)

506 507
cc_test(
    name = "protobuf_test",
508
    srcs = COMMON_TEST_SRCS + [
509 510 511 512
        # 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
513
        "src/google/protobuf/compiler/annotation_test_util.cc",
514 515
        "src/google/protobuf/compiler/command_line_interface_unittest.cc",
        "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
Jisi Liu's avatar
Jisi Liu committed
516
        "src/google/protobuf/compiler/cpp/cpp_move_unittest.cc",
517 518
        "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
        "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
519
        "src/google/protobuf/compiler/cpp/cpp_unittest.inc",
520
        "src/google/protobuf/compiler/cpp/metadata_test.cc",
521
        "src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc",
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
        "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",
        "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",
544
        "src/google/protobuf/message_unittest.inc",
545 546
        "src/google/protobuf/no_field_presence_test.cc",
        "src/google/protobuf/preserve_unknown_enum_test.cc",
547
        "src/google/protobuf/proto3_arena_lite_unittest.cc",
Jisi Liu's avatar
Jisi Liu committed
548
        "src/google/protobuf/proto3_arena_unittest.cc",
549
        "src/google/protobuf/proto3_lite_unittest.cc",
550 551 552 553 554
        "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",
555
        "src/google/protobuf/stubs/int128_unittest.cc",
Jisi Liu's avatar
Jisi Liu committed
556
        "src/google/protobuf/stubs/io_win32_unittest.cc",
557 558 559 560 561 562 563 564 565 566
        "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",
567
        "src/google/protobuf/util/delimited_message_util_test.cc",
568
        "src/google/protobuf/util/field_comparator_test.cc",
569
        "src/google/protobuf/util/field_mask_util_test.cc",
570 571 572 573 574 575 576
        "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
577
        "src/google/protobuf/util/message_differencer_unittest.cc",
578
        "src/google/protobuf/util/time_util_test.cc",
579 580 581 582 583 584 585
        "src/google/protobuf/util/type_resolver_util_test.cc",
        "src/google/protobuf/well_known_types_unittest.cc",
        "src/google/protobuf/wire_format_unittest.cc",
    ],
    copts = COPTS,
    data = [
        ":test_plugin",
586 587
    ] + glob([
        "src/google/protobuf/**/*",
588 589 590
        # Files for csharp_bootstrap_unittest.cc.
        "conformance/**/*",
        "csharp/src/**/*",
591
    ]),
592 593 594 595 596
    includes = [
        "src/",
    ],
    linkopts = LINK_OPTS,
    deps = [
Jisi Liu's avatar
Jisi Liu committed
597
        ":cc_test_protos",
598 599 600 601 602
        ":protobuf",
        ":protoc_lib",
        "//external:gtest_main",
    ],
)
Jisi Liu's avatar
Jisi Liu committed
603 604 605 606

################################################################################
# Java support
################################################################################
607
internal_gen_well_known_protos_java(
Ming Zhao's avatar
Ming Zhao committed
608
    srcs = WELL_KNOWN_PROTOS,
Jisi Liu's avatar
Jisi Liu committed
609 610 611
)

java_library(
612
    name = "protobuf_java",
Jisi Liu's avatar
Jisi Liu committed
613
    srcs = glob([
Ming Zhao's avatar
Ming Zhao committed
614
        "java/core/src/main/java/com/google/protobuf/*.java",
Jisi Liu's avatar
Jisi Liu committed
615
    ]) + [
Ming Zhao's avatar
Ming Zhao committed
616
        ":gen_well_known_protos_java",
Jisi Liu's avatar
Jisi Liu committed
617
    ],
618 619 620 621
    javacopts = select({
       "//:jdk9": ["--add-modules=jdk.unsupported"],
       "//conditions:default": ["-source 7", "-target 7"],
    }),
Jisi Liu's avatar
Jisi Liu committed
622 623 624
    visibility = ["//visibility:public"],
)

625 626 627 628 629
java_library(
    name = "protobuf_java_util",
    srcs = glob([
        "java/util/src/main/java/com/google/protobuf/util/*.java",
    ]),
David Ostrovsky's avatar
David Ostrovsky committed
630
    javacopts = ["-source 7", "-target 7"],
631
    visibility = ["//visibility:public"],
632
    deps = [
633 634 635
        "protobuf_java",
        "//external:gson",
        "//external:guava",
636 637 638
    ],
)

Jisi Liu's avatar
Jisi Liu committed
639 640 641 642
################################################################################
# Python support
################################################################################

643
py_library(
Jisi Liu's avatar
Jisi Liu committed
644 645 646
    name = "python_srcs",
    srcs = glob(
        [
647
            "python/google/__init__.py",
Jisi Liu's avatar
Jisi Liu committed
648 649 650 651
            "python/google/protobuf/*.py",
            "python/google/protobuf/**/*.py",
        ],
        exclude = [
652 653
            "python/google/protobuf/__init__.py",
            "python/google/protobuf/**/__init__.py",
Jisi Liu's avatar
Jisi Liu committed
654 655 656 657
            "python/google/protobuf/internal/*_test.py",
            "python/google/protobuf/internal/test_util.py",
        ],
    ),
658
    imports = ["python"],
659
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
660 661
)

662
cc_binary(
663
    name = "python/google/protobuf/internal/_api_implementation.so",
664 665 666 667 668 669
    srcs = ["python/google/protobuf/internal/api_implementation.cc"],
    copts = COPTS + [
        "-DPYTHON_PROTO2_CPP_IMPL_V2",
    ],
    linkshared = 1,
    linkstatic = 1,
670 671
    deps = select({
        "//conditions:default": [],
672
        ":use_fast_cpp_protos": ["//external:python_headers"],
673
    }),
674 675 676
)

cc_binary(
677
    name = "python/google/protobuf/pyext/_message.so",
678 679 680 681 682 683
    srcs = glob([
        "python/google/protobuf/pyext/*.cc",
        "python/google/protobuf/pyext/*.h",
    ]),
    copts = COPTS + [
        "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
684 685 686 687
    ] + select({
        "//conditions:default": [],
        ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
    }),
688 689 690 691 692 693
    includes = [
        "python/",
        "src/",
    ],
    linkshared = 1,
    linkstatic = 1,
694 695
    deps = [
        ":protobuf",
696
        ":proto_api",
697 698
    ] + select({
        "//conditions:default": [],
699
        ":use_fast_cpp_protos": ["//external:python_headers"],
700 701 702 703 704 705 706 707
    }),
)

config_setting(
    name = "use_fast_cpp_protos",
    values = {
        "define": "use_fast_cpp_protos=true",
    },
708 709
)

710 711 712 713 714 715 716
config_setting(
    name = "allow_oversize_protos",
    values = {
        "define": "allow_oversize_protos=true",
    },
)

717 718 719 720 721 722 723 724 725
# 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",
726
    strip_prefix = "src",
727 728 729 730 731 732
)

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

Jisi Liu's avatar
Jisi Liu committed
733
py_proto_library(
734
    name = "protobuf_python",
735 736
    srcs = COPIED_WELL_KNOWN_PROTOS,
    include = "python",
737 738 739
    data = select({
        "//conditions:default": [],
        ":use_fast_cpp_protos": [
740 741
            ":python/google/protobuf/internal/_api_implementation.so",
            ":python/google/protobuf/pyext/_message.so",
742 743
        ],
    }),
744
    default_runtime = "",
745
    protoc = ":protoc",
746 747
    py_libs = [
        ":python_srcs",
748
        "//external:six",
749
    ],
750
    py_extra_srcs = glob(["python/**/__init__.py"]),
751
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
752 753 754
    visibility = ["//visibility:public"],
)

755 756 757 758 759 760 761 762 763
# 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",
764
    strip_prefix = "src",
765 766 767 768 769
)

# 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]
770

771 772
COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]

Jisi Liu's avatar
Jisi Liu committed
773 774
py_proto_library(
    name = "python_common_test_protos",
775 776
    srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
    include = "python",
777
    default_runtime = "",
778
    protoc = ":protoc",
779
    srcs_version = "PY2AND3",
780
    deps = [":protobuf_python"],
Jisi Liu's avatar
Jisi Liu committed
781 782 783 784
)

py_proto_library(
    name = "python_specific_test_protos",
785 786 787 788
    srcs = glob([
        "python/google/protobuf/internal/*.proto",
        "python/google/protobuf/internal/import_test_package/*.proto",
    ]),
Jisi Liu's avatar
Jisi Liu committed
789
    include = "python",
790
    default_runtime = ":protobuf_python",
791
    protoc = ":protoc",
792
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
793 794 795 796 797
    deps = [":python_common_test_protos"],
)

py_library(
    name = "python_tests",
798 799 800 801
    srcs = glob(
        [
            "python/google/protobuf/internal/*_test.py",
            "python/google/protobuf/internal/test_util.py",
802
            "python/google/protobuf/internal/import_test_package/__init__.py",
803 804 805
        ],
    ),
    imports = ["python"],
806
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
807
    deps = [
808
        ":protobuf_python",
809
        ":python_common_test_protos",
Jisi Liu's avatar
Jisi Liu committed
810 811 812 813 814
        ":python_specific_test_protos",
    ],
)

internal_protobuf_py_tests(
Jisi Liu's avatar
Jisi Liu committed
815
    name = "python_tests_batch",
816 817 818
    data = glob([
        "src/google/protobuf/**/*",
    ]),
Jisi Liu's avatar
Jisi Liu committed
819 820 821 822 823 824 825
    modules = [
        "descriptor_database_test",
        "descriptor_pool_test",
        "descriptor_test",
        "generator_test",
        "json_format_test",
        "message_factory_test",
826
        "message_test",
Jisi Liu's avatar
Jisi Liu committed
827
        "proto_builder_test",
828
        "reflection_test",
Jisi Liu's avatar
Jisi Liu committed
829 830 831
        "service_reflection_test",
        "symbol_database_test",
        "text_encoding_test",
832
        "text_format_test",
Jisi Liu's avatar
Jisi Liu committed
833 834 835 836 837
        "unknown_fields_test",
        "wire_format_test",
    ],
    deps = [":python_tests"],
)
838

839 840 841 842 843 844
cc_library(
    name = "proto_api",
    hdrs = ["python/google/protobuf/proto_api.h"],
    deps = [
        "//external:python_headers",
    ],
845
    visibility = ["//visibility:public"],
846 847
)

848
proto_lang_toolchain(
849 850 851 852
    name = "cc_toolchain",
    command_line = "--cpp_out=$(OUT)",
    runtime = ":protobuf",
    visibility = ["//visibility:public"],
853
    blacklisted_protos = [":_internal_wkt_protos_genrule"],
854
)
855 856 857 858 859 860 861

proto_lang_toolchain(
    name = "java_toolchain",
    command_line = "--java_out=$(OUT)",
    runtime = ":protobuf_java",
    visibility = ["//visibility:public"],
)
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942

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",
]

OBJC_PRIVATE_HDRS = [
    "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",
]

OBJC_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",
]

objc_library(
    name = "objectivec",
    hdrs = OBJC_HDRS + OBJC_PRIVATE_HDRS,
    includes = [
        "objectivec",
    ],
    non_arc_srcs = OBJC_SRCS,
    visibility = ["//visibility:public"],
)
943 944 945 946 947 948 949 950 951 952 953 954 955 956

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

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

proto_library(
    name = "generated_protos_proto",
957 958 959 960
    srcs = [
        "unittest_gen.proto",
        "src/google/protobuf/unittest_import_public.proto",
    ],
961 962 963 964 965 966 967 968 969 970 971
)

py_proto_library(
    name = "generated_protos_py",
    srcs = [
        "unittest_gen.proto",
        "src/google/protobuf/unittest_import_public.proto",
    ],
    default_runtime = "",
    protoc = ":protoc",
)