BUILD 14.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

donghuixu's avatar
donghuixu committed
16 17 18 19 20 21
licenses(["notice"])  # Apache v2

exports_files(["LICENSE"])

load(":bazel/brpc.bzl", "brpc_proto_library")

donghuixu's avatar
donghuixu committed
22
config_setting(
23 24 25 26 27
    name = "with_glog",
    define_values = {"with_glog": "true"},
    visibility = ["//visibility:public"],
)

28 29 30 31 32 33
config_setting(
    name = "with_mesalink",
    define_values = {"with_mesalink": "true"},
    visibility = ["//visibility:public"],
)

wangxuefeng's avatar
wangxuefeng committed
34 35 36 37 38 39
config_setting(
    name = "with_thrift",
    define_values = {"with_thrift": "true"},
    visibility = ["//visibility:public"],
)

40 41 42
config_setting(
    name = "unittest",
    define_values = {"unittest": "true"},
donghuixu's avatar
donghuixu committed
43
)
donghuixu's avatar
donghuixu committed
44

45 46 47 48 49 50 51 52 53 54 55 56
config_setting(
    name = "darwin",
    values = {"cpu": "darwin"},
    visibility = ["//visibility:public"],
)

config_setting(
    name = "linux",
    values = {"cpu": "linux"},
    visibility = ["//visibility:public"],
)

donghuixu's avatar
donghuixu committed
57 58 59 60 61 62 63 64 65 66
COPTS = [
    "-DBTHREAD_USE_FAST_PTHREAD_MUTEX",
    "-D__const__=",
    "-D_GNU_SOURCE",
    "-DUSE_SYMBOLIZE",
    "-DNO_TCMALLOC",
    "-D__STDC_FORMAT_MACROS",
    "-D__STDC_LIMIT_MACROS",
    "-D__STDC_CONSTANT_MACROS",
    "-DGFLAGS_NS=google",
donghuixu's avatar
donghuixu committed
67
] + select({
68
    ":with_glog": ["-DBRPC_WITH_GLOG=1"],
donghuixu's avatar
donghuixu committed
69
    "//conditions:default": ["-DBRPC_WITH_GLOG=0"],
70 71 72
}) + select({
    ":with_mesalink": ["-DUSE_MESALINK"],
    "//conditions:default": [""],
wangxuefeng's avatar
wangxuefeng committed
73 74 75
}) + select({
    ":with_thrift": ["-DENABLE_THRIFT_FRAMED_PROTOCOL=1"],
    "//conditions:default": [""],
donghuixu's avatar
donghuixu committed
76
})
donghuixu's avatar
donghuixu committed
77

78 79 80
LINKOPTS = [
    "-lpthread",
    "-ldl",
81
    "-lz",
zhenren's avatar
zhenren committed
82 83
    "-lssl",
    "-lcrypto",
84
] + select({
zhenren's avatar
zhenren committed
85 86 87 88 89 90 91 92 93 94 95 96
    ":darwin": [
        "-framework CoreFoundation",
        "-framework CoreGraphics",
        "-framework CoreData",
        "-framework CoreText",
        "-framework Security",
        "-framework Foundation",
        "-Wl,-U,_MallocExtension_ReleaseFreeMemory",
        "-Wl,-U,_ProfilerStart",
        "-Wl,-U,_ProfilerStop",
        "-Wl,-U,_RegisterThriftProtocol",
    ],
97 98 99
    "//conditions:default": [
      "-lrt",
    ],
100 101 102 103 104
}) + select({
    ":with_mesalink": [
        "-lmesalink",
    ],
    "//conditions:default": [],
wangxuefeng's avatar
wangxuefeng committed
105 106 107 108 109 110
}) + select({
    ":with_thrift": [
        "-lthriftnb",
        "-levent",
        "-lthrift"],
    "//conditions:default": [],
111
})
112

