1# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2from __future__ import absolute_import 3from __future__ import division 4from __future__ import print_function 5from __future__ import unicode_literals 6 7rocksdb_target_header = """# This file \100generated by `python buckifier/buckify_rocksdb.py` 8# --> DO NOT EDIT MANUALLY <-- 9# This file is a Facebook-specific integration for buck builds, so can 10# only be validated by Facebook employees. 11# 12load("@fbcode_macros//build_defs:auto_headers.bzl", "AutoHeaders") 13load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") 14load(":defs.bzl", "test_binary") 15 16REPO_PATH = package_name() + "/" 17 18ROCKSDB_COMPILER_FLAGS = [ 19 "-fno-builtin-memcmp", 20 # Needed to compile in fbcode 21 "-Wno-expansion-to-defined", 22 # Added missing flags from output of build_detect_platform 23 "-Wnarrowing", 24 "-DROCKSDB_NO_DYNAMIC_EXTENSION", 25] 26 27ROCKSDB_EXTERNAL_DEPS = [ 28 ("bzip2", None, "bz2"), 29 ("snappy", None, "snappy"), 30 ("zlib", None, "z"), 31 ("gflags", None, "gflags"), 32 ("lz4", None, "lz4"), 33 ("zstd", None), 34 ("tbb", None), 35 ("googletest", None, "gtest"), 36] 37 38ROCKSDB_OS_DEPS = [ 39 ( 40 "linux", 41 ["third-party//numa:numa", "third-party//liburing:uring"], 42 ), 43] 44 45ROCKSDB_OS_PREPROCESSOR_FLAGS = [ 46 ( 47 "linux", 48 [ 49 "-DOS_LINUX", 50 "-DROCKSDB_FALLOCATE_PRESENT", 51 "-DROCKSDB_MALLOC_USABLE_SIZE", 52 "-DROCKSDB_PTHREAD_ADAPTIVE_MUTEX", 53 "-DROCKSDB_RANGESYNC_PRESENT", 54 "-DROCKSDB_SCHED_GETCPU_PRESENT", 55 "-DROCKSDB_IOURING_PRESENT", 56 "-DHAVE_SSE42", 57 "-DLIBURING", 58 "-DNUMA", 59 ], 60 ), 61 ( 62 "macos", 63 ["-DOS_MACOSX"], 64 ), 65] 66 67ROCKSDB_PREPROCESSOR_FLAGS = [ 68 "-DROCKSDB_PLATFORM_POSIX", 69 "-DROCKSDB_LIB_IO_POSIX", 70 "-DROCKSDB_SUPPORT_THREAD_LOCAL", 71 72 # Flags to enable libs we include 73 "-DSNAPPY", 74 "-DZLIB", 75 "-DBZIP2", 76 "-DLZ4", 77 "-DZSTD", 78 "-DZSTD_STATIC_LINKING_ONLY", 79 "-DGFLAGS=gflags", 80 "-DTBB", 81 82 # Added missing flags from output of build_detect_platform 83 "-DROCKSDB_BACKTRACE", 84 85 # Directories with files for #include 86 "-I" + REPO_PATH + "include/", 87 "-I" + REPO_PATH, 88] 89 90ROCKSDB_ARCH_PREPROCESSOR_FLAGS = { 91 "x86_64": [ 92 "-DHAVE_PCLMUL", 93 ], 94} 95 96build_mode = read_config("fbcode", "build_mode") 97 98is_opt_mode = build_mode.startswith("opt") 99 100# -DNDEBUG is added by default in opt mode in fbcode. But adding it twice 101# doesn't harm and avoid forgetting to add it. 102ROCKSDB_COMPILER_FLAGS += (["-DNDEBUG"] if is_opt_mode else []) 103 104sanitizer = read_config("fbcode", "sanitizer") 105 106# Do not enable jemalloc if sanitizer presents. RocksDB will further detect 107# whether the binary is linked with jemalloc at runtime. 108ROCKSDB_OS_PREPROCESSOR_FLAGS += ([( 109 "linux", 110 ["-DROCKSDB_JEMALLOC"], 111)] if sanitizer == "" else []) 112 113ROCKSDB_OS_DEPS += ([( 114 "linux", 115 ["third-party//jemalloc:headers"], 116)] if sanitizer == "" else []) 117""" 118 119 120library_template = """ 121cpp_library( 122 name = "{name}", 123 srcs = [{srcs}], 124 {headers_attr_prefix}headers = {headers}, 125 arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, 126 compiler_flags = ROCKSDB_COMPILER_FLAGS, 127 os_deps = ROCKSDB_OS_DEPS, 128 os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS, 129 preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, 130 deps = [{deps}], 131 external_deps = ROCKSDB_EXTERNAL_DEPS, 132) 133""" 134 135binary_template = """ 136cpp_binary( 137 name = "%s", 138 srcs = [%s], 139 arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, 140 compiler_flags = ROCKSDB_COMPILER_FLAGS, 141 preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, 142 deps = [%s], 143 external_deps = ROCKSDB_EXTERNAL_DEPS, 144) 145""" 146 147test_cfg_template = """ [ 148 "%s", 149 "%s", 150 "%s", 151 %s, 152 %s, 153 ], 154""" 155 156unittests_template = """ 157# [test_name, test_src, test_type, extra_deps, extra_compiler_flags] 158ROCKS_TESTS = [ 159%s] 160 161# Generate a test rule for each entry in ROCKS_TESTS 162# Do not build the tests in opt mode, since SyncPoint and other test code 163# will not be included. 164[ 165 test_binary( 166 extra_compiler_flags = extra_compiler_flags, 167 extra_deps = extra_deps, 168 parallelism = parallelism, 169 rocksdb_arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, 170 rocksdb_compiler_flags = ROCKSDB_COMPILER_FLAGS, 171 rocksdb_external_deps = ROCKSDB_EXTERNAL_DEPS, 172 rocksdb_os_deps = ROCKSDB_OS_DEPS, 173 rocksdb_os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS, 174 rocksdb_preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, 175 test_cc = test_cc, 176 test_name = test_name, 177 ) 178 for test_name, test_cc, parallelism, extra_deps, extra_compiler_flags in ROCKS_TESTS 179 if not is_opt_mode 180] 181""" 182