Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add support to use system libraries #803

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ 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)
-(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true
endif
ifneq ($(USE_SYSTEM_ROCKSDB),yes)
-(cd rocksdb && $(MAKE) clean) > /dev/null || true
endif
-(cd hdr_histogram && $(MAKE) clean) > /dev/null || true
-(rm -f .make-*)

Expand Down

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/deb/debian_dh9/patches/series
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
#debian-packaging/0003-dpkg-buildflags.patch
#debian-packaging/0007-Set-Debian-configuration-defaults.patch
#0010-Use-get_current_dir_name-over-PATHMAX-etc.patch
#0010-Add-support-for-USE_SYSTEM_JEMALLOC-flag.patch
#0011-Add-support-for-a-USE_SYSTEM_LUA-flag.patch
#0007-Add-support-for-a-USE_SYSTEM_HIREDIS-flag.patch
#test
55 changes: 47 additions & 8 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 @@ -73,12 +73,19 @@ ifneq ($(strip $(SANITIZE)),)
endif

ifeq ($(ENABLE_FLASH),yes)
STORAGE_OBJ+= storage/rocksdb.o storage/rocksdbfactory.o
ifeq ($(USE_SYSTEM_ROCKSDB),yes)
FINAL_LIBS+= $(shell pkg-config --libs rocksdb)
FINAL_CXXFLAGS+= $(shell pkg-config --cflags rocksdb) -DENABLE_ROCKSDB

else
FINAL_LIBS+= -lz -lcrypto -lbz2 -lzstd -llz4 -lsnappy
CXXFLAGS+= -I../deps/rocksdb/include/ -DENABLE_ROCKSDB
STORAGE_OBJ+= storage/rocksdb.o storage/rocksdbfactory.o
FINAL_CXXFLAGS+= -I../deps/rocksdb/include/
FINAL_LIBS+= ../deps/rocksdb/librocksdb.a
DEPENDENCY_TARGETS+= rocksdb
endif
endif


ifeq ($(CHECKED),true)
Expand Down Expand Up @@ -267,8 +274,14 @@ 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 -I../deps/rocksdb/include/ -I../deps/concurrentqueue
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
else
FINAL_CXXFLAGS+= -I../deps/concurrentqueue
endif

# Determine systemd support and/or build preference (defaulting to auto-detection)
BUILD_WITH_SYSTEMD=no
Expand Down Expand Up @@ -311,11 +324,17 @@ ifeq ($(MALLOC),tcmalloc_minimal)
endif

ifeq ($(MALLOC),jemalloc)
ifeq ($(USE_SYSTEM_JEMALLOC),yes)
FINAL_CFLAGS+= -DUSE_JEMALLOC $(shell $(PKG_CONFIG) --cflags jemalloc)
FINAL_CXXFLAGS+= -DUSE_JEMALLOC $(shell $(PKG_CONFIG) --cflags jemalloc)
FINAL_LIBS := $(shell $(PKG_CONFIG) --libs jemalloc) $(FINAL_LIBS)
else
DEPENDENCY_TARGETS+= jemalloc
FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
FINAL_CXXFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
FINAL_LIBS := ../deps/jemalloc/lib/libjemalloc.a $(FINAL_LIBS)
endif
endif

ifeq ($(MALLOC),memkind)
DEPENDENCY_TARGETS+= memkind
Expand All @@ -324,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 @@ -342,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 @@ -414,9 +450,12 @@ persist-settings: distclean
echo STD=$(STD) >> .make-settings
echo WARN=$(WARN) >> .make-settings
echo OPT=$(OPT) >> .make-settings
echo USE_SYSTEM_CONCURRENTQUEUE=$(USE_SYSTEM_CONCURRENTQUEUE) >> .make-settings
echo MALLOC=$(MALLOC) >> .make-settings
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 @@ -446,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 @@ -462,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
Loading
Loading