donghuixu's avatar
donghuixu committed
113 114 115 116 117
genrule(
    name = "config_h",
    outs = [
        "src/butil/config.h",
    ],
donghuixu's avatar
donghuixu committed
118
    cmd = """cat << EOF  >$@""" + """
donghuixu's avatar
donghuixu committed
119 120 121 122 123 124 125
// This file is auto-generated.
#ifndef  BUTIL_CONFIG_H
#define  BUTIL_CONFIG_H

#ifdef BRPC_WITH_GLOG
#undef BRPC_WITH_GLOG
#endif
donghuixu's avatar
donghuixu committed
126
#define BRPC_WITH_GLOG """ + select({
127
    ":with_glog": "1",
donghuixu's avatar
donghuixu committed
128 129 130
    "//conditions:default": "0",
}) +
"""
donghuixu's avatar
donghuixu committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
#endif  // BUTIL_CONFIG_H
EOF
    """
)

BUTIL_SRCS = [
    "src/butil/third_party/dmg_fp/g_fmt.cc",
    "src/butil/third_party/dmg_fp/dtoa_wrapper.cc",
    "src/butil/third_party/dynamic_annotations/dynamic_annotations.c",
    "src/butil/third_party/icu/icu_utf.cc",
    "src/butil/third_party/superfasthash/superfasthash.c",
    "src/butil/third_party/modp_b64/modp_b64.cc",
    "src/butil/third_party/symbolize/demangle.cc",
    "src/butil/third_party/symbolize/symbolize.cc",
    "src/butil/third_party/snappy/snappy-sinksource.cc",
    "src/butil/third_party/snappy/snappy-stubs-internal.cc",
    "src/butil/third_party/snappy/snappy.cc",
    "src/butil/third_party/murmurhash3/murmurhash3.cpp",
    "src/butil/arena.cpp",
    "src/butil/at_exit.cc",
    "src/butil/atomicops_internals_x86_gcc.cc",
    "src/butil/base64.cc",
    "src/butil/big_endian.cc",
    "src/butil/cpu.cc",
    "src/butil/debug/alias.cc",
    "src/butil/debug/asan_invalid_access.cc",
    "src/butil/debug/crash_logging.cc",
    "src/butil/debug/debugger.cc",
    "src/butil/debug/debugger_posix.cc",
    "src/butil/debug/dump_without_crashing.cc",
    "src/butil/debug/proc_maps_linux.cc",
    "src/butil/debug/stack_trace.cc",
    "src/butil/debug/stack_trace_posix.cc",
    "src/butil/environment.cc",
    "src/butil/files/file.cc",
    "src/butil/files/file_posix.cc",
    "src/butil/files/file_enumerator.cc",
    "src/butil/files/file_enumerator_posix.cc",
    "src/butil/files/file_path.cc",
    "src/butil/files/file_path_constants.cc",
    "src/butil/files/memory_mapped_file.cc",
    "src/butil/files/memory_mapped_file_posix.cc",
    "src/butil/files/scoped_file.cc",
    "src/butil/files/scoped_temp_dir.cc",
    "src/butil/file_util.cc",
    "src/butil/file_util_posix.cc",
    "src/butil/guid.cc",
    "src/butil/guid_posix.cc",
    "src/butil/hash.cc",
    "src/butil/lazy_instance.cc",
    "src/butil/location.cc",
    "src/butil/memory/aligned_memory.cc",
    "src/butil/memory/ref_counted.cc",
    "src/butil/memory/ref_counted_memory.cc",
    "src/butil/memory/singleton.cc",
    "src/butil/memory/weak_ptr.cc",
    "src/butil/posix/file_descriptor_shuffle.cc",
    "src/butil/posix/global_descriptors.cc",
189
    "src/butil/process_util.cc",
donghuixu's avatar
donghuixu committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
    "src/butil/rand_util.cc",
    "src/butil/rand_util_posix.cc",
    "src/butil/fast_rand.cpp",
    "src/butil/safe_strerror_posix.cc",
    "src/butil/sha1_portable.cc",
    "src/butil/strings/latin1_string_conversions.cc",
    "src/butil/strings/nullable_string16.cc",
    "src/butil/strings/safe_sprintf.cc",
    "src/butil/strings/string16.cc",
    "src/butil/strings/string_number_conversions.cc",
    "src/butil/strings/string_split.cc",
    "src/butil/strings/string_piece.cc",
    "src/butil/strings/string_util.cc",
    "src/butil/strings/string_util_constants.cc",
    "src/butil/strings/stringprintf.cc",
    "src/butil/strings/utf_offset_string_conversions.cc",
    "src/butil/strings/utf_string_conversion_utils.cc",
    "src/butil/strings/utf_string_conversions.cc",
    "src/butil/synchronization/cancellation_flag.cc",
    "src/butil/synchronization/condition_variable_posix.cc",
    "src/butil/synchronization/waitable_event_posix.cc",
    "src/butil/threading/non_thread_safe_impl.cc",
    "src/butil/threading/platform_thread_posix.cc",
    "src/butil/threading/simple_thread.cc",
    "src/butil/threading/thread_checker_impl.cc",
    "src/butil/threading/thread_collision_warner.cc",
    "src/butil/threading/thread_id_name_manager.cc",
    "src/butil/threading/thread_local_posix.cc",
    "src/butil/threading/thread_local_storage.cc",
    "src/butil/threading/thread_local_storage_posix.cc",
    "src/butil/threading/thread_restrictions.cc",
    "src/butil/threading/watchdog.cc",
    "src/butil/time/clock.cc",
    "src/butil/time/default_clock.cc",
    "src/butil/time/default_tick_clock.cc",
    "src/butil/time/tick_clock.cc",
    "src/butil/time/time.cc",
    "src/butil/time/time_posix.cc",
    "src/butil/version.cc",
    "src/butil/logging.cc",
    "src/butil/class_name.cpp",
    "src/butil/errno.cpp",
    "src/butil/find_cstr.cpp",
    "src/butil/status.cpp",
    "src/butil/string_printf.cpp",
    "src/butil/thread_local.cpp",
    "src/butil/unix_socket.cpp",
    "src/butil/endpoint.cpp",
    "src/butil/fd_utility.cpp",
    "src/butil/files/temp_file.cpp",
    "src/butil/files/file_watcher.cpp",
    "src/butil/time.cpp",
    "src/butil/zero_copy_stream_as_streambuf.cpp",
    "src/butil/crc32c.cc",
    "src/butil/containers/case_ignored_flat_map.cpp",
    "src/butil/iobuf.cpp",
246
    "src/butil/binary_printer.cpp",
247
    "src/butil/recordio.cc",
donghuixu's avatar
donghuixu committed
248
    "src/butil/popen.cpp",
249 250 251 252 253 254 255 256 257 258 259
] + select({
        ":darwin": [
            "src/butil/time/time_mac.cc",
            "src/butil/mac/scoped_mach_port.cc",
        ],
        "//conditions:default": [
            "src/butil/file_util_linux.cc",
            "src/butil/threading/platform_thread_linux.cc",
            "src/butil/strings/sys_string_conversions_posix.cc",
        ],
})
donghuixu's avatar
donghuixu committed
260

