BUILD 13.8 KB
Newer Older
donghuixu's avatar
donghuixu committed
1 2 3 4 5 6
licenses(["notice"])  # Apache v2

exports_files(["LICENSE"])

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

donghuixu's avatar
donghuixu committed
7
config_setting(
8 9 10 11 12
    name = "with_glog",
    define_values = {"with_glog": "true"},
    visibility = ["//visibility:public"],
)

wangxuefeng's avatar
wangxuefeng committed
13 14 15 16 17 18
config_setting(
    name = "with_thrift",
    define_values = {"with_thrift": "true"},
    visibility = ["//visibility:public"],
)

19 20 21
config_setting(
    name = "unittest",
    define_values = {"unittest": "true"},
donghuixu's avatar
donghuixu committed
22
)
donghuixu's avatar
donghuixu committed
23

24 25 26 27 28 29 30 31 32 33 34 35
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
36 37 38 39 40 41 42 43 44 45
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
46
] + select({
47
    ":with_glog": ["-DBRPC_WITH_GLOG=1"],
donghuixu's avatar
donghuixu committed
48
    "//conditions:default": ["-DBRPC_WITH_GLOG=0"],
wangxuefeng's avatar
wangxuefeng committed
49 50 51
}) + select({
    ":with_thrift": ["-DENABLE_THRIFT_FRAMED_PROTOCOL=1"],
    "//conditions:default": [""],
donghuixu's avatar
donghuixu committed
52
})
donghuixu's avatar
donghuixu committed
53

54 55 56
LINKOPTS = [
    "-lpthread",
    "-ldl",
zhenren's avatar
zhenren committed
57 58 59
    "-lz", 
    "-lssl",
    "-lcrypto",
60
] + select({
zhenren's avatar
zhenren committed
61 62 63 64 65 66 67 68 69 70 71 72
    ":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",
    ],
73 74 75
    "//conditions:default": [
      "-lrt",
    ],
wangxuefeng's avatar
wangxuefeng committed
76 77 78 79 80 81
}) + select({
    ":with_thrift": [
        "-lthriftnb",
        "-levent",
        "-lthrift"],
    "//conditions:default": [],
82
})
83

donghuixu's avatar
donghuixu committed
84 85 86 87 88
genrule(
    name = "config_h",
    outs = [
        "src/butil/config.h",
    ],
donghuixu's avatar
donghuixu committed
89
    cmd = """cat << EOF  >$@""" + """
donghuixu's avatar
donghuixu committed
90 91 92 93 94 95 96
// 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
97
#define BRPC_WITH_GLOG """ + select({
98
    ":with_glog": "1",
donghuixu's avatar
donghuixu committed
99 100 101
    "//conditions:default": "0",
}) +
"""
donghuixu's avatar
donghuixu committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 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
#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/nspr/prtime.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/md5.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",
162
    "src/butil/process_util.cc",
donghuixu's avatar
donghuixu committed
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 189 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
    "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",
219
    "src/butil/binary_printer.cpp",
donghuixu's avatar
donghuixu committed
220
    "src/butil/popen.cpp",
221 222 223 224 225 226 227 228 229 230 231
] + 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
232

233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 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
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",
        "src/butil/base_export.h",        
        "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",
        "src/butil/time.h",        
        "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
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314

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",
315 316
    ] + select({
        ":with_glog": ["@com_github_google_glog//:glog"],
317
        ":darwin": [":macos_lib"],
318 319
        "//conditions:default": [],
    }),
donghuixu's avatar
donghuixu committed
320 321 322
    includes = [
        "src/",
    ],
323 324 325 326 327 328 329
    copts = COPTS + select({
        ":unittest": [
            "-DBVAR_NOT_LINK_DEFAULT_VARIABLES",
            "-DUNIT_TEST",
        ],
        "//conditions:default": [],
    }),
330
    linkopts = LINKOPTS,
331
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
332 333 334 335 336 337 338
)

cc_library(
    name = "bvar",
    srcs = glob([
        "src/bvar/*.cpp",
        "src/bvar/detail/*.cpp",
339 340 341 342 343 344 345
    ],
    exclude = [
        "src/bvar/default_variables.cpp",
    ]) + select({
        ":unittest": [],
        "//conditions:default": ["src/bvar/default_variables.cpp"],
    }),
donghuixu's avatar
donghuixu committed
346 347 348 349 350 351 352 353 354 355 356
    hdrs = glob([
        "src/bvar/*.h",
        "src/bvar/utils/*.h",
        "src/bvar/detail/*.h",
    ]),
    includes = [
        "src/",
    ],
    deps = [
        ":butil",
    ],
357 358 359 360 361 362 363
    copts = COPTS + select({
        ":unittest": [
            "-DBVAR_NOT_LINK_DEFAULT_VARIABLES",
            "-DUNIT_TEST",
        ],
        "//conditions:default": [],
    }),
364
    linkopts = LINKOPTS,
365
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
)

cc_library(
    name = "bthread",
    srcs = glob([
        "src/bthread/*.cpp",
    ]),
    hdrs = glob([
        "src/bthread/*.h",
        "src/bthread/*.list",
    ]),
    includes = [
        "src/"
    ],
    deps = [
        ":butil",
        ":bvar",
    ],
    copts = COPTS,
385
    linkopts = LINKOPTS,
386
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
)

cc_library(
    name = "json2pb",
    srcs = glob([
        "src/json2pb/*.cpp",
    ]),
    hdrs = glob([
        "src/json2pb/*.h",
    ]),
    includes = [
        "src/",
    ],
    deps = [
        ":butil",
    ],
    copts = COPTS,
404
    linkopts = LINKOPTS,
405
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
406 407 408 409
)

cc_library(
    name = "mcpack2pb",
410 411 412 413 414 415
    srcs = [
        "src/mcpack2pb/field_type.cpp",
        "src/mcpack2pb/mcpack2pb.cpp",
        "src/mcpack2pb/parser.cpp",
        "src/mcpack2pb/serializer.cpp",
    ],
donghuixu's avatar
donghuixu committed
416 417 418 419 420 421 422 423
    hdrs = glob([
        "src/mcpack2pb/*.h",
    ]),
    includes = [
        "src/",
    ],
    deps = [
        ":butil",
424
        ":cc_brpc_idl_options_proto",
425
        "@com_google_protobuf//:protoc_lib",
donghuixu's avatar
donghuixu committed
426 427
    ],
    copts = COPTS,
428
    linkopts = LINKOPTS,
429
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
430 431
)

432 433 434 435 436 437 438 439 440 441 442
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
443 444 445 446 447 448 449 450
brpc_proto_library(
    name = "cc_brpc_internal_proto",
    srcs = glob([
        "src/brpc/*.proto",
        "src/brpc/policy/*.proto",
    ]),
    include = "src/",
    deps = [
451
        ":cc_brpc_idl_options_proto",
donghuixu's avatar
donghuixu committed
452 453
        "@com_google_protobuf//:cc_wkt_protos"
    ],
454
    visibility = ["//visibility:public"],
donghuixu's avatar
donghuixu committed
455 456 457 458 459 460 461
)

cc_library(
    name = "brpc",
    srcs = glob([
        "src/brpc/*.cpp",
        "src/brpc/**/*.cpp",
wangxuefeng's avatar
wangxuefeng committed
462 463 464 465 466 467 468 469 470 471 472
    ],
    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
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
    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,
490
    linkopts = LINKOPTS,
donghuixu's avatar
donghuixu committed
491 492 493
    visibility = ["//visibility:public"],
)

494 495 496 497 498 499 500 501 502 503 504 505 506 507
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"],
)