From: Joel Rosdahl Date: Sat, 24 Jul 2021 20:00:01 +0000 (+0200) Subject: Add support for downloading hiredis from Internet X-Git-Tag: v4.4~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2994d8e17d3fe2b83b940ccd5736a429f10956ce;p=thirdparty%2Fccache.git Add support for downloading hiredis from Internet --- diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index db8843ac1..056f5212c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -165,7 +165,7 @@ jobs: CFLAGS: -m32 -g -O2 CXXFLAGS: -m32 -g -O2 LDFLAGS: -m32 - CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DREDIS_STORAGE_BACKEND=OFF + CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON ENABLE_CACHE_CLEANUP_TESTS: 1 apt_get: elfutils gcc-multilib g++-multilib lib32stdc++-5-dev @@ -173,7 +173,7 @@ jobs: os: ubuntu-18.04 CC: gcc CXX: g++ - CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DREDIS_STORAGE_BACKEND=OFF + CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON ENABLE_CACHE_CLEANUP_TESTS: 1 CUDA: 10.1.243-1 apt_get: elfutils libzstd-dev diff --git a/CMakeLists.txt b/CMakeLists.txt index f06f0468b..0673a4a3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,10 +87,12 @@ include(GenerateVersionFile) # # Third party # +set(HIREDIS_FROM_INTERNET_DEFAULT OFF) set(ZSTD_FROM_INTERNET_DEFAULT OFF) # Default to downloading deps for Visual Studio, unless using a package manager. if(MSVC AND NOT CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg|conan") + set(HIREDIS_FROM_INTERNET_DEFAULT ON) set(ZSTD_FROM_INTERNET_DEFAULT ON) endif() @@ -99,6 +101,7 @@ find_package(zstd 1.1.2 REQUIRED) option(REDIS_STORAGE_BACKEND "Enable Redis secondary storage" ON) if(REDIS_STORAGE_BACKEND) + option(HIREDIS_FROM_INTERNET "Download and use libhiredis from the Internet" ${HIREDIS_FROM_INTERNET_DEFAULT}) find_package(hiredis 0.13.3 REQUIRED) endif() diff --git a/cmake/Findhiredis.cmake b/cmake/Findhiredis.cmake index ec5ff2351..21bec80e0 100644 --- a/cmake/Findhiredis.cmake +++ b/cmake/Findhiredis.cmake @@ -1,27 +1,75 @@ -find_package(PkgConfig) -if(PKG_CONFIG_FOUND) - pkg_check_modules(HIREDIS REQUIRED hiredis>=${hiredis_FIND_VERSION}) - find_library(HIREDIS_LIBRARY ${HIREDIS_LIBRARIES} HINTS ${HIREDIS_LIBDIR}) - find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h HINTS ${HIREDIS_PREFIX}/include) +if(HIREDIS_FROM_INTERNET) + set(hiredis_version "1.0.0") + set(hiredis_url https://github.com/redis/hiredis/archive/v${hiredis_version}.tar.gz) + + set(hiredis_dir ${CMAKE_BINARY_DIR}/hiredis-${hiredis_version}) + set(hiredis_build ${CMAKE_BINARY_DIR}/hiredis-build) + + if(NOT EXISTS "${hiredis_dir}.tar.gz") + file(DOWNLOAD "${hiredis_url}" "${hiredis_dir}.tar.gz" STATUS download_status) + list(GET download_status 0 error_code) + if(error_code) + file(REMOVE "${hiredis_dir}.tar.gz") + list(GET download_status 1 error_message) + message(FATAL "Failed to download hiredis: ${error_message}") + endif() + endif() + + execute_process( + COMMAND tar xf "${hiredis_dir}.tar.gz" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" + RESULT_VARIABLE tar_error) + if(NOT tar_error EQUAL 0) + message(FATAL "extracting ${hiredis_dir}.tar.gz failed") + endif() + + set( + hiredis_sources + "${hiredis_dir}/alloc.c" + "${hiredis_dir}/async.c" + "${hiredis_dir}/dict.c" + "${hiredis_dir}/hiredis.c" + "${hiredis_dir}/net.c" + "${hiredis_dir}/read.c" + "${hiredis_dir}/sds.c" + "${hiredis_dir}/sockcompat.c" + ) + add_library(libhiredis_static STATIC EXCLUDE_FROM_ALL ${hiredis_sources}) + add_library(HIREDIS::HIREDIS ALIAS libhiredis_static) + make_directory("${hiredis_dir}/include") + make_directory("${hiredis_dir}/include/hiredis") + file(GLOB hiredis_headers "${hiredis_dir}/*.h") + file(COPY ${hiredis_headers} DESTINATION "${hiredis_dir}/include/hiredis") + set_target_properties( + libhiredis_static + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "$") else() - find_library(HIREDIS_LIBRARY hiredis) - find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h) -endif() + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + pkg_check_modules(HIREDIS REQUIRED hiredis>=${hiredis_FIND_VERSION}) + find_library(HIREDIS_LIBRARY ${HIREDIS_LIBRARIES} HINTS ${HIREDIS_LIBDIR}) + find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h HINTS ${HIREDIS_PREFIX}/include) + else() + find_library(HIREDIS_LIBRARY hiredis) + find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h) + endif() -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - hiredis - "please install libhiredis or disable with -DREDIS_STORAGE_BACKEND=OFF" - HIREDIS_INCLUDE_DIR HIREDIS_LIBRARY) -mark_as_advanced(HIREDIS_INCLUDE_DIR HIREDIS_LIBRARY) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( + hiredis + "please install libhiredis or use -DHIREDIS_FROM_INTERNET=ON or disable with -DREDIS_STORAGE_BACKEND=OFF" + HIREDIS_INCLUDE_DIR HIREDIS_LIBRARY) + mark_as_advanced(HIREDIS_INCLUDE_DIR HIREDIS_LIBRARY) -add_library(HIREDIS::HIREDIS UNKNOWN IMPORTED) -set_target_properties( - HIREDIS::HIREDIS - PROPERTIES - IMPORTED_LOCATION "${HIREDIS_LIBRARY}" - INTERFACE_COMPILE_OPTIONS "${HIREDIS_CFLAGS_OTHER}" - INTERFACE_INCLUDE_DIRECTORIES "${HIREDIS_INCLUDE_DIR}") + add_library(HIREDIS::HIREDIS UNKNOWN IMPORTED) + set_target_properties( + HIREDIS::HIREDIS + PROPERTIES + IMPORTED_LOCATION "${HIREDIS_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${HIREDIS_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${HIREDIS_INCLUDE_DIR}") +endif() include(FeatureSummary) set_package_properties( diff --git a/doc/INSTALL.md b/doc/INSTALL.md index 79f422a05..4391ffaf9 100644 --- a/doc/INSTALL.md +++ b/doc/INSTALL.md @@ -14,6 +14,7 @@ To build ccache you need: - [libzstd](http://www.zstd.net). If you don't have libzstd installed and can't or don't want to install it in a standard system location, there are two options: + 1. Install zstd in a custom path and set `CMAKE_PREFIX_PATH` to it, e.g. by passing `-DCMAKE_PREFIX_PATH=/some/custom/path` to `cmake`, or 2. Pass `-DZSTD_FROM_INTERNET=ON` to `cmake` to make it download libzstd @@ -24,6 +25,18 @@ To build ccache you need: Optional: +- [hiredis](https://github.com/redis/hiredis) for the Redis storage backend. If + you don't have libhiredis installed and can't or don't want to install it in a + standard system location, there are two options: + + 1. Install hiredis in a custom path and set `CMAKE_PREFIX_PATH` to it, e.g. + by passing `-DCMAKE_PREFIX_PATH=/some/custom/path` to `cmake`, or + 2. Pass `-DHIREDIS_FROM_INTERNET=ON` to `cmake` to make it download hiredis + from the Internet and unpack it in the local binary tree. Ccache will + then be linked statically to the locally built libhiredis. + + To link libhiredis statically you can use + `-DHIREDIS_LIBRARY=/path/to/libhiredis.a`. - GNU Bourne Again SHell (bash) for tests. - [AsciiDoc](https://www.methods.co.nz/asciidoc/) to build the HTML documentation. diff --git a/src/storage/secondary/RedisStorage.cpp b/src/storage/secondary/RedisStorage.cpp index 09943c8e7..8740edcb2 100644 --- a/src/storage/secondary/RedisStorage.cpp +++ b/src/storage/secondary/RedisStorage.cpp @@ -25,7 +25,15 @@ #include #include +#ifdef __GNUC__ +# pragma GCC diagnostic push +// Ignore "ISO C++ forbids flexible array member ‘buf’" warning from -Wpedantic. +# pragma GCC diagnostic ignored "-Wpedantic" +#endif #include +#ifdef __GNUC__ +# pragma GCC diagnostic pop +#endif #include #include