Unverified Commit 1acd8666 authored by Ge Jun's avatar Ge Jun Committed by GitHub

Merge pull request #145 from dhx1989/master

support bazel build
parents e89dbb80 a30f552c
......@@ -9,6 +9,11 @@ compiler:
env:
- PURPOSE=compile
- PURPOSE=unittest
- PURPOSE=compile-with-bazel
before_install:
- wget --no-clobber https://github.com/bazelbuild/bazel/releases/download/0.8.1/bazel_0.8.1-linux-x86_64.deb
- sudo dpkg -i bazel_0.8.1-linux-x86_64.deb
install:
- sudo apt-get install -qq realpath libgflags-dev libprotobuf-dev libprotoc-dev protobuf-compiler libleveldb-dev libgoogle-perftools-dev
......
This diff is collapsed.
workspace(name = "com_github_brpc_brpc")
load("//:bazel/workspace.bzl", "brpc_workspace")
brpc_workspace()
load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library")
def brpc_proto_library(name, srcs, deps=[], include=None, visibility=None, testonly=0):
native.filegroup(name=name + "_proto_srcs",
srcs=srcs,
visibility=visibility,)
cc_proto_library(name=name,
srcs=srcs,
deps=deps,
cc_libs=["@com_google_protobuf//:protobuf"],
include=include,
protoc="@com_google_protobuf//:protoc",
default_runtime="@com_google_protobuf//:protobuf",
testonly=testonly,
visibility=visibility,)
# brpc external dependencies
def brpc_workspace():
native.http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-b04e5cba356212e4e8c66c61bbe0c3a20537c5b9",
url = "https://github.com/google/protobuf/archive/b04e5cba356212e4e8c66c61bbe0c3a20537c5b9.tar.gz",
)
native.http_archive(
name = "com_github_gflags_gflags",
strip_prefix = "gflags-46f73f88b18aee341538c0dfc22b1710a6abedef",
url = "https://github.com/gflags/gflags/archive/46f73f88b18aee341538c0dfc22b1710a6abedef.tar.gz",
)
native.bind(
name = "gflags",
actual = "@com_github_gflags_gflags//:gflags",
)
native.new_http_archive(
name = "com_github_google_leveldb",
build_file = str(Label("//:leveldb.BUILD")),
strip_prefix = "leveldb-a53934a3ae1244679f812d998a4f16f2c7f309a6",
url = "https://github.com/google/leveldb/archive/a53934a3ae1244679f812d998a4f16f2c7f309a6.tar.gz"
)
native.new_http_archive(
name = "com_github_google_glog",
build_file = str(Label("//:glog.BUILD")),
strip_prefix = "glog-a6a166db069520dbbd653c97c2e5b12e08a8bb26",
url = "https://github.com/google/glog/archive/a6a166db069520dbbd653c97c2e5b12e08a8bb26.tar.gz"
)
native.http_archive(
name = "com_google_googletest",
strip_prefix = "googletest-0fe96607d85cf3a25ac40da369db62bbee2939a5",
url = "https://github.com/google/googletest/archive/0fe96607d85cf3a25ac40da369db62bbee2939a5.tar.gz",
)
......@@ -10,7 +10,26 @@ if [ -z "$CC" ]; then
echo "CC must be set"
exit 1
fi
runcmd(){
eval $@
[[ $? != 0 ]] && {
exit 1
}
return 0
}
echo "build combination: PURPOSE=$PURPOSE CXX=$CXX CC=$CC"
if [ "$PURPOSE" = "compile-with-bazel" ]; then
runcmd "bazel build -j 12 -c opt --copt -DHAVE_ZLIB=1 //..."
runcmd "bazel test -j 12 -c opt --copt -DHAVE_ZLIB=1 --define=unittest=true //..."
# Build with glog
runcmd "bazel build -j 12 -c opt --copt -DHAVE_ZLIB=1 --define=with_glog=true //..."
runcmd "bazel test -j 12 -c opt --copt -DHAVE_ZLIB=1 --define=with_glog=true --define=unittest=true //..."
exit 0
fi
# The default env in travis-ci is Ubuntu.
if ! sh config_brpc.sh --headers=/usr/include --libs=/usr/lib --nodebugsymbols --cxx=$CXX --cc=$CC; then
echo "Fail to configure brpc"
......
COPTS = [
"-D__STDC_FORMAT_MACROS",
"-DBTHREAD_USE_FAST_PTHREAD_MUTEX",
"-D__const__=",
"-D_GNU_SOURCE",
"-DUSE_SYMBOLIZE",
"-DNO_TCMALLOC",
"-D__STDC_LIMIT_MACROS",
"-D__STDC_CONSTANT_MACROS",
"-fPIC",
"-Wno-unused-parameter",
"-fno-omit-frame-pointer",
"-DGFLAGS_NS=google",
] + select({
"//:with_glog": ["-DBRPC_WITH_GLOG=1"],
"//conditions:default": ["-DBRPC_WITH_GLOG=0"],
})
proto_library(
name = "echo_c++_proto",
srcs = [
"echo_c++/echo.proto",
],
)
cc_proto_library(
name = "cc_echo_c++_proto",
deps = [
":echo_c++_proto",
],
)
cc_binary(
name = "echo_c++_server",
srcs = [
"echo_c++/server.cpp",
],
includes = [
"echo_c++",
],
deps = [
":cc_echo_c++_proto",
"//:brpc",
],
copts = COPTS,
)
cc_binary(
name = "echo_c++_client",
srcs = [
"echo_c++/client.cpp",
],
includes = [
"echo_c++",
],
deps = [
":cc_echo_c++_proto",
"//:brpc",
],
copts = COPTS,
)
licenses(["notice"])
cc_library(
name = "glog",
srcs = [
"src/base/commandlineflags.h",
"src/base/googleinit.h",
"src/demangle.cc",
"src/logging.cc",
"src/raw_logging.cc",
"src/symbolize.cc",
"src/utilities.cc",
"src/vlog_is_on.cc",
],
hdrs = [
"raw_logging_h",
"src/base/mutex.h",
"src/demangle.h",
"src/symbolize.h",
"src/utilities.h",
"src/glog/log_severity.h",
":config_h",
":logging_h",
":stl_logging_h",
":vlog_is_on_h",
],
copts = [
# Disable warnings that exists in glog
"-Wno-sign-compare",
"-Wno-unused-local-typedefs",
# Inject google namespace as "google"
"-D_START_GOOGLE_NAMESPACE_='namespace google {'",
"-D_END_GOOGLE_NAMESPACE_='}'",
"-DGOOGLE_NAMESPACE='google'",
# Allows src/base/mutex.h to include pthread.h.
"-DHAVE_PTHREAD",
# Allows src/logging.cc to determine the host name.
"-DHAVE_SYS_UTSNAME_H",
# System header files enabler for src/utilities.cc
# Enable system calls from syscall.h
"-DHAVE_SYS_SYSCALL_H",
# Enable system calls from sys/time.h
"-DHAVE_SYS_TIME_H",
"-DHAVE_STDINT_H",
"-DHAVE_STRING_H",
# For logging.cc
"-DHAVE_PREAD",
"-DHAVE_FCNTL",
"-DHAVE_SYS_TYPES_H",
# Allows syslog support
"-DHAVE_SYSLOG_H",
# GFlags
"-isystem $(GENDIR)/external/com_github_gflags_gflags/",
"-DHAVE_LIB_GFLAGS",
# Necessary for creating soft links of log files
"-DHAVE_UNISTD_H",
],
includes = [
".",
"src",
],
visibility = ["//visibility:public"],
deps = [
"//external:gflags",
],
)
# Below are the generation rules that generates the necessary header
# files for glog. Originally they are generated by CMAKE
# configure_file() command, which replaces certain template
# placeholders in the .in files with provided values.
# gen_sh is a bash script that provides the values for generated
# header files. Under the hood it is just a wrapper over sed.
genrule(
name = "gen_sh",
outs = [
"gen.sh",
],
cmd = """
cat > $@ <<"EOF"
#! /bin/sh
sed -e 's/@ac_cv_have_unistd_h@/1/g' \
-e 's/@ac_cv_have_stdint_h@/1/g' \
-e 's/@ac_cv_have_systypes_h@/1/g' \
-e 's/@ac_cv_have_libgflags_h@/1/g' \
-e 's/@ac_cv_have_uint16_t@/1/g' \
-e 's/@ac_cv_have___builtin_expect@/1/g' \
-e 's/@ac_cv_have_.*@/0/g' \
-e 's/@ac_google_start_namespace@/namespace google {/g' \
-e 's/@ac_google_end_namespace@/}/g' \
-e 's/@ac_google_namespace@/google/g' \
-e 's/@ac_cv___attribute___noinline@/__attribute__((noinline))/g' \
-e 's/@ac_cv___attribute___noreturn@/__attribute__((noreturn))/g' \
-e 's/@ac_cv___attribute___printf_4_5@/__attribute__((__format__ (__printf__, 4, 5)))/g'
EOF""",
)
genrule(
name = "config_h",
srcs = [
"src/config.h.cmake.in",
],
outs = [
"config.h",
],
cmd = "awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $(<) > $(@)",
)
genrule(
name = "logging_h",
srcs = [
"src/glog/logging.h.in",
],
outs = [
"glog/logging.h",
],
cmd = "$(location :gen_sh) < $(<) > $(@)",
tools = [":gen_sh"],
)
genrule(
name = "raw_logging_h",
srcs = [
"src/glog/raw_logging.h.in",
],
outs = [
"glog/raw_logging.h",
],
cmd = "$(location :gen_sh) < $(<) > $(@)",
tools = [":gen_sh"],
)
genrule(
name = "stl_logging_h",
srcs = [
"src/glog/stl_logging.h.in",
],
outs = [
"glog/stl_logging.h",
],
cmd = "$(location :gen_sh) < $(<) > $(@)",
tools = [":gen_sh"],
)
genrule(
name = "vlog_is_on_h",
srcs = [
"src/glog/vlog_is_on.h.in",
],
outs = [
"glog/vlog_is_on.h",
],
cmd = "$(location :gen_sh) < $(<) > $(@)",
tools = [":gen_sh"],
)
package(default_visibility = ["//visibility:public"])
SOURCES = ["db/builder.cc",
"db/c.cc",
"db/dbformat.cc",
"db/db_impl.cc",
"db/db_iter.cc",
"db/dumpfile.cc",
"db/filename.cc",
"db/log_reader.cc",
"db/log_writer.cc",
"db/memtable.cc",
"db/repair.cc",
"db/table_cache.cc",
"db/version_edit.cc",
"db/version_set.cc",
"db/write_batch.cc",
"table/block_builder.cc",
"table/block.cc",
"table/filter_block.cc",
"table/format.cc",
"table/iterator.cc",
"table/merger.cc",
"table/table_builder.cc",
"table/table.cc",
"table/two_level_iterator.cc",
"util/arena.cc",
"util/bloom.cc",
"util/cache.cc",
"util/coding.cc",
"util/comparator.cc",
"util/crc32c.cc",
"util/env.cc",
"util/env_posix.cc",
"util/filter_policy.cc",
"util/hash.cc",
"util/histogram.cc",
"util/logging.cc",
"util/options.cc",
"util/status.cc",
"port/port_posix.cc",
"port/port_posix_sse.cc",
"helpers/memenv/memenv.cc",
]
cc_library(
name = "leveldb",
srcs = SOURCES,
hdrs = glob([
"helpers/memenv/*.h",
"util/*.h",
"port/*.h",
"port/win/*.h",
"table/*.h",
"db/*.h",
"include/leveldb/*.h"
],
exclude = [
"**/*test.*",
]),
includes = [
"include/",
],
copts = [
"-fno-builtin-memcmp",
"-DOS_LINUX",
"-DLEVELDB_PLATFORM_POSIX=1",
"-DLEVELDB_ATOMIC_PRESENT",
],
)
......@@ -22,6 +22,7 @@
#include <butil/config.h> // BRPC_WITH_GLOG
#include <inttypes.h>
#include <string>
#include <cstring>
#include <sstream>
......
load("//:bazel/brpc.bzl", "brpc_proto_library")
COPTS = [
"-D__STDC_FORMAT_MACROS",
"-DBTHREAD_USE_FAST_PTHREAD_MUTEX",
"-D__const__=",
"-D_GNU_SOURCE",
"-DUSE_SYMBOLIZE",
"-DNO_TCMALLOC",
"-D__STDC_LIMIT_MACROS",
"-D__STDC_CONSTANT_MACROS",
"-fPIC",
"-Wno-unused-parameter",
"-fno-omit-frame-pointer",
"-DGFLAGS_NS=google",
"-Dprivate=public",
"-Dprotected=public",
"--include test/sstream_workaround.h",
"-DBAZEL_TEST=1",
"-DBVAR_NOT_LINK_DEFAULT_VARIABLES",
"-DUNIT_TEST",
] + select({
"//:with_glog": ["-DBRPC_WITH_GLOG=1"],
"//conditions:default": ["-DBRPC_WITH_GLOG=0"],
})
LINKOPTS = [
"-lpthread",
"-lrt",
"-lssl",
"-lcrypto",
"-ldl",
"-lz",
]
TEST_BUTIL_SOURCES = [
"at_exit_unittest.cc",
"atomicops_unittest.cc",
"base64_unittest.cc",
"big_endian_unittest.cc",
"bits_unittest.cc",
"hash_tables_unittest.cc",
"linked_list_unittest.cc",
"mru_cache_unittest.cc",
"small_map_unittest.cc",
"stack_container_unittest.cc",
"cpu_unittest.cc",
"crash_logging_unittest.cc",
"leak_tracker_unittest.cc",
"proc_maps_linux_unittest.cc",
"stack_trace_unittest.cc",
"environment_unittest.cc",
"file_util_unittest.cc",
"dir_reader_posix_unittest.cc",
"file_path_unittest.cc",
"file_unittest.cc",
"scoped_temp_dir_unittest.cc",
"guid_unittest.cc",
"hash_unittest.cc",
"lazy_instance_unittest.cc",
"md5_unittest.cc",
"aligned_memory_unittest.cc",
"linked_ptr_unittest.cc",
"ref_counted_memory_unittest.cc",
"ref_counted_unittest.cc",
"scoped_ptr_unittest.cc",
"scoped_vector_unittest.cc",
"singleton_unittest.cc",
"weak_ptr_unittest.cc",
"observer_list_unittest.cc",
"file_descriptor_shuffle_unittest.cc",
"rand_util_unittest.cc",
"safe_numerics_unittest.cc",
"scoped_clear_errno_unittest.cc",
"scoped_generic_unittest.cc",
"security_unittest.cc",
"sha1_unittest.cc",
"stl_util_unittest.cc",
"nullable_string16_unittest.cc",
"safe_sprintf_unittest.cc",
"string16_unittest.cc",
"stringprintf_unittest.cc",
"string_number_conversions_unittest.cc",
"string_piece_unittest.cc",
"string_split_unittest.cc",
"string_tokenizer_unittest.cc",
"string_util_unittest.cc",
"stringize_macros_unittest.cc",
"sys_string_conversions_unittest.cc",
"utf_offset_string_conversions_unittest.cc",
"utf_string_conversions_unittest.cc",
"cancellation_flag_unittest.cc",
"condition_variable_unittest.cc",
"lock_unittest.cc",
"waitable_event_unittest.cc",
"type_traits_unittest.cc",
"non_thread_safe_unittest.cc",
"platform_thread_unittest.cc",
"simple_thread_unittest.cc",
"thread_checker_unittest.cc",
"thread_collision_warner_unittest.cc",
"thread_id_name_manager_unittest.cc",
"thread_local_storage_unittest.cc",
"thread_local_unittest.cc",
"watchdog_unittest.cc",
"pr_time_unittest.cc",
"time_unittest.cc",
"version_unittest.cc",
"logging_unittest.cc",
"cacheline_unittest.cpp",
"class_name_unittest.cpp",
"endpoint_unittest.cpp",
"unique_ptr_unittest.cpp",
"errno_unittest.cpp",
"fd_guard_unittest.cpp",
"file_watcher_unittest.cpp",
"find_cstr_unittest.cpp",
"scoped_lock_unittest.cpp",
"status_unittest.cpp",
"string_printf_unittest.cpp",
"string_splitter_unittest.cpp",
"synchronous_event_unittest.cpp",
"temp_file_unittest.cpp",
"baidu_thread_local_unittest.cpp",
"baidu_time_unittest.cpp",
"flat_map_unittest.cpp",
"crc32c_unittest.cc",
"iobuf_unittest.cpp",
"test_switches.cc",
"scoped_locale.cc",
"test_file_util_linux.cc",
#"popen_unittest.cpp",
"butil_unittest_main.cpp",
]
proto_library(
name = "test_proto",
srcs = glob([
"*.proto",
],
exclude = [
"echo.proto",
]
),
visibility = ["//visibility:public"],
)
cc_proto_library(
name = "cc_test_proto",
deps = [
":test_proto",
],
visibility = ["//visibility:public"],
)
cc_library(
name = "sstream_workaround",
hdrs = [
"sstream_workaround.h",
]
)
cc_test(
name = "butil_test",
srcs = TEST_BUTIL_SOURCES + [
"scoped_locale.h",
"multiprocess_func_list.h",
"test_switches.h",
],
deps = [
":sstream_workaround",
":cc_test_proto",
"//:brpc",
"@com_google_googletest//:gtest",
],
copts = COPTS,
)
cc_test(
name = "bvar_test",
srcs = glob([
"bvar_*_unittest.cpp",
],
exclude = [
"bvar_lock_timer_unittest.cpp",
"bvar_recorder_unittest.cpp",
]),
deps = [
":sstream_workaround",
"//:bvar",
"@com_google_googletest//:gtest",
],
copts = COPTS,
)
cc_test(
name = "bthread_test",
srcs = glob([
"bthread_*_unittest.cpp",
],
exclude = [
"bthread_cond_unittest.cpp",
"bthread_execution_queue_unittest.cpp",
"bthread_dispatcher_unittest.cpp",
"bthread_fd_unittest.cpp",
"bthread_mutex_unittest.cpp",
"bthread_setconcurrency_unittest.cpp",
# glog CHECK die with a fatal error
"bthread_key_unittest.cpp"
]),
deps = [
":sstream_workaround",
"//:brpc",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
copts = COPTS,
)
......@@ -108,7 +108,7 @@ TEST_BUTIL_SOURCES = \
baidu_time_unittest.cpp \
flat_map_unittest.cpp \
crc32c_unittest.cc \
iobuf_unittest.cc \
iobuf_unittest.cpp \
test_switches.cc \
scoped_locale.cc \
test_file_util_linux.cc \
......
......@@ -17,7 +17,11 @@
#include <butil/fd_guard.h>
#include <butil/errno.h>
#include <butil/fast_rand.h>
#if BAZEL_TEST
#include "test/iobuf.pb.h"
#else
#include "iobuf.pb.h"
#endif // BAZEL_TEST
namespace butil {
namespace iobuf {
......
build --copt -DHAVE_ZLIB=1
# bazel build with glog
# build --define=with_glog=true
build -c opt
# unittest
test --define=unittest=true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment