From f7415b37c5da36b3f25ed11d0fac94a9131ff33b Mon Sep 17 00:00:00 2001 From: Philipp Moritz Date: Sun, 27 Jan 2019 18:32:04 -0800 Subject: [PATCH] Build Ray with Bazel (#3867) --- BUILD.bazel | 165 ++++++++++++++++++++++++++++++++++++++++++++- WORKSPACE | 15 ++++- bazel/BUILD.glog | 84 +++++++++++++++++++++++ bazel/BUILD.plasma | 2 +- bazel/ray.bzl | 13 ++++ 5 files changed, 276 insertions(+), 3 deletions(-) create mode 100644 bazel/BUILD.glog create mode 100644 bazel/ray.bzl diff --git a/BUILD.bazel b/BUILD.bazel index afb957b5e..e0f8c835b 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -2,8 +2,11 @@ # C/C++ documentation: https://docs.bazel.build/versions/master/be/c-cpp.html load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library") +load("@//bazel:ray.bzl", "flatbuffer_py_library") load("@//bazel:cython_library.bzl", "pyx_library") +COPTS = ["-DRAY_USE_GLOG"] + cc_binary( name = "raylet", srcs = ["src/ray/raylet/main.cc"], @@ -11,6 +14,7 @@ cc_binary( ":ray_util", ":raylet_lib", ], + copts = COPTS, ) cc_binary( @@ -24,6 +28,7 @@ cc_binary( ":gcs", ":ray_util", ], + copts = COPTS, ) cc_library( @@ -49,6 +54,7 @@ cc_library( "@plasma//:plasma_client", "@com_google_googletest//:gtest", ], + copts = COPTS, ) cc_test( @@ -59,6 +65,7 @@ cc_test( ":node_manager_fbs", ":raylet_lib", ], + copts = COPTS, ) cc_test( @@ -70,6 +77,7 @@ cc_test( ":object_manager", ":raylet_lib" ], + copts = COPTS, ) cc_test( @@ -79,6 +87,7 @@ cc_test( "@com_google_googletest//:gtest_main", ":raylet_lib", ], + copts = COPTS, ) cc_test( @@ -88,6 +97,7 @@ cc_test( "@com_google_googletest//:gtest_main", ":ray_util", ], + copts = COPTS, ) cc_test( @@ -97,6 +107,7 @@ cc_test( "@com_google_googletest//:gtest_main", ":raylet_lib" ], + copts = COPTS, ) cc_test( @@ -106,6 +117,7 @@ cc_test( "@com_google_googletest//:gtest_main", ":raylet_lib", ], + copts = COPTS, ) cc_library( @@ -127,6 +139,7 @@ cc_library( "@boost//:asio", "@plasma//:plasma_client" ], + copts = COPTS, ) cc_binary( @@ -137,6 +150,7 @@ cc_binary( "@com_google_googletest//:gtest_main", ":object_manager", ], + copts = COPTS, ) cc_binary( @@ -147,6 +161,7 @@ cc_binary( "@com_google_googletest//:gtest_main", ":object_manager", ], + copts = COPTS, ) cc_library( @@ -167,8 +182,10 @@ cc_library( ], deps = [ "@plasma//:plasma_client", + "@com_github_google_glog//:glog", ":sha256" - ] + ], + copts = COPTS, ) cc_library( @@ -190,6 +207,7 @@ cc_library( ":ray_util", "@boost//:asio", ], + copts = COPTS, ) cc_library( @@ -247,6 +265,7 @@ cc_library( ":hiredis", "@boost//:asio", ], + copts = COPTS, ) cc_binary( @@ -257,6 +276,7 @@ cc_binary( ":gcs", "@com_google_googletest//:gtest_main", ], + copts = COPTS, ) cc_binary( @@ -268,6 +288,7 @@ cc_binary( "@com_google_googletest//:gtest_main", ":ray_util", ], + copts = COPTS, ) FLATC_ARGS = [ @@ -316,3 +337,145 @@ pyx_library( ]), deps = ["//:raylet_lib"] ) + +flatbuffer_py_library( + name = "python_gcs_fbs", + srcs = [ + "src/ray/gcs/format/gcs.fbs" + ], + outs = [ + "ActorState.py", + "ActorTableData.py", + "Arg.py", + "ClassTableData.py", + "ClientTableData.py", + "ConfigTableData.py", + "CustomSerializerData.py", + "DriverTableData.py", + "ErrorTableData.py", + "FunctionTableData.py", + "GcsTableEntry.py", + "HeartbeatBatchTableData.py", + "HeartbeatTableData.py", + "Language.py", + "ObjectTableData.py", + "ProfileEvent.py", + "ProfileTableData.py", + "RayResource.py", + "ResourcePair.py", + "SchedulingState.py", + "TablePrefix.py", + "TablePubsub.py", + "TaskInfo.py", + "TaskLeaseData.py", + "TaskReconstructionData.py", + "TaskTableData.py", + "TaskTableTestAndUpdate.py", + ], + out_prefix = "python/ray/core/generated/", +) + +flatbuffer_py_library( + name = "python_node_manager_fbs", + srcs = [ + "src/ray/raylet/format/node_manager.fbs" + ], + outs = [ + "ray/protocol/DisconnectClient.py", + "ray/protocol/FetchOrReconstruct.py", + "ray/protocol/ForwardTaskRequest.py", + "ray/protocol/FreeObjectsRequest.py", + "ray/protocol/GetTaskReply.py", + "ray/protocol/MessageType.py", + "ray/protocol/NotifyUnblocked.py", + "ray/protocol/PushErrorRequest.py", + "ray/protocol/RegisterClientReply.py", + "ray/protocol/RegisterClientRequest.py", + "ray/protocol/RegisterNodeManagerRequest.py", + "ray/protocol/ResourceIdSetInfo.py", + "ray/protocol/SubmitTaskRequest.py", + "ray/protocol/Task.py", + "ray/protocol/TaskExecutionSpecification.py", + "ray/protocol/WaitReply.py", + "ray/protocol/WaitRequest.py" + ], + out_prefix = "python/ray/core/generated/", + include_paths = [ + "src/ray/gcs/format/" + ], + includes = ["src/ray/gcs/format/gcs.fbs"] +) + +filegroup( + name = "python_sources", + srcs = glob([ + "python/ray/*.py", + "python/ray/autoscaler/*.py", + "python/ray/cloudpickle/*.py", + "python/ray/core/__init__.py", + "python/ray/core/generated/__init__.py", + "python/ray/core/generated/ray/__init__.py", + "python/ray/core/generated/ray/protocol/__init__.py", + "python/ray/experimental/*.py", + "python/ray/internal/*.py", + "python/ray/WebUI.ipynb", + "python/ray/workers/default_worker.py" + ]) +) + +genrule( + name = "redis", + cmd = """ + set -x && + curl -sL \"https://github.com/antirez/redis/archive/5.0.3.tar.gz\" | tar xz --strip-components=1 -C . && + make && + mv ./src/redis-server $(location redis-server) + """, + outs = ["redis-server"] +) + +cc_library( + name = "ray_redis_module", + hdrs = [ + "src/ray/gcs/redis_module/redismodule.h", + "src/ray/gcs/redis_module/redis_string.h" + ], + srcs = [ + "src/ray/gcs/redis_module/ray_redis_module.cc", + "src/ray/util/logging.cc" + ], + deps = [ + ":ray_common" + ] +) + +genrule( + name = "ray_pkg", + srcs = [ + "python/ray/_raylet.so", + "//:python_sources", + "//:python_gcs_fbs", + "//:python_node_manager_fbs", + "//:redis-server", + "//:ray_redis_module", + "//:raylet", + "//:raylet_monitor", + "@plasma//:plasma_store_server" + ], + outs = ["ray_pkg"], + cmd = """ + set -x && + mkdir -p python/ray && + cp $(location python/ray/_raylet.so) python/ray && + mkdir -p python/ray/core/src/ray/thirdparty/redis/src/ && + cp $(location //:redis-server) python/ray/core/src/ray/thirdparty/redis/src/ && + mkdir -p python/ray/core/src/ray/gcs/redis_module/ && + for f in $(locations //:ray_redis_module); do cp $$f python/ray/core/src/ray/gcs/redis_module/; done && + mkdir -p python/ray/core/src/ray/raylet/ && + cp $(location //:raylet_monitor) python/ray/core/src/ray/raylet/ && + mkdir -p python/ray/core/src/plasma && + cp $(location @plasma//:plasma_store_server) python/ray/core/src/plasma/ && + cp $(location //:raylet) python/ray/core/src/ray/raylet/ && + mv python $(location ray_pkg) + """, +) diff --git a/WORKSPACE b/WORKSPACE index 2074dcdf1..7e307d7f9 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -21,11 +21,24 @@ git_repository( commit = "3306848f697568aacf4bcca330f6bdd5ce671899", ) +git_repository( + name = "com_github_gflags_gflags", + remote = "https://github.com/gflags/gflags.git", + tag = "v2.2.2", +) + +new_git_repository( + name = "com_github_google_glog", + build_file = "//bazel:BUILD.glog", + remote = "https://github.com/google/glog.git", + tag = "v0.3.5", +) + new_git_repository( name = "plasma", build_file = "@//bazel:BUILD.plasma", remote = "https://github.com/ray-project/arrow", - commit = "f5d1be2fed69899aea636bd074aaeaa4149acc79", + commit = "6a27c660ea700febf6fd73b2e851ab96e9315134", ) new_git_repository( diff --git a/bazel/BUILD.glog b/bazel/BUILD.glog new file mode 100644 index 000000000..80c71f35c --- /dev/null +++ b/bazel/BUILD.glog @@ -0,0 +1,84 @@ +# This file is from https://github.com/google/or-tools/blob/master/bazel/glog.BUILD + +cc_library( + name = "glog", + srcs = [ + "config.h", + "src/base/commandlineflags.h", + "src/base/googleinit.h", + "src/base/mutex.h", + "src/demangle.cc", + "src/demangle.h", + "src/logging.cc", + "src/raw_logging.cc", + "src/signalhandler.cc", + "src/symbolize.cc", + "src/symbolize.h", + "src/utilities.cc", + "src/utilities.h", + "src/vlog_is_on.cc", + ] + glob(["src/stacktrace*.h"]), + hdrs = [ + "src/glog/log_severity.h", + "src/glog/logging.h", + "src/glog/raw_logging.h", + "src/glog/stl_logging.h", + "src/glog/vlog_is_on.h", + ], + copts = [ + "-Wno-sign-compare", + "-U_XOPEN_SOURCE", + ], + includes = ["./src"], + linkopts = ["-lpthread"] + select({ + ":libunwind": ["-lunwind"], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], + deps = [ + "@com_github_gflags_gflags//:gflags", + ], +) + +config_setting( + name = "libunwind", + values = { + "define": "libunwind=true", + }, +) + +genrule( + name = "run_configure", + srcs = [ + "README", + "Makefile.in", + "config.guess", + "config.sub", + "install-sh", + "ltmain.sh", + "missing", + "libglog.pc.in", + "src/config.h.in", + "src/glog/logging.h.in", + "src/glog/raw_logging.h.in", + "src/glog/stl_logging.h.in", + "src/glog/vlog_is_on.h.in", + ], + outs = [ + "config.h", + "src/glog/logging.h", + "src/glog/raw_logging.h", + "src/glog/stl_logging.h", + "src/glog/vlog_is_on.h", + ], + tools = [ + "configure", + ], + cmd = "$(location :configure)" + + "&& cp -v src/config.h $(location config.h) " + + "&& cp -v src/glog/logging.h $(location src/glog/logging.h) " + + "&& cp -v src/glog/raw_logging.h $(location src/glog/raw_logging.h) " + + "&& cp -v src/glog/stl_logging.h $(location src/glog/stl_logging.h) " + + "&& cp -v src/glog/vlog_is_on.h $(location src/glog/vlog_is_on.h) " + , +) diff --git a/bazel/BUILD.plasma b/bazel/BUILD.plasma index be6c6d55f..6a91b20a9 100644 --- a/bazel/BUILD.plasma +++ b/bazel/BUILD.plasma @@ -86,7 +86,7 @@ cc_library( cc_binary( - name = "plasma_server", + name = "plasma_store_server", visibility = ["//visibility:public"], srcs = glob([ "cpp/src/plasma/store.cc", diff --git a/bazel/ray.bzl b/bazel/ray.bzl new file mode 100644 index 000000000..92af31621 --- /dev/null +++ b/bazel/ray.bzl @@ -0,0 +1,13 @@ +load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_library_public") + +def flatbuffer_py_library(name, srcs, outs, out_prefix, includes = [], include_paths = ""): + + flatbuffer_library_public( + name = name, + srcs = srcs, + outs = outs, + language_flag = "-p", + out_prefix = out_prefix, + include_paths = include_paths, + includes = includes, + )