targets_cfg.py 4.7 KB
Newer Older
1
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 3 4 5
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
6 7 8 9 10 11 12

rocksdb_target_header = """# This file \100generated by `python buckifier/buckify_rocksdb.py`
# --> DO NOT EDIT MANUALLY <--
# This file is a Facebook-specific integration for buck builds, so can
# only be validated by Facebook employees.
#
load("@fbcode_macros//build_defs:auto_headers.bzl", "AutoHeaders")
13
load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library")
14
load(":defs.bzl", "test_binary")
15 16

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

18
ROCKSDB_COMPILER_FLAGS = [
Y
Yi Wu 已提交
19 20 21
    "-fno-builtin-memcmp",
    # Needed to compile in fbcode
    "-Wno-expansion-to-defined",
F
Fosco Marotto 已提交
22
    # Added missing flags from output of build_detect_platform
Y
Yi Wu 已提交
23
    "-Wnarrowing",
24
    "-DROCKSDB_NO_DYNAMIC_EXTENSION",
25 26
]

27
ROCKSDB_EXTERNAL_DEPS = [
Y
Yi Wu 已提交
28 29 30 31 32 33 34 35
    ("bzip2", None, "bz2"),
    ("snappy", None, "snappy"),
    ("zlib", None, "z"),
    ("gflags", None, "gflags"),
    ("lz4", None, "lz4"),
    ("zstd", None),
    ("tbb", None),
    ("googletest", None, "gtest"),
36 37
]

Y
Yanqin Jin 已提交
38 39 40
ROCKSDB_OS_DEPS = [
    (
        "linux",
C
Chad Austin 已提交
41
        ["third-party//numa:numa", "third-party//liburing:uring"],
Y
Yanqin Jin 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    ),
]

ROCKSDB_OS_PREPROCESSOR_FLAGS = [
    (
        "linux",
        [
            "-DOS_LINUX",
            "-DROCKSDB_FALLOCATE_PRESENT",
            "-DROCKSDB_MALLOC_USABLE_SIZE",
            "-DROCKSDB_PTHREAD_ADAPTIVE_MUTEX",
            "-DROCKSDB_RANGESYNC_PRESENT",
            "-DROCKSDB_SCHED_GETCPU_PRESENT",
            "-DHAVE_SSE42",
            "-DNUMA",
        ],
    ),
    (
        "macos",
        ["-DOS_MACOSX"],
    ),
]

65
ROCKSDB_PREPROCESSOR_FLAGS = [
Y
Yanqin Jin 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    "-DROCKSDB_PLATFORM_POSIX",
    "-DROCKSDB_LIB_IO_POSIX",
    "-DROCKSDB_SUPPORT_THREAD_LOCAL",

    # Flags to enable libs we include
    "-DSNAPPY",
    "-DZLIB",
    "-DBZIP2",
    "-DLZ4",
    "-DZSTD",
    "-DZSTD_STATIC_LINKING_ONLY",
    "-DGFLAGS=gflags",
    "-DTBB",

    # Added missing flags from output of build_detect_platform
    "-DROCKSDB_BACKTRACE",

Y
Yi Wu 已提交
83 84 85
    # Directories with files for #include
    "-I" + REPO_PATH + "include/",
    "-I" + REPO_PATH,
86
]
87

88
ROCKSDB_ARCH_PREPROCESSOR_FLAGS = {
S
Siying Dong 已提交
89 90 91
    "x86_64": [
        "-DHAVE_PCLMUL",
    ],
92
}
Y
Yi Wu 已提交
93 94 95 96 97 98 99

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.
100
ROCKSDB_COMPILER_FLAGS += (["-DNDEBUG"] if is_opt_mode else [])
101 102 103

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

104 105
# Do not enable jemalloc if sanitizer presents. RocksDB will further detect
# whether the binary is linked with jemalloc at runtime.
Y
Yanqin Jin 已提交
106 107 108 109 110 111 112 113 114
ROCKSDB_OS_PREPROCESSOR_FLAGS += ([(
    "linux",
    ["-DROCKSDB_JEMALLOC"],
)] if sanitizer == "" else [])

ROCKSDB_OS_DEPS += ([(
    "linux",
    ["third-party//jemalloc:headers"],
)] if sanitizer == "" else [])
115 116 117 118 119
"""


library_template = """
cpp_library(
120 121 122
    name = "{name}",
    srcs = [{srcs}],
    {headers_attr_prefix}headers = {headers},
123 124
    arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS,
    compiler_flags = ROCKSDB_COMPILER_FLAGS,
Y
Yanqin Jin 已提交
125 126
    os_deps = ROCKSDB_OS_DEPS,
    os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS,
127
    preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS,
128
    deps = [{deps}],
129
    external_deps = ROCKSDB_EXTERNAL_DEPS,
130 131 132 133 134
)
"""

binary_template = """
cpp_binary(
Y
Yi Wu 已提交
135 136
    name = "%s",
    srcs = [%s],
137 138 139
    arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS,
    compiler_flags = ROCKSDB_COMPILER_FLAGS,
    preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS,
Y
Yi Wu 已提交
140
    deps = [%s],
141
    external_deps = ROCKSDB_EXTERNAL_DEPS,
142 143 144
)
"""

Y
Yi Wu 已提交
145 146 147 148
test_cfg_template = """    [
        "%s",
        "%s",
        "%s",
149 150
        %s,
        %s,
Y
Yi Wu 已提交
151 152 153
    ],
"""

154
unittests_template = """
155
# [test_name, test_src, test_type, extra_deps, extra_compiler_flags]
Y
Yi Wu 已提交
156 157
ROCKS_TESTS = [
%s]
158 159

# Generate a test rule for each entry in ROCKS_TESTS
Y
Yi Wu 已提交
160 161
# Do not build the tests in opt mode, since SyncPoint and other test code
# will not be included.
162 163
[
    test_binary(
164 165
        extra_compiler_flags = extra_compiler_flags,
        extra_deps = extra_deps,
166 167 168 169
        parallelism = parallelism,
        rocksdb_arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS,
        rocksdb_compiler_flags = ROCKSDB_COMPILER_FLAGS,
        rocksdb_external_deps = ROCKSDB_EXTERNAL_DEPS,
Y
Yanqin Jin 已提交
170 171
        rocksdb_os_deps = ROCKSDB_OS_DEPS,
        rocksdb_os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS,
172 173 174 175
        rocksdb_preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS,
        test_cc = test_cc,
        test_name = test_name,
    )
176
    for test_name, test_cc, parallelism, extra_deps, extra_compiler_flags in ROCKS_TESTS
177 178
    if not is_opt_mode
]
179
"""