Skip to content

Commit 0731a05

Browse files
guillemjJohnSully
authored andcommitted
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 bffbbea in redis itself.
1 parent d67c658 commit 0731a05

11 files changed

+38
-99
lines changed

deps/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'),
3434
endif
3535

3636
distclean:
37+
ifneq ($(USE_SYSTEM_HIREDIS),yes)
3738
-(cd hiredis && $(MAKE) clean) > /dev/null || true
39+
endif
3840
-(cd linenoise && $(MAKE) clean) > /dev/null || true
3941
-(cd lua && $(MAKE) clean) > /dev/null || true
4042
ifneq ($(USE_SYSTEM_JEMALLOC),yes)

pkg/deb/debian_dh9/patches/0007-Add-support-for-a-USE_SYSTEM_HIREDIS-flag.patch

-84
This file was deleted.

pkg/deb/debian_dh9/patches/series

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
#debian-packaging/0007-Set-Debian-configuration-defaults.patch
44
#0010-Use-get_current_dir_name-over-PATHMAX-etc.patch
55
#0011-Add-support-for-a-USE_SYSTEM_LUA-flag.patch
6-
#0007-Add-support-for-a-USE_SYSTEM_HIREDIS-flag.patch
76
#test

src/Makefile

+25-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ release_hdr := $(shell sh -c './mkreleasehdr.sh')
2020
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
2121
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
2222
OPTIMIZATION?=-O2 -flto
23-
DEPENDENCY_TARGETS=hiredis linenoise lua hdr_histogram
23+
DEPENDENCY_TARGETS=linenoise lua hdr_histogram
2424
NODEPS:=clean distclean
2525

2626
# Default settings
@@ -274,8 +274,8 @@ ifdef OPENSSL_PREFIX
274274
endif
275275

276276
# Include paths to dependencies
277-
FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram
278-
FINAL_CXXFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram
277+
FINAL_CFLAGS+= -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram
278+
FINAL_CXXFLAGS+= -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram
279279

280280
ifeq ($(USE_SYSTEM_CONCURRENTQUEUE),yes)
281281
FINAL_CXXFLAGS+= -I/usr/include/concurrentqueue/moodycamel
@@ -343,6 +343,22 @@ ifeq ($(MALLOC),memkind)
343343
FINAL_LIBS := ../deps/memkind/src/.libs/libmemkind.a -lnuma $(FINAL_LIBS)
344344
endif
345345

346+
ifeq ($(USE_SYSTEM_HIREDIS),yes)
347+
HIREDIS_CFLAGS := $(shell $(PKG_CONFIG) --cflags hiredis) -DUSE_SYSTEM_HIREDIS=1
348+
FINAL_CFLAGS+= $(HIREDIS_CFLAGS)
349+
FINAL_CXXFLAGS+= $(HIREDIS_CFLAGS)
350+
FINAL_LIBS+= $(shell $(PKG_CONFIG) --libs hiredis)
351+
ifeq ($(BUILD_TLS),yes)
352+
HIREDIS_TLS_CFLAGS := $(shell $(PKG_CONFIG) --cflags hiredis_ssl)
353+
FINAL_CFLAGS+= $(HIREDIS_TLS_CFLAGS)
354+
FINAL_CXXFLAGS+= $(HIREDIS_TLS_CFLAGS)
355+
FINAL_LIBS+= $(shell $(PKG_CONFIG) --libs hiredis_ssl)
356+
endif
357+
else
358+
DEPENDENCY_TARGETS+= hiredis
359+
FINAL_CFLAGS+= -I../deps/hiredis
360+
FINAL_CXXFLAGS+= -I../deps/hiredis
361+
FINAL_LIBS+=../deps/hiredis/libhiredis.a
346362
ifeq ($(BUILD_TLS),yes)
347363
FINAL_CFLAGS+=-DUSE_OPENSSL $(OPENSSL_CFLAGS)
348364
FINAL_CXXFLAGS+=-DUSE_OPENSSL $(OPENSSL_CXXFLAGS)
@@ -361,6 +377,7 @@ else
361377
endif
362378
FINAL_LIBS += ../deps/hiredis/libhiredis_ssl.a $(LIBSSL_LIBS) $(LIBCRYPTO_LIBS)
363379
endif
380+
endif
364381