261 262 263 264 265 266
objc_library(
    name = "macos_lib",
    hdrs = [":config_h",
        "src/butil/atomicops.h",
        "src/butil/atomicops_internals_atomicword_compat.h",
        "src/butil/atomicops_internals_mac.h",
267
        "src/butil/base_export.h",
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
        "src/butil/basictypes.h",
        "src/butil/build_config.h",
        "src/butil/compat.h",
        "src/butil/compiler_specific.h",
        "src/butil/containers/hash_tables.h",
        "src/butil/debug/debugger.h",
        "src/butil/debug/leak_annotations.h",
        "src/butil/file_util.h",
        "src/butil/file_descriptor_posix.h",
        "src/butil/files/file_path.h",
        "src/butil/files/file.h",
        "src/butil/files/scoped_file.h",
        "src/butil/lazy_instance.h",
        "src/butil/logging.h",
        "src/butil/mac/bundle_locations.h",
        "src/butil/mac/foundation_util.h",
        "src/butil/mac/scoped_cftyperef.h",
        "src/butil/mac/scoped_typeref.h",
        "src/butil/macros.h",
        "src/butil/memory/aligned_memory.h",
        "src/butil/memory/scoped_policy.h",
        "src/butil/memory/scoped_ptr.h",
        "src/butil/move.h",
        "src/butil/port.h",
        "src/butil/posix/eintr_wrapper.h",
        "src/butil/scoped_generic.h",
        "src/butil/strings/string16.h",
        "src/butil/strings/string_piece.h",
        "src/butil/strings/string_util.h",
        "src/butil/strings/string_util_posix.h",
        "src/butil/strings/sys_string_conversions.h",
        "src/butil/synchronization/lock.h",
        "src/butil/time/time.h",
301
        "src/butil/time.h",
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
        "src/butil/third_party/dynamic_annotations/dynamic_annotations.h",
        "src/butil/threading/platform_thread.h",
        "src/butil/threading/thread_restrictions.h",
        "src/butil/threading/thread_id_name_manager.h",
        "src/butil/type_traits.h",
    ],
    non_arc_srcs = [
        "src/butil/mac/bundle_locations.mm",
        "src/butil/mac/foundation_util.mm",
        "src/butil/file_util_mac.mm",
        "src/butil/threading/platform_thread_mac.mm",
        "src/butil/strings/sys_string_conversions_mac.mm",
    ],
    deps = [
        "@com_github_gflags_gflags//:gflags",
    ] + select({
        ":with_glog": ["@com_github_google_glog//:glog"],
        "//conditions:default": [],
    }),
    includes = ["src/"],
    enable_modules = True,
    tags = ["manual"],
)
donghuixu's avatar
donghuixu committed
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342

