Skip to content

Commit

Permalink
Split hiredis from Redis and use it directly (ray-project#9176)
Browse files Browse the repository at this point in the history
* Split hiredis from Redis and use it directly

Co-authored-by: Mehrdad <[email protected]>
  • Loading branch information
mehrdadn and web-flow committed Jun 30, 2020
1 parent eb8eb2c commit 79c4c67
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 38 deletions.
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ cc_library(

alias(
name = "hiredis",
actual = "@com_github_antirez_redis//:hiredis",
actual = "@com_github_redis_hiredis//:hiredis",
)

cc_library(
Expand Down
49 changes: 49 additions & 0 deletions bazel/BUILD.hiredis
Original file line number Diff line number Diff line change
@@ -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"],
)
18 changes: 0 additions & 18 deletions bazel/BUILD.redis
Original file line number Diff line number Diff line change
@@ -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(["**"]),
Expand All @@ -25,7 +17,6 @@ cc_library(
hdrs = [
"deps/hiredis/dict.c",
],
copts = COPTS,
strip_include_prefix = "deps/hiredis",
)

Expand All @@ -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"],
)
11 changes: 10 additions & 1 deletion bazel/ray_deps_setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
6 changes: 3 additions & 3 deletions thirdparty/patches/hiredis-connect-rename.patch
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions thirdparty/patches/hiredis-windows-sigpipe.patch
Original file line number Diff line number Diff line change
@@ -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). */
Expand Down
18 changes: 9 additions & 9 deletions thirdparty/patches/hiredis-windows-sockets.patch
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions thirdparty/patches/hiredis-windows-strerror.patch
Original file line number Diff line number Diff line change
@@ -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) \
Expand Down

0 comments on commit 79c4c67

Please sign in to comment.