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

Build Raylet with Bazel #3806

Merged
merged 30 commits into from
Jan 20, 2019
Merged
Show file tree
Hide file tree
Changes from 27 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
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ matrix:
script:
- ./java/test.sh

# Test Bazel build
- ./.travis/install-bazel.sh
- bazel build ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to put it here for now, but this is temporary, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, eventually everything should be switched, for now it just makes sure it doesn't get broken. This is the build matrix entry that is the least loaded (aside from linting) and has java already installed, so it's the natural candidate.


- os: linux
dist: trusty
env: LINT=1 PYTHONWARNINGS=ignore
Expand Down
13 changes: 13 additions & 0 deletions .travis/install-bazel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Cause the script to exit if a single command fails
set -e

OS=linux
ARCH=x86_64
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then OS=darwin; fi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly not a huge deal, but might as well make this script run outside of Travis. The way we normally detect OS in Travis is

platform="unknown"
unamestr="$(uname)"
if [[ "$unamestr" == "Linux" ]]; then
echo "Platform is linux."
platform="linux"
elif [[ "$unamestr" == "Darwin" ]]; then
echo "Platform is macosx."
platform="macosx"
else
echo "Unrecognized platform."
exit 1
fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea yeah, I fixed it

URL="https://github.com/bazelbuild/bazel/releases/download/0.21.0/bazel-0.21.0-installer-${OS}-x86_64.sh"
wget -O install.sh $URL
chmod +x install.sh
./install.sh --user
rm -f install.sh
309 changes: 309 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
# Bazel build
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to prefer BUILD or BUILD.bazel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, BUILD wouldn't work because we already have a build directory and macOS is case-insensitive (I found out the hard way)

# C/C++ documentation: https://docs.bazel.build/versions/master/be/c-cpp.html

load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")

cc_binary(
name = "raylet",
srcs = ["src/ray/raylet/main.cc"],
deps = [
":ray_util",
":raylet_lib",
],
)

cc_binary(
name = "raylet_monitor",
srcs = [
"src/ray/raylet/monitor.cc",
"src/ray/raylet/monitor.h",
"src/ray/raylet/monitor_main.cc",
],
deps = [
":gcs",
":ray_util",
],
)

cc_library(
name = "raylet_lib",
srcs = glob(
[
"src/ray/raylet/*.cc",
],
exclude = [
"src/ray/raylet/mock_gcs_client.cc",
"src/ray/raylet/monitor_main.cc",
"src/ray/raylet/*_test.cc",
],
),
hdrs = glob([
"src/ray/raylet/*.h",
],),
deps = [
":gcs",
":gcs_fbs",
":node_manager_fbs",
":object_manager",
":ray_common",
":ray_util",
"@boost//:asio",
"@plasma",
"@com_google_googletest//:gtest",
],
)

cc_test(
name = "lineage_cache_test",
srcs = ["src/ray/raylet/lineage_cache_test.cc"],
deps = [
"@com_google_googletest//:gtest_main",
":node_manager_fbs",
":raylet_lib",
],
)

cc_test(
name = "reconstruction_policy_test",
srcs = ["src/ray/raylet/reconstruction_policy_test.cc"],
deps = [
"@com_google_googletest//:gtest_main",
":node_manager_fbs",
":object_manager",
":raylet_lib"
],
)

cc_test(
name = "worker_pool_test",
srcs = ["src/ray/raylet/worker_pool_test.cc"],
deps = [
"@com_google_googletest//:gtest_main",
":raylet_lib",
],
)

cc_test(
name = "logging_test",
srcs = ["src/ray/util/logging_test.cc"],
deps = [
"@com_google_googletest//:gtest_main",
":ray_util",
],
)

cc_test(
name = "task_dependency_manager_test",
srcs = ["src/ray/raylet/task_dependency_manager_test.cc"],
deps = [
"@com_google_googletest//:gtest_main",
":raylet_lib"
],
)

cc_test(
name = "task_test",
srcs = ["src/ray/raylet/task_test.cc"],
deps = [
"@com_google_googletest//:gtest_main",
":raylet_lib",
],
)

cc_library(
name = "object_manager",
srcs = glob([
"src/ray/object_manager/*.cc",
]),
hdrs = glob([
"src/ray/object_manager/*.h",
]),
includes = [
"src",
],
deps = [
":gcs",
":object_manager_fbs",
":ray_common",
":ray_util",
"@boost//:asio",
"@plasma"
],
)

cc_binary(
name = "object_manager_test",
testonly = 1,
srcs = ["src/ray/object_manager/test/object_manager_test.cc"],
deps = [
"@com_google_googletest//:gtest_main",
":object_manager",
],
)

cc_binary(
name = "object_manager_stress_test",
testonly = 1,
srcs = ["src/ray/object_manager/test/object_manager_stress_test.cc"],
deps = [
"@com_google_googletest//:gtest_main",
":object_manager",
],
)

