From 0731a0509a82af5114da1b5aa6cf8ba84c06e134 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 23 Mar 2024 00:23:16 +0100 Subject: [PATCH] build: Add support for linking against a system libhiredis/libhiredis_ssl Add a new USE_SYSTEM_HIREDIS make variable to select whether to link against the system libhiredis (and libhiredis_ssl if BUILD_TLS is enabled). Move the sdscompat.h header from the vendored hiredis directory to src/, as this file is not and has never been part of the upstream hiredis project, it got added in commit bffbbeaa9a1a6b8e81384297272cb0631502e8fd in redis itself. --- deps/Makefile | 2 + ...upport-for-a-USE_SYSTEM_HIREDIS-flag.patch | 84 ------------------- pkg/deb/debian_dh9/patches/series | 1 - src/Makefile | 32 +++++-- src/cli_common.c | 2 +- src/keydb-diagnostic-tool.cpp | 2 +- src/motd.cpp | 4 +- src/redis-benchmark.cpp | 2 +- src/redis-cli.c | 2 +- src/redis-cli.h | 2 +- {deps/hiredis => src}/sdscompat.h | 4 + 11 files changed, 38 insertions(+), 99 deletions(-) delete mode 100644 pkg/deb/debian_dh9/patches/0007-Add-support-for-a-USE_SYSTEM_HIREDIS-flag.patch rename {deps/hiredis => src}/sdscompat.h (98%) diff --git a/deps/Makefile b/deps/Makefile index 7112907ab..7ef872784 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -34,7 +34,9 @@ ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), endif distclean: +ifneq ($(USE_SYSTEM_HIREDIS),yes) -(cd hiredis && $(MAKE) clean) > /dev/null || true +endif -(cd linenoise && $(MAKE) clean) > /dev/null || true -(cd lua && $(MAKE) clean) > /dev/null || true ifneq ($(USE_SYSTEM_JEMALLOC),yes) diff --git a/pkg/deb/debian_dh9/patches/0007-Add-support-for-a-USE_SYSTEM_HIREDIS-flag.patch b/pkg/deb/debian_dh9/patches/0007-Add-support-for-a-USE_SYSTEM_HIREDIS-flag.patch deleted file mode 100644 index 8e59cc144..000000000 --- a/pkg/deb/debian_dh9/patches/0007-Add-support-for-a-USE_SYSTEM_HIREDIS-flag.patch +++ /dev/null @@ -1,84 +0,0 @@ -From: Chris Lamb -Date: Wed, 3 Oct 2018 19:24:16 +0100 -Subject: Add support for a USE_SYSTEM_HIREDIS flag. - ---- - deps/Makefile | 2 ++ - src/Makefile | 19 ++++++++++++++----- - 2 files changed, 16 insertions(+), 5 deletions(-) - -diff --git a/deps/Makefile b/deps/Makefile -index 2ed7736..d6b8e3e 100644 ---- a/deps/Makefile -+++ b/deps/Makefile -@@ -33,7 +33,9 @@ ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), - endif - - distclean: -+ifneq ($(USE_SYSTEM_HIREDIS),yes) - -(cd hiredis && $(MAKE) clean) > /dev/null || true -+endif - -(cd linenoise && $(MAKE) clean) > /dev/null || true - ifneq ($(USE_SYSTEM_LUA),yes) - -(cd lua && $(MAKE) clean) > /dev/null || true -diff --git a/src/Makefile b/src/Makefile -index 49085f2..9e7e6f1 100644 ---- a/src/Makefile -+++ b/src/Makefile -@@ -16,7 +16,7 @@ release_hdr := $(shell sh -c './mkreleasehdr.sh') - uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') - uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not') - OPTIMIZATION?=-O2 --DEPENDENCY_TARGETS=hiredis linenoise -+DEPENDENCY_TARGETS=linenoise - NODEPS:=clean distclean - - # Default settings -@@ -107,7 +107,7 @@ endif - endif - endif - # Include paths to dependencies --FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -+FINAL_CFLAGS+= -I../deps/linenoise - - ifeq ($(MALLOC),tcmalloc) - FINAL_CFLAGS+= -DUSE_TCMALLOC -@@ -139,6 +139,15 @@ else - FINAL_LIBS := ../deps/lua/src/liblua.a $(FINAL_LIBS) - endif - -+ifeq ($(USE_SYSTEM_HIREDIS),yes) -+ FINAL_LIBS+= -lhiredis -+ FINAL_CFLAGS+= -I/usr/include/hiredis -+else -+ DEPENDENCY_TARGETS += hiredis -+ FINAL_LIBS+= ../deps/hiredis/libhiredis.a -+ FINAL_CFLAGS+= -I../deps/hiredis -+endif -+ - REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS) $(CPPFLAGS) - REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS) - REDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL) -@@ -210,7 +219,7 @@ endif - - # redis-server - $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) -- $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS) -+ $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) - - # redis-sentinel - $(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME) -@@ -226,11 +235,11 @@ $(REDIS_CHECK_AOF_NAME): $(REDIS_SERVER_NAME) - - # redis-cli - $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ) -- $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS) -+ $(REDIS_LD) -o $@ $^ ../deps/linenoise/linenoise.o $(FINAL_LIBS) - - # redis-benchmark - $(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ) -- $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS) -+ $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) - - dict-benchmark: dict.c zmalloc.c sds.c siphash.c - $(REDIS_CC) $(FINAL_CFLAGS) $^ -D DICT_BENCHMARK_MAIN -o $@ $(FINAL_LIBS) diff --git a/pkg/deb/debian_dh9/patches/series b/pkg/deb/debian_dh9/patches/series index 3e108036d..2da3b11e1 100644 --- a/pkg/deb/debian_dh9/patches/series +++ b/pkg/deb/debian_dh9/patches/series @@ -3,5 +3,4 @@ #debian-packaging/0007-Set-Debian-configuration-defaults.patch #0010-Use-get_current_dir_name-over-PATHMAX-etc.patch #0011-Add-support-for-a-USE_SYSTEM_LUA-flag.patch -#0007-Add-support-for-a-USE_SYSTEM_HIREDIS-flag.patch #test diff --git a/src/Makefile b/src/Makefile index 4476f7c96..587a265fd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,7 @@ release_hdr := $(shell sh -c './mkreleasehdr.sh') uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not') OPTIMIZATION?=-O2 -flto -DEPENDENCY_TARGETS=hiredis linenoise lua hdr_histogram +DEPENDENCY_TARGETS=linenoise lua hdr_histogram NODEPS:=clean distclean # Default settings @@ -274,8 +274,8 @@ ifdef OPENSSL_PREFIX endif # Include paths to dependencies -FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram -FINAL_CXXFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram +FINAL_CFLAGS+= -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram +FINAL_CXXFLAGS+= -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram ifeq ($(USE_SYSTEM_CONCURRENTQUEUE),yes) FINAL_CXXFLAGS+= -I/usr/include/concurrentqueue/moodycamel @@ -343,6 +343,22 @@ ifeq ($(MALLOC),memkind) FINAL_LIBS := ../deps/memkind/src/.libs/libmemkind.a -lnuma $(FINAL_LIBS) endif +ifeq ($(USE_SYSTEM_HIREDIS),yes) + HIREDIS_CFLAGS := $(shell $(PKG_CONFIG) --cflags hiredis) -DUSE_SYSTEM_HIREDIS=1 + FINAL_CFLAGS+= $(HIREDIS_CFLAGS) + FINAL_CXXFLAGS+= $(HIREDIS_CFLAGS) + FINAL_LIBS+= $(shell $(PKG_CONFIG) --libs hiredis) +ifeq ($(BUILD_TLS),yes) + HIREDIS_TLS_CFLAGS := $(shell $(PKG_CONFIG) --cflags hiredis_ssl) + FINAL_CFLAGS+= $(HIREDIS_TLS_CFLAGS) + FINAL_CXXFLAGS+= $(HIREDIS_TLS_CFLAGS) + FINAL_LIBS+= $(shell $(PKG_CONFIG) --libs hiredis_ssl) +endif +else + DEPENDENCY_TARGETS+= hiredis + FINAL_CFLAGS+= -I../deps/hiredis + FINAL_CXXFLAGS+= -I../deps/hiredis + FINAL_LIBS+=../deps/hiredis/libhiredis.a ifeq ($(BUILD_TLS),yes) FINAL_CFLAGS+=-DUSE_OPENSSL $(OPENSSL_CFLAGS) FINAL_CXXFLAGS+=-DUSE_OPENSSL $(OPENSSL_CXXFLAGS) @@ -361,6 +377,7 @@ else endif FINAL_LIBS += ../deps/hiredis/libhiredis_ssl.a $(LIBSSL_LIBS) $(LIBCRYPTO_LIBS) endif +endif ifndef V define MAKE_INSTALL @@ -438,6 +455,7 @@ persist-settings: distclean echo USE_SYSTEM_JEMALLOC=$(USE_SYSTEM_JEMALLOC) >> .make-settings echo BUILD_TLS=$(BUILD_TLS) >> .make-settings echo USE_SYSTEMD=$(USE_SYSTEMD) >> .make-settings + echo USE_SYSTEM_HIREDIS=$(USE_SYSTEM_HIREDIS) >> .make-settings echo CFLAGS=$(CFLAGS) >> .make-settings echo CXXFLAGS=$(CXXFLAGS) >> .make-settings echo LDFLAGS=$(LDFLAGS) >> .make-settings @@ -467,7 +485,7 @@ endif # keydb-server $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) $(KEYDB_SERVER_OBJ) - $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS) + $(REDIS_LD) -o $@ $^ ../deps/lua/src/liblua.a $(FINAL_LIBS) # keydb-sentinel $(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME) @@ -483,15 +501,15 @@ $(REDIS_CHECK_AOF_NAME): $(REDIS_SERVER_NAME) # keydb-cli $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ) - $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS) + $(REDIS_LD) -o $@ $^ ../deps/linenoise/linenoise.o $(FINAL_LIBS) # keydb-benchmark $(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ) - $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/hdr_histogram/hdr_histogram.o $(FINAL_LIBS) + $(REDIS_LD) -o $@ $^ ../deps/hdr_histogram/hdr_histogram.o $(FINAL_LIBS) # keydb-diagnostic-tool $(KEYDB_DIAGNOSTIC_NAME): $(KEYDB_DIAGNOSTIC_OBJ) - $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS) + $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) DEP = $(REDIS_SERVER_OBJ:%.o=%.d) $(KEYDB_SERVER_OBJ:%.o=%.d) $(REDIS_CLI_OBJ:%.o=%.d) $(REDIS_BENCHMARK_OBJ:%.o=%.d) -include $(DEP) diff --git a/src/cli_common.c b/src/cli_common.c index e88327ace..c531c6c98 100644 --- a/src/cli_common.c +++ b/src/cli_common.c @@ -31,7 +31,7 @@ #include "cli_common.h" #include #include -#include /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */ +#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */ #include /* use sds.h from hiredis, so that only one set of sds functions will be present in the binary */ #ifdef USE_OPENSSL #include diff --git a/src/keydb-diagnostic-tool.cpp b/src/keydb-diagnostic-tool.cpp index 2368043b0..43cf116d9 100644 --- a/src/keydb-diagnostic-tool.cpp +++ b/src/keydb-diagnostic-tool.cpp @@ -46,7 +46,7 @@ #include extern "C" { #include /* Use hiredis sds. */ -#include +#include "sdscompat.h" #include "hiredis.h" } #include "ae.h" diff --git a/src/motd.cpp b/src/motd.cpp index 795281734..ba957fa32 100644 --- a/src/motd.cpp +++ b/src/motd.cpp @@ -1,6 +1,6 @@ #ifdef CLIENT extern "C" { -#include +#include "sdscompat.h" #include } #else @@ -19,7 +19,7 @@ extern "C" { #ifdef MOTD #include -#ifdef CLIENT +#if !defined(USE_SYSTEM_HIREDIS) && defined(CLIENT) extern "C" { __attribute__ ((weak)) hisds hi_sdscatlen(hisds s, const void *t, size_t len) { return sdscatlen(s, t, len); diff --git a/src/redis-benchmark.cpp b/src/redis-benchmark.cpp index 34e19c372..538ed5275 100644 --- a/src/redis-benchmark.cpp +++ b/src/redis-benchmark.cpp @@ -44,7 +44,7 @@ #include #include extern "C" { -#include /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */ +#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */ #include /* Use hiredis sds. */ #include } diff --git a/src/redis-cli.c b/src/redis-cli.c index 6d077dbdd..a7a3b8e8a 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -54,7 +54,7 @@ #include #include #endif -#include /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */ +#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */ #include /* use sds.h from hiredis, so that only one set of sds functions will be present in the binary */ #include "adlist.h" #include "zmalloc.h" diff --git a/src/redis-cli.h b/src/redis-cli.h index 677f952c1..858c4e110 100644 --- a/src/redis-cli.h +++ b/src/redis-cli.h @@ -1,6 +1,6 @@ #pragma once #include "cli_common.h" -#include /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */ +#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */ #include #ifdef __cplusplus diff --git a/deps/hiredis/sdscompat.h b/src/sdscompat.h similarity index 98% rename from deps/hiredis/sdscompat.h rename to src/sdscompat.h index e5a2574f3..58e6fdbdf 100644 --- a/deps/hiredis/sdscompat.h +++ b/src/sdscompat.h @@ -42,6 +42,8 @@ #ifndef HIREDIS_SDS_COMPAT #define HIREDIS_SDS_COMPAT +#ifndef USE_SYSTEM_HIREDIS + #define sds hisds #define sdslen hi_sdslen @@ -91,4 +93,6 @@ #define sdsull2str hi_sdsull2str #define sdsupdatelen hi_sdsupdatelen +#endif /* !USE_SYSTEM_HIREDIS */ + #endif /* HIREDIS_SDS_COMPAT */