targets_cfg.py 3.9 KB
Newer Older
1 2 3 4
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
Y
Yi Wu 已提交
5
rocksdb_target_header = """load("@fbcode_macros//build_defs:auto_headers.bzl", "AutoHeaders")
6 7

REPO_PATH = package_name() + "/"
Y
Yi Wu 已提交
8

9
BUCK_BINS = "buck-out/gen/" + REPO_PATH
Y
Yi Wu 已提交
10

11
TEST_RUNNER = REPO_PATH + "buckifier/rocks_test_runner.sh"
Y
Yi Wu 已提交
12

13
rocksdb_compiler_flags = [
Y
Yi Wu 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
    "-fno-builtin-memcmp",
    "-DROCKSDB_PLATFORM_POSIX",
    "-DROCKSDB_LIB_IO_POSIX",
    "-DROCKSDB_FALLOCATE_PRESENT",
    "-DROCKSDB_MALLOC_USABLE_SIZE",
    "-DROCKSDB_RANGESYNC_PRESENT",
    "-DROCKSDB_SCHED_GETCPU_PRESENT",
    "-DROCKSDB_SUPPORT_THREAD_LOCAL",
    "-DOS_LINUX",
    # Flags to enable libs we include
    "-DSNAPPY",
    "-DZLIB",
    "-DBZIP2",
    "-DLZ4",
    "-DZSTD",
    "-DGFLAGS=gflags",
    "-DNUMA",
    "-DTBB",
    # Needed to compile in fbcode
    "-Wno-expansion-to-defined",
F
Fosco Marotto 已提交
34 35 36
    # Added missing flags from output of build_detect_platform
    "-DROCKSDB_PTHREAD_ADAPTIVE_MUTEX",
    "-DROCKSDB_BACKTRACE",
Y
Yi Wu 已提交
37
    "-Wnarrowing",
38 39 40
]

rocksdb_external_deps = [
Y
Yi Wu 已提交
41 42 43 44 45 46 47 48 49
    ("bzip2", None, "bz2"),
    ("snappy", None, "snappy"),
    ("zlib", None, "z"),
    ("gflags", None, "gflags"),
    ("lz4", None, "lz4"),
    ("zstd", None),
    ("tbb", None),
    ("numa", None, "numa"),
    ("googletest", None, "gtest"),
50 51 52
]

rocksdb_preprocessor_flags = [
Y
Yi Wu 已提交
53 54 55
    # Directories with files for #include
    "-I" + REPO_PATH + "include/",
    "-I" + REPO_PATH,
56
]
57 58

rocksdb_arch_preprocessor_flags = {
S
Siying Dong 已提交
59 60 61 62
    "x86_64": [
        "-DHAVE_SSE42",
        "-DHAVE_PCLMUL",
    ],
63
}
Y
Yi Wu 已提交
64 65 66 67 68 69 70 71 72

build_mode = read_config("fbcode", "build_mode")

is_opt_mode = build_mode.startswith("opt")

# -DNDEBUG is added by default in opt mode in fbcode. But adding it twice
# doesn't harm and avoid forgetting to add it.
if is_opt_mode:
    rocksdb_compiler_flags.append("-DNDEBUG")
73 74 75 76 77 78 79 80 81 82

default_allocator = read_config("fbcode", "default_allocator")

sanitizer = read_config("fbcode", "sanitizer")

# Let RocksDB aware of jemalloc existence.
# Do not enable it if sanitizer presents.
if default_allocator.startswith("jemalloc") and sanitizer == "":
    rocksdb_compiler_flags.append("-DROCKSDB_JEMALLOC")
    rocksdb_external_deps.append(("jemalloc", None, "headers"))
83 84 85 86 87 88 89
"""


library_template = """
cpp_library(
    name = "%s",
    srcs = [%s],
Y
Yi Wu 已提交
90
    headers = %s,
91
    arch_preprocessor_flags = rocksdb_arch_preprocessor_flags,
92
    compiler_flags = rocksdb_compiler_flags,
Y
Yi Wu 已提交
93 94
    preprocessor_flags = rocksdb_preprocessor_flags,
    deps = [%s],
95 96 97 98 99 100
    external_deps = rocksdb_external_deps,
)
"""

binary_template = """
cpp_binary(
Y
Yi Wu 已提交
101 102 103 104 105 106 107
    name = "%s",
    srcs = [%s],
    arch_preprocessor_flags = rocksdb_arch_preprocessor_flags,
    compiler_flags = rocksdb_compiler_flags,
    preprocessor_flags = rocksdb_preprocessor_flags,
    deps = [%s],
    external_deps = rocksdb_external_deps,
108 109 110
)
"""

Y
Yi Wu 已提交
111 112 113 114 115 116 117
test_cfg_template = """    [
        "%s",
        "%s",
        "%s",
    ],
"""

118 119
unittests_template = """
# [test_name, test_src, test_type]
Y
Yi Wu 已提交
120 121
ROCKS_TESTS = [
%s]
122 123

# Generate a test rule for each entry in ROCKS_TESTS
Y
Yi Wu 已提交
124 125 126 127 128 129 130 131 132
# Do not build the tests in opt mode, since SyncPoint and other test code
# will not be included.
if not is_opt_mode:
    for test_cfg in ROCKS_TESTS:
        test_name = test_cfg[0]
        test_cc = test_cfg[1]
        ttype = "gtest" if test_cfg[2] == "parallel" else "simple"
        test_bin = test_name + "_bin"

Y
Yi Wu 已提交
133 134 135 136 137 138 139 140
        cpp_binary(
            name = test_bin,
            srcs = [test_cc],
            arch_preprocessor_flags = rocksdb_arch_preprocessor_flags,
            compiler_flags = rocksdb_compiler_flags,
            preprocessor_flags = rocksdb_preprocessor_flags,
            deps = [":rocksdb_test_lib"],
            external_deps = rocksdb_external_deps,
Y
Yi Wu 已提交
141 142 143
        )

        custom_unittest(
Y
Yi Wu 已提交
144 145 146 147
            name = test_name,
            command = [TEST_RUNNER, BUCK_BINS + test_bin],
            type = ttype,
            deps = [":" + test_bin],
Y
Yi Wu 已提交
148
        )
149
"""