cc_library(
    name = "butil",
    srcs = BUTIL_SRCS,
    hdrs = glob([
        "src/butil/*.h",
        "src/butil/*.hpp",
        "src/butil/**/*.h",
        "src/butil/**/*.hpp",
        "src/butil/**/**/*.h",
        "src/butil/**/**/*.hpp",
        "src/butil/**/**/**/*.h",
        "src/butil/**/**/**/*.hpp",
        "src/butil/third_party/dmg_fp/dtoa.cc",
    ]) + [":config_h"],
    deps = [
        "@com_google_protobuf//:protobuf",
        "@com_github_gflags_gflags//:gflags",
343 344
    ] + select({
        ":with_glog": ["@com_github_google_glog//:glog"],
345
        ":darwin": [":macos_lib"],
346 347
        "//conditions:default": [],
    }),
donghuixu's avatar
donghuixu committed
348 349 350
    includes = [
        "src/",
    ],
351 352 353 354 355 356 357
    copts = COPTS + select({
        ":unittest": [
            "-DBVAR_NOT_LINK_DEFAULT_VARIABLES",
            "-DUNIT_TEST",
        ],
        "//conditions:default": [],
    }),
358
    linkopts = LINKOPTS,
359
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
360 361 362 363 364 365 366
)

cc_library(
    name = "bvar",
    srcs = glob([
        "src/bvar/*.cpp",
        "src/bvar/detail/*.cpp",
367 368 369 370 371 372 373
    ],
    exclude = [
        "src/bvar/default_variables.cpp",
    ]) + select({
        ":unittest": [],
        "//conditions:default": ["src/bvar/default_variables.cpp"],
    }),
donghuixu's avatar
donghuixu committed
374 375 376 377 378 379 380 381 382 383 384
    hdrs = glob([
        "src/bvar/*.h",
        "src/bvar/utils/*.h",
        "src/bvar/detail/*.h",
    ]),
    includes = [
        "src/",
    ],
    deps = [
        ":butil",
    ],
385 386 387 388 389 390 391
    copts = COPTS + select({
        ":unittest": [
            "-DBVAR_NOT_LINK_DEFAULT_VARIABLES",
            "-DUNIT_TEST",
        ],
        "//conditions:default": [],
    }),
392
    linkopts = LINKOPTS,
393
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
)

cc_library(
    name = "bthread",
    srcs = glob([
        "src/bthread/*.cpp",
    ]),
    hdrs = glob([
        "src/bthread/*.h",
        "src/bthread/*.list",
    ]),
    includes = [
        "src/"
    ],
    deps = [
        ":butil",
        ":bvar",
    ],
    copts = COPTS,
413
    linkopts = LINKOPTS,
414
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
)

cc_library(
    name = "json2pb",
    srcs = glob([
        "src/json2pb/*.cpp",
    ]),
    hdrs = glob([
        "src/json2pb/*.h",
    ]),
    includes = [
        "src/",
    ],
    deps = [
        ":butil",
    ],
    copts = COPTS,
432
    linkopts = LINKOPTS,
433
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
434 435 436 437
)

cc_library(
    name = "mcpack2pb",
438 439 440 441 442 443
    srcs = [
        "src/mcpack2pb/field_type.cpp",
        "src/mcpack2pb/mcpack2pb.cpp",
        "src/mcpack2pb/parser.cpp",
        "src/mcpack2pb/serializer.cpp",
    ],
donghuixu's avatar
donghuixu committed
444 445 446 447 448 449 450 451
    hdrs = glob([
        "src/mcpack2pb/*.h",
    ]),
    includes = [
        "src/",
    ],
    deps = [
        ":butil",
452
        ":cc_brpc_idl_options_proto",
453
        "@com_google_protobuf//:protoc_lib",
donghuixu's avatar
donghuixu committed
454 455
    ],
    copts = COPTS,
456
    linkopts = LINKOPTS,
457
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
458 459
)

460 461 462 463 464 465 466 467 468 469 470
brpc_proto_library(
    name = "cc_brpc_idl_options_proto",
    srcs = [
        "src/idl_options.proto",
    ],
    deps = [
        "@com_google_protobuf//:cc_wkt_protos"
    ],
    visibility = ["//visibility:public"],
)

donghuixu's avatar
donghuixu committed
471 472 473 474 475 476 477 478
brpc_proto_library(
    name = "cc_brpc_internal_proto",
    srcs = glob([
        "src/brpc/*.proto",
        "src/brpc/policy/*.proto",
    ]),
    include = "src/",
    deps = [
479
        ":cc_brpc_idl_options_proto",
donghuixu's avatar
donghuixu committed
480 481
        "@com_google_protobuf//:cc_wkt_protos"
    ],
482
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
483 484 485 486 487 488 489
)

cc_library(
    name = "brpc",
    srcs = glob([
        "src/brpc/*.cpp",
        "src/brpc/**/*.cpp",
wangxuefeng's avatar
wangxuefeng committed
490 491 492 493 494 495 496 497 498 499 500
    ],
    exclude = [
        "src/brpc/thrift_service.cpp",
        "src/brpc/thrift_message.cpp",
        "src/brpc/policy/thrift_protocol.cpp",
    ]) + select({
        ":with_thrift" : glob([
            "src/brpc/thrift*.cpp",
            "src/brpc/**/thrift*.cpp"]),
        "//conditions:default" : [],
    }),
donghuixu's avatar
donghuixu committed
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
    hdrs = glob([
        "src/brpc/*.h",
        "src/brpc/**/*.h"
    ]),
    includes = [
        "src/",
    ],
    deps = [
        ":butil",
        ":bthread",
        ":bvar",
        ":json2pb",
        ":mcpack2pb",
        ":cc_brpc_internal_proto",
        "@com_github_google_leveldb//:leveldb",
    ],
    copts = COPTS,
518
    linkopts = LINKOPTS,
donghuixu's avatar
donghuixu committed
519 520 521
    visibility = ["//visibility:public"],
)

522 523 524 525 526 527 528 529 530 531 532 533 534 535
cc_binary(
    name = "protoc-gen-mcpack",
    srcs = [
        "src/mcpack2pb/generator.cpp",
    ],
    deps = [
        ":cc_brpc_idl_options_proto",
        ":brpc",
    ],
    copts = COPTS,
    linkopts = LINKOPTS,
    visibility = ["//visibility:public"],
)