targets_cfg.py 4.7 KB

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