cc_library(
name = "ray_util",
srcs = glob(
[
"src/ray/*.cc",
"src/ray/util/*.cc",
],
exclude = [
"src/ray/util/logging_test.cc",
"src/ray/util/signal_test.cc"
],
),
hdrs = glob([
"src/ray/*.h",
"src/ray/util/*.h",
]),
includes = [
"src",
],
deps = [
"@plasma",
":sha256"
]
)

cc_library(
name = "ray_common",
srcs = ["src/ray/common/client_connection.cc",
"src/ray/common/common_protocol.cc"],
hdrs = ["src/ray/common/client_connection.h",
"src/ray/common/common_protocol.h"],
includes = [
"src/ray/gcs/format",
],
deps = [
":gcs_fbs",
":node_manager_fbs",
":ray_util",
"@boost//:asio",
],
)

cc_library(
name = "sha256",
srcs = [
"src/ray/thirdparty/sha256.c",
],
hdrs = [
"src/ray/thirdparty/sha256.h",
],
includes = ["src/ray/thirdparty"],
)

cc_library(
name = "hiredis",
srcs = glob([
"src/ray/thirdparty/ae/ae.c",
"src/ray/thirdparty/hiredis/*.c",
], exclude = ["src/ray/thirdparty/hiredis/test.c"]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exclude should probably be on a new line

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe not? not sure what the proper formatting is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exclude is part of the glob command so it makes sense to me to have it on the same line

hdrs = glob([
"src/ray/thirdparty/ae/*.h",
"src/ray/thirdparty/hiredis/*.h",
"src/ray/thirdparty/hiredis/adapters/*.h",
"src/ray/thirdparty/hiredis/dict.c",
"src/ray/thirdparty/ae/ae_kqueue.c",
"src/ray/thirdparty/ae/ae_epoll.c",
]),
includes = [
"src/ray/thirdparty/hiredis",
"src/ray/thirdparty/ae",
],
)

cc_library(
name = "gcs",
srcs = glob(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting here is a bit different from before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to make it more consistent

[
"src/ray/gcs/*.cc",
],
exclude = [
"src/ray/gcs/*_test.cc",
],
),
hdrs = glob([
"src/ray/gcs/*.h",
"src/ray/gcs/format/*.h",
]),
includes = [
"src/ray/gcs/format",
],
deps = [
":gcs_fbs",
":node_manager_fbs",
":ray_util",
":ray_common",
":hiredis",
"@boost//:asio",
],
)

cc_binary(
name = "gcs_client_test",
testonly = 1,
srcs = ["src/ray/gcs/client_test.cc"],
deps = [
":gcs",
"@com_google_googletest//:gtest_main",
],
)

cc_binary(
name = "asio_test",
testonly = 1,
srcs = ["src/ray/gcs/asio_test.cc"],
deps = [
":gcs",
"@com_google_googletest//:gtest_main",
":ray_util",
],
)

FLATC_ARGS = [
"--gen-object-api",
"--gen-mutable",
"--scoped-enums",
]

flatbuffer_cc_library(
name = "gcs_fbs",
srcs = ["src/ray/gcs/format/gcs.fbs"],
flatc_args = FLATC_ARGS,
out_prefix = "src/ray/gcs/format/",
)

flatbuffer_cc_library(
name = "common_fbs",
srcs = ["@plasma//:cpp/src/plasma/format/common.fbs"],
flatc_args = FLATC_ARGS,
out_prefix = "src/ray/common/"
)

flatbuffer_cc_library(
name = "node_manager_fbs",
srcs = ["src/ray/raylet/format/node_manager.fbs"],
flatc_args = FLATC_ARGS,
include_paths = ["src/ray/gcs/format"],
includes = [":gcs_fbs_includes"],
out_prefix = "src/ray/raylet/format/",
)

flatbuffer_cc_library(
name = "object_manager_fbs",
srcs = ["src/ray/object_manager/format/object_manager.fbs"],
flatc_args = FLATC_ARGS,
out_prefix = "src/ray/object_manager/format/",
)
29 changes: 29 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")

git_repository(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this git_repository command in addition to the load command below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load brings "git_repository" into the namespace (this is needed to be compatible with the latest version of bazel)

name = "com_github_nelhage_rules_boost",
commit = "6d6fd834281cb8f8e758dd9ad76df86304bf1869",
remote = "https://github.com/nelhage/rules_boost",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this official or just some random repo on the internet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no official BAZEL support for boost, so we can be glad to have this random repo. It's the best I could find so far, short of writing build files for boost ourselves.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

)

load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
boost_deps()

git_repository(
name = "com_github_google_flatbuffers",
remote = "https://github.com/google/flatbuffers.git",
commit = "63d51afd1196336a7d1f56a988091ef05deb1c62",
)

git_repository(
name = "com_google_googletest",
remote = "https://github.com/google/googletest",
commit = "3306848f697568aacf4bcca330f6bdd5ce671899",
)

new_git_repository(
name = "plasma",
build_file = "@//bazel:BUILD.plasma",
remote = "https://github.com/ray-project/arrow",
commit = "1e4f867eb1dc31107331ab1defdffb94467f31dc",
)
Empty file added bazel/BUILD
Empty file.
Loading