Skip to content

Commit

Permalink
build: Add support for linking against a system libhiredis/libhiredis…
Browse files Browse the repository at this point in the history
…_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.
  • Loading branch information
guillemj authored and JohnSully committed Mar 26, 2024
1 parent d67c658 commit 0731a05
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 99 deletions.
2 changes: 2 additions & 0 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion pkg/deb/debian_dh9/patches/series
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 25 additions & 7 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -361,6 +377,7 @@ else
endif
FINAL_LIBS += ../deps/hiredis/libhiredis_ssl.a $(LIBSSL_LIBS) $(LIBCRYPTO_LIBS)
endif
endif

ifndef V
define MAKE_INSTALL
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/cli_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "cli_common.h"
#include <errno.h>
#include <hiredis.h>
#include <sdscompat.h> /* 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 <sds.h> /* use sds.h from hiredis, so that only one set of sds functions will be present in the binary */
#ifdef USE_OPENSSL
#include <openssl/ssl.h>
Expand Down
2 changes: 1 addition & 1 deletion src/keydb-diagnostic-tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include <deque>
extern "C" {
#include <sds.h> /* Use hiredis sds. */
#include <sdscompat.h>
#include "sdscompat.h"
#include "hiredis.h"
}
#include "ae.h"
Expand Down
4 changes: 2 additions & 2 deletions src/motd.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef CLIENT
extern "C" {
#include <sdscompat.h>
#include "sdscompat.h"
#include <sds.h>
}
#else
Expand All @@ -19,7 +19,7 @@ extern "C" {
#ifdef MOTD
#include <curl/curl.h>

#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);
Expand Down
2 changes: 1 addition & 1 deletion src/redis-benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include <pthread.h>
#include <string>
extern "C" {
#include <sdscompat.h> /* 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 <sds.h> /* Use hiredis sds. */
#include <hiredis.h>
}
Expand Down
2 changes: 1 addition & 1 deletion src/redis-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#include <openssl/err.h>
#include <hiredis_ssl.h>
#endif
#include <sdscompat.h> /* 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 <sds.h> /* 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"
Expand Down
2 changes: 1 addition & 1 deletion src/redis-cli.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "cli_common.h"
#include <sdscompat.h> /* 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 <sds.h>

#ifdef __cplusplus
Expand Down
4 changes: 4 additions & 0 deletions deps/hiredis/sdscompat.h → src/sdscompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#ifndef HIREDIS_SDS_COMPAT
#define HIREDIS_SDS_COMPAT

#ifndef USE_SYSTEM_HIREDIS

#define sds hisds

#define sdslen hi_sdslen
Expand Down Expand Up @@ -91,4 +93,6 @@
#define sdsull2str hi_sdsull2str
#define sdsupdatelen hi_sdsupdatelen

#endif /* !USE_SYSTEM_HIREDIS */

#endif /* HIREDIS_SDS_COMPAT */

0 comments on commit 0731a05

Please sign in to comment.