From 79c4c67ed9678235a7b6604d027cf5ce3f797445 Mon Sep 17 00:00:00 2001 From: mehrdadn Date: Mon, 29 Jun 2020 18:16:32 -0700 Subject: [PATCH] Split hiredis from Redis and use it directly (#9176) * Split hiredis from Redis and use it directly Co-authored-by: Mehrdad --- BUILD.bazel | 2 +- bazel/BUILD.hiredis | 49 +++++++++++++++++++ bazel/BUILD.redis | 18 ------- bazel/ray_deps_setup.bzl | 11 ++++- .../patches/hiredis-connect-rename.patch | 6 +-- .../patches/hiredis-windows-sigpipe.patch | 6 +-- .../patches/hiredis-windows-sockets.patch | 18 +++---- .../patches/hiredis-windows-strerror.patch | 6 +-- 8 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 bazel/BUILD.hiredis diff --git a/BUILD.bazel b/BUILD.bazel index f84528082..6a63cf12a 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1333,7 +1333,7 @@ cc_library( alias( name = "hiredis", - actual = "@com_github_antirez_redis//:hiredis", + actual = "@com_github_redis_hiredis//:hiredis", ) cc_library( diff --git a/bazel/BUILD.hiredis b/bazel/BUILD.hiredis new file mode 100644 index 000000000..e97413d9d --- /dev/null +++ b/bazel/BUILD.hiredis @@ -0,0 +1,49 @@ +COPTS = [] + select({ + "@bazel_tools//src/conditions:windows": [ + "-D_CRT_DECLARE_NONSTDC_NAMES=0", # don't define off_t, to avoid conflicts + ], + "//conditions:default": [ + ], +}) + +# This library is for internal hiredis use, because hiredis assumes a +# different include prefix for itself than external libraries do. +cc_library( + name = "_hiredis", + hdrs = [ + "dict.c", + ], + copts = COPTS, +) + +cc_library( + name = "hiredis", + srcs = glob( + [ + "*.c", + "*.h", + ], + exclude = + [ + "test.c", + ], + ), + hdrs = glob([ + "*.h", + "adapters/*.h", + ]), + copts = COPTS + select({ + "@bazel_tools//src/conditions:windows": [ + "-D" + "WIN32_REPLACE_FD_APIS", + "/FI" + "win32fd.h", + ], + "//conditions:default": [ + ], + }), + include_prefix = "hiredis", + deps = [ + ":_hiredis", + "@//:platform_shims", + ], + visibility = ["//visibility:public"], +) diff --git a/bazel/BUILD.redis b/bazel/BUILD.redis index 6f84f7ab9..e0f2bb4fe 100644 --- a/bazel/BUILD.redis +++ b/bazel/BUILD.redis @@ -1,11 +1,3 @@ -COPTS = [] + select({ - "@bazel_tools//src/conditions:windows": [ - "-D_CRT_DECLARE_NONSTDC_NAMES=0", # don't define off_t, to avoid conflicts - ], - "//conditions:default": [ - ], -}) - filegroup( name = "files", srcs = glob(["**"]), @@ -25,7 +17,6 @@ cc_library( hdrs = [ "deps/hiredis/dict.c", ], - copts = COPTS, strip_include_prefix = "deps/hiredis", ) @@ -45,19 +36,10 @@ cc_library( "deps/hiredis/*.h", "deps/hiredis/adapters/*.h", ]), - copts = COPTS + select({ - "@bazel_tools//src/conditions:windows": [ - "-D" + "WIN32_REPLACE_FD_APIS", - "/FI" + "win32fd.h", - ], - "//conditions:default": [ - ], - }), includes = ["deps/hiredis"], strip_include_prefix = "deps", deps = [ ":_hiredis", - "@//:platform_shims", ], visibility = ["//visibility:public"], ) diff --git a/bazel/ray_deps_setup.bzl b/bazel/ray_deps_setup.bzl index a159295b1..9a04a0f3e 100644 --- a/bazel/ray_deps_setup.bzl +++ b/bazel/ray_deps_setup.bzl @@ -81,12 +81,21 @@ def ray_deps_setup(): build_file = "//bazel:BUILD.redis", url = "https://github.com/antirez/redis/archive/5.0.9.tar.gz", sha256 = "db9bf149e237126f9bb5f40fb72f33701819555d06f16e9a38b4949794214201", + patches = [ + "//thirdparty/patches:redis-quiet.patch", + ], + ) + + auto_http_archive( + name = "com_github_redis_hiredis", + build_file = "//bazel:BUILD.hiredis", + url = "https://github.com/redis/hiredis/archive/33152ad163a21f568fb40eeeb88b79365886b4ea.tar.gz", + sha256 = "9a91274dfd131111227b39ffa3cf7b446fbbd7ee2e5a94c8e7d8ad334b4ff255", patches = [ "//thirdparty/patches:hiredis-connect-rename.patch", "//thirdparty/patches:hiredis-windows-sigpipe.patch", "//thirdparty/patches:hiredis-windows-sockets.patch", "//thirdparty/patches:hiredis-windows-strerror.patch", - "//thirdparty/patches:redis-quiet.patch", ], ) diff --git a/thirdparty/patches/hiredis-connect-rename.patch b/thirdparty/patches/hiredis-connect-rename.patch index 55428033d..6a95d5057 100644 --- a/thirdparty/patches/hiredis-connect-rename.patch +++ b/thirdparty/patches/hiredis-connect-rename.patch @@ -1,6 +1,6 @@ -diff --git deps/hiredis/test.c deps/hiredis/test.c ---- deps/hiredis/test.c -+++ deps/hiredis/test.c +diff --git test.c test.c +--- test.c ++++ test.c @@ -94,1 +94,1 @@ -static redisContext *connect(struct config config) { +static redisContext *connect_(struct config config) { diff --git a/thirdparty/patches/hiredis-windows-sigpipe.patch b/thirdparty/patches/hiredis-windows-sigpipe.patch index babe2fe4a..bcfa5055e 100644 --- a/thirdparty/patches/hiredis-windows-sigpipe.patch +++ b/thirdparty/patches/hiredis-windows-sigpipe.patch @@ -1,6 +1,6 @@ -diff --git deps/hiredis/test.c deps/hiredis/test.c ---- deps/hiredis/test.c -+++ deps/hiredis/test.c +diff --git test.c test.c +--- test.c ++++ test.c @@ -762,2 +762,4 @@ int main(int argc, char **argv) { +#ifndef _WIN32 /* Ignore broken pipe signal (for I/O error tests). */ diff --git a/thirdparty/patches/hiredis-windows-sockets.patch b/thirdparty/patches/hiredis-windows-sockets.patch index 5fc463bcc..f458083b2 100644 --- a/thirdparty/patches/hiredis-windows-sockets.patch +++ b/thirdparty/patches/hiredis-windows-sockets.patch @@ -1,21 +1,21 @@ -diff --git deps/hiredis/hiredis.c deps/hiredis/hiredis.c ---- deps/hiredis/hiredis.c -+++ deps/hiredis/hiredis.c +diff --git hiredis.c hiredis.c +--- hiredis.c ++++ hiredis.c @@ -620,1 +620,1 @@ - close(c->fd); + redisContextCloseFd(c); @@ -648,1 +648,1 @@ - close(c->fd); + redisContextCloseFd(c); -diff --git deps/hiredis/net.h deps/hiredis/net.h ---- deps/hiredis/net.h -+++ deps/hiredis/net.h +diff --git net.h net.h +--- net.h ++++ net.h @@ -44,1 +44,2 @@ +void redisContextCloseFd(redisContext *c); int redisContextConnectTcp(redisContext *c, const char *addr, int port, const struct timeval *timeout); -diff --git deps/hiredis/net.c deps/hiredis/net.c ---- deps/hiredis/net.c -+++ deps/hiredis/net.c +diff --git net.c net.c +--- net.c ++++ net.c @@ -60,1 +60,1 @@ -static void redisContextCloseFd(redisContext *c) { +void redisContextCloseFd(redisContext *c) { diff --git a/thirdparty/patches/hiredis-windows-strerror.patch b/thirdparty/patches/hiredis-windows-strerror.patch index c2fb4a7bf..c650d4dcd 100644 --- a/thirdparty/patches/hiredis-windows-strerror.patch +++ b/thirdparty/patches/hiredis-windows-strerror.patch @@ -1,6 +1,6 @@ -diff --git deps/hiredis/hiredis.h deps/hiredis/hiredis.h ---- deps/hiredis/hiredis.h -+++ deps/hiredis/hiredis.h +diff --git hiredis.h hiredis.h +--- hiredis.h ++++ hiredis.h @@ -87,5 +87,12 @@ +#ifdef _WIN32 +#define __redis_strerror_r(errno, buf, len) \