365382
ifndef V
366383
define MAKE_INSTALL
@@ -438,6 +455,7 @@ persist-settings: distclean
438455
echo USE_SYSTEM_JEMALLOC=$(USE_SYSTEM_JEMALLOC) >> .make-settings
439456
echo BUILD_TLS=$(BUILD_TLS) >> .make-settings
440457
echo USE_SYSTEMD=$(USE_SYSTEMD) >> .make-settings
458+
echo USE_SYSTEM_HIREDIS=$(USE_SYSTEM_HIREDIS) >> .make-settings
441459
echo CFLAGS=$(CFLAGS) >> .make-settings
442460
echo CXXFLAGS=$(CXXFLAGS) >> .make-settings
443461
echo LDFLAGS=$(LDFLAGS) >> .make-settings
@@ -467,7 +485,7 @@ endif
467485

468486
# keydb-server
469487
$(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) $(KEYDB_SERVER_OBJ)
470-
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS)
488+
$(REDIS_LD) -o $@ $^ ../deps/lua/src/liblua.a $(FINAL_LIBS)
471489

472490
# keydb-sentinel
473491
$(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME)
@@ -483,15 +501,15 @@ $(REDIS_CHECK_AOF_NAME): $(REDIS_SERVER_NAME)
483501

484502
# keydb-cli
485503
$(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
486-
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS)
504+
$(REDIS_LD) -o $@ $^ ../deps/linenoise/linenoise.o $(FINAL_LIBS)
487505

488506
# keydb-benchmark
489507
$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
490-
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/hdr_histogram/hdr_histogram.o $(FINAL_LIBS)
508+
$(REDIS_LD) -o $@ $^ ../deps/hdr_histogram/hdr_histogram.o $(FINAL_LIBS)
491509

492510
# keydb-diagnostic-tool
493511
$(KEYDB_DIAGNOSTIC_NAME): $(KEYDB_DIAGNOSTIC_OBJ)
494-
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
512+
$(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
495513

496514
DEP = $(REDIS_SERVER_OBJ:%.o=%.d) $(KEYDB_SERVER_OBJ:%.o=%.d) $(REDIS_CLI_OBJ:%.o=%.d) $(REDIS_BENCHMARK_OBJ:%.o=%.d)
497515
-include $(DEP)

src/cli_common.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "cli_common.h"
3232
#include <errno.h>
3333
#include <hiredis.h>
34-
#include <sdscompat.h> /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
34+
#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
3535
#include <sds.h> /* use sds.h from hiredis, so that only one set of sds functions will be present in the binary */
3636
#ifdef USE_OPENSSL
3737
#include <openssl/ssl.h>

src/keydb-diagnostic-tool.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include <deque>
4747
extern "C" {
4848
#include <sds.h> /* Use hiredis sds. */
49-
#include <sdscompat.h>
49+
#include "sdscompat.h"
5050
#include "hiredis.h"
5151
}
5252
#include "ae.h"

src/motd.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifdef CLIENT
22
extern "C" {
3-
#include <sdscompat.h>
3+
#include "sdscompat.h"
44
#include <sds.h>
55
}
66
#else
@@ -19,7 +19,7 @@ extern "C" {
1919
#ifdef MOTD
2020
#include <curl/curl.h>
2121

22-
#ifdef CLIENT
22+
#if !defined(USE_SYSTEM_HIREDIS) && defined(CLIENT)
2323
extern "C" {
2424
__attribute__ ((weak)) hisds hi_sdscatlen(hisds s, const void *t, size_t len) {
2525
return sdscatlen(s, t, len);

src/redis-benchmark.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include <pthread.h>
4545
#include <string>
4646
extern "C" {
47-
#include <sdscompat.h> /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
47+
#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
4848
#include <sds.h> /* Use hiredis sds. */
4949
#include <hiredis.h>
5050
}

src/redis-cli.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#include <openssl/err.h>
5555
#include <hiredis_ssl.h>
5656
#endif
57-
#include <sdscompat.h> /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
57+
#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
5858
#include <sds.h> /* use sds.h from hiredis, so that only one set of sds functions will be present in the binary */
5959
#include "adlist.h"
6060
#include "zmalloc.h"

src/redis-cli.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
#include "cli_common.h"
3-
#include <sdscompat.h> /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
3+
#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
44
#include <sds.h>
55

66
#ifdef __cplusplus

deps/hiredis/sdscompat.h renamed to src/sdscompat.h

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#ifndef HIREDIS_SDS_COMPAT
4343
#define HIREDIS_SDS_COMPAT
4444

45+
#ifndef USE_SYSTEM_HIREDIS
46+
4547
#define sds hisds
4648

4749
#define sdslen hi_sdslen
@@ -91,4 +93,6 @@
9193
#define sdsull2str hi_sdsull2str
9294
#define sdsupdatelen hi_sdsupdatelen
9395

96+
#endif /* !USE_SYSTEM_HIREDIS */
97+
9498
#endif /* HIREDIS_SDS_COMPAT */

0 commit comments

Comments
 (0)