Skip to content

Commit

Permalink
gcc-11 and cmake related cleanup (facebook#9286)
Browse files Browse the repository at this point in the history
Summary:
in hope to get rockdb compiled with GCC-11 without warning

* util/bloom_test: init a variable before using it
  to silence the GCC warning like
  ```
  util/bloom_test.cc:1253:31: error: ‘<anonymous>’ may be used uninitialized [-Werror=maybe-uninitialized]
   1253 |   Slice key_slice{key_bytes, 8};
        |                               ^
  ...
  include/rocksdb/slice.h:41:3: note: by argument 2 of type ‘const char*’ to ‘rocksdb::Slice::Slice(const char*, size_t)’ declared here
     41 |   Slice(const char* d, size_t n) : data_(d), size_(n) {}
        |   ^~~~~
  util/bloom_test.cc:1249:3: note: ‘<anonymous>’ declared here
   1249 |   };
        |   ^
  cc1plus: all warnings being treated as errors
  ```
* cmake: add find_package(uring ...)
  find liburing in a more consistent way. also it is the encouraged way for finding a library.

Pull Request resolved: facebook#9286

Reviewed By: mrambacher

Differential Revision: D33165241

Pulled By: jay-zhuang

fbshipit-source-id: 9f3487e11b4e40fd8f1c97c8facb24a190e5ce31
  • Loading branch information
tchaikov authored and facebook-github-bot committed Dec 18, 2021
1 parent 7bfad07 commit cc1d4e3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
22 changes: 7 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,25 +352,17 @@ int main() {
return 0;
}
" BUILTIN_ATOMIC)
if (NOT BUILTIN_ATOMIC)
#TODO: Check if -latomic exists
list(APPEND THIRDPARTY_LIBS atomic)
endif()
if (NOT BUILTIN_ATOMIC)
#TODO: Check if -latomic exists
list(APPEND THIRDPARTY_LIBS atomic)
endif()
endif()

if (WITH_LIBURING)
set(CMAKE_REQUIRED_FLAGS "-luring")
CHECK_CXX_SOURCE_COMPILES("
#include <liburing.h>
int main() {
struct io_uring ring;
io_uring_queue_init(1, &ring, 0);
return 0;
}
" HAS_LIBURING)
if (HAS_LIBURING)
find_package(uring)
if (uring_FOUND)
add_definitions(-DROCKSDB_IOURING_PRESENT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -luring")
list(APPEND THIRDPARTY_LIBS uring::uring)
endif()
endif()

Expand Down
26 changes: 26 additions & 0 deletions cmake/modules/Finduring.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# - Find liburing
#
# uring_INCLUDE_DIR - Where to find liburing.h
# uring_LIBRARIES - List of libraries when using uring.
# uring_FOUND - True if uring found.

find_path(uring_INCLUDE_DIR
NAMES liburing.h)
find_library(uring_LIBRARIES
NAMES liburing.a liburing)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(uring
DEFAULT_MSG uring_LIBRARIES uring_INCLUDE_DIR)

mark_as_advanced(
uring_INCLUDE_DIR
uring_LIBRARIES)

if(uring_FOUND AND NOT TARGET uring::uring)
add_library(uring::uring UNKNOWN IMPORTED)
set_target_properties(uring::uring PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${uring_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${uring_LIBRARIES}")
endif()
2 changes: 1 addition & 1 deletion util/bloom_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ INSTANTIATE_TEST_CASE_P(Full, FullBloomTest,

static double GetEffectiveBitsPerKey(FilterBitsBuilder* builder) {
union {
uint64_t key_value;
uint64_t key_value = 0;
char key_bytes[8];
};

Expand Down

0 comments on commit cc1d4e3

Please sign in to comment.