Skip to content

Commit

Permalink
Polish Bazel build scripts (#6424)
Browse files Browse the repository at this point in the history
* Polish Bazel build scripts

* Remove glog references from streaming_logging.cc

* Move out COPTS and reference them

* Disable streaming on Windows

* Remove -fno-gnu-unique
  • Loading branch information
mehrdadn authored and pcmoritz committed Dec 17, 2019
1 parent 9d6e03a commit 7a24144
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 50 deletions.
64 changes: 23 additions & 41 deletions BUILD.bazel
Expand Up @@ -7,41 +7,7 @@ load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
load("@com_github_grpc_grpc//bazel:cython_library.bzl", "pyx_library")
load("@rules_proto_grpc//python:defs.bzl", "python_grpc_compile")
load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
load("//bazel:ray.bzl", "if_linux_x86_64")

config_setting(
name = "windows",
values = {"cpu": "x64_windows"},
visibility = ["//visibility:public"],
)

config_setting(
name = "macos",
values = {
"apple_platform_type": "macos",
"cpu": "darwin",
},
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_x86_64",
values = {"cpu": "k8"},
visibility = ["//visibility:public"],
)

# TODO(mehrdadn): (How to) support dynamic linking?
PROPAGATED_WINDOWS_DEFINES = ["RAY_STATIC"]

COPTS = ["-DRAY_USE_GLOG"] + select({
"@bazel_tools//src/conditions:windows": [
"-DWIN32_LEAN_AND_MEAN=", # Block the inclusion of WinSock.h, which is obsolete and causes errors
"-Wno-builtin-macro-redefined", # To get rid of warnings caused by deterministic build macros (e.g. #define __DATE__ "redacted")
"-Wno-microsoft-unqualified-friend", # This shouldn't normally be enabled, but otherwise we get: google/protobuf/map_field.h: warning: unqualified friend declaration referring to type outside of the nearest enclosing namespace is a Microsoft extension; add a nested name specifier (for: friend class DynamicMessage)
] + ["-D" + define for define in PROPAGATED_WINDOWS_DEFINES],
"//conditions:default": [
],
})
load("//bazel:ray.bzl", "COPTS", "PROPAGATED_WINDOWS_DEFINES")

# === Begin of protobuf definitions ===

Expand Down Expand Up @@ -938,16 +904,17 @@ pyx_library(
"linkstatic": 1,
# see https://github.com/tensorflow/tensorflow/blob/r2.1/tensorflow/lite/BUILD#L444
"linkopts": select({
"//:macos": [
"@bazel_tools//src/conditions:darwin": [
"-Wl,-exported_symbols_list,$(location //:src/ray/ray_exported_symbols.lds)",
],
"//:windows": [],
"@bazel_tools//src/conditions:windows": [
],
"//conditions:default": [
"-Wl,--version-script,$(location //:src/ray/ray_version_script.lds)",
],
}),
},
copts = COPTS + if_linux_x86_64(["-fno-gnu-unique"]),
copts = COPTS,
deps = [
"//:core_worker_lib",
"//:raylet_lib",
Expand All @@ -969,6 +936,7 @@ pyx_library(
"python/ray/streaming/includes/*.pxd",
"python/ray/streaming/includes/*.pxi",
]),
copts = COPTS,
deps = [
"//streaming:streaming_lib",
],
Expand Down Expand Up @@ -1098,11 +1066,23 @@ py_library(
visibility = ["__subpackages__"],
)

genrule(
name = "cp_streaming_lib",
srcs = ["python/ray/streaming/_streaming.so"],
outs = ["cp_streaming_lib.out"],
cmd = """
set -x &&
WORK_DIR=$$(pwd) &&
cp -f $(location python/ray/streaming/_streaming.so) "$$WORK_DIR/python/ray/streaming" &&
echo "$$WORK_DIR" > $@
""",
local = 1,
)

genrule(
name = "ray_pkg",
srcs = [
"python/ray/_raylet.so",
"python/ray/streaming/_streaming.so",
"//:python_sources",
"//:all_py_proto",
"//:redis-server",
Expand All @@ -1112,13 +1092,15 @@ genrule(
"//:raylet_monitor",
"@plasma//:plasma_store_server",
"//streaming:copy_streaming_py_proto",
],
] + select({
"@bazel_tools//src/conditions:windows": [], # ignore build streaming for windows
"//conditions:default": [":cp_streaming_lib"],
}),
outs = ["ray_pkg.out"],
cmd = """
set -x &&
WORK_DIR=$$(pwd) &&
cp -f $(location python/ray/_raylet.so) "$$WORK_DIR/python/ray" &&
cp -f $(location python/ray/streaming/_streaming.so) $$WORK_DIR/python/ray/streaming &&
mkdir -p "$$WORK_DIR/python/ray/core/src/ray/thirdparty/redis/src/" &&
cp -f $(location //:redis-server) "$$WORK_DIR/python/ray/core/src/ray/thirdparty/redis/src/" &&
cp -f $(location //:redis-cli) "$$WORK_DIR/python/ray/core/src/ray/thirdparty/redis/src/" &&
Expand Down
19 changes: 13 additions & 6 deletions bazel/ray.bzl
Expand Up @@ -2,6 +2,19 @@ load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_library_publ
load("@com_github_checkstyle_java//checkstyle:checkstyle.bzl", "checkstyle_test")
load("@bazel_common//tools/maven:pom_file.bzl", "pom_file")

# TODO(mehrdadn): (How to) support dynamic linking?
PROPAGATED_WINDOWS_DEFINES = ["RAY_STATIC"]

COPTS = ["-DRAY_USE_GLOG"] + select({
"@bazel_tools//src/conditions:windows": [
"-DWIN32_LEAN_AND_MEAN=", # Block the inclusion of WinSock.h, which is obsolete and causes errors
"-Wno-builtin-macro-redefined", # To get rid of warnings caused by deterministic build macros (e.g. #define __DATE__ "redacted")
"-Wno-microsoft-unqualified-friend", # This shouldn't normally be enabled, but otherwise we get: google/protobuf/map_field.h: warning: unqualified friend declaration referring to type outside of the nearest enclosing namespace is a Microsoft extension; add a nested name specifier (for: friend class DynamicMessage)
] + ["-D" + define for define in PROPAGATED_WINDOWS_DEFINES],
"//conditions:default": [
],
})

def flatbuffer_py_library(name, srcs, outs, out_prefix, includes = [], include_paths = []):
flatbuffer_library_public(
name = name,
Expand Down Expand Up @@ -64,9 +77,3 @@ def define_java_module(
"{auto_gen_header}": "<!-- This file is auto-generated by Bazel from pom_template.xml, do not modify it. -->",
},
)

def if_linux_x86_64(a):
return select({
"//:linux_x86_64": a,
"//conditions:default": [],
})
10 changes: 10 additions & 0 deletions streaming/BUILD.bazel
Expand Up @@ -3,6 +3,7 @@

load("@com_github_grpc_grpc//bazel:cython_library.bzl", "pyx_library")
load("@rules_proto_grpc//python:defs.bzl", "python_proto_compile")
load("//bazel:ray.bzl", "COPTS")

proto_library(
name = "streaming_proto",
Expand Down Expand Up @@ -30,20 +31,23 @@ cc_proto_library(
# be linked into streaming libs by dynamic linker. See bazel rule `//:_raylet`
cc_binary(
name = "ray_util.so",
copts = COPTS,
linkshared = 1,
visibility = ["//visibility:public"],
deps = ["//:ray_util"],
)

cc_binary(
name = "ray_common.so",
copts = COPTS,
linkshared = 1,
visibility = ["//visibility:public"],
deps = ["//:ray_common"],
)

cc_binary(
name = "core_worker_lib.so",
copts = COPTS,
linkshared = 1,
deps = ["//:core_worker_lib"],
)
Expand All @@ -56,6 +60,7 @@ cc_library(
hdrs = glob([
"src/util/*.h",
]),
copts = COPTS,
includes = [
"src",
],
Expand All @@ -75,6 +80,7 @@ cc_library(
hdrs = glob([
"src/config/*.h",
]),
copts = COPTS,
deps = [
"ray_common.so",
":streaming_cc_proto",
Expand All @@ -90,6 +96,7 @@ cc_library(
hdrs = glob([
"src/message/*.h",
]),
copts = COPTS,
deps = [
"ray_common.so",
":streaming_config",
Expand All @@ -105,6 +112,7 @@ cc_library(
hdrs = glob([
"src/queue/*.h",
]),
copts = COPTS,
deps = [
"core_worker_lib.so",
"ray_common.so",
Expand All @@ -128,6 +136,7 @@ cc_library(
"src/queue/*.h",
"src/test/*.h",
]),
copts = COPTS,
includes = ["src"],
visibility = ["//visibility:public"],
deps = [
Expand All @@ -154,6 +163,7 @@ cc_binary(
srcs = glob(["src/test/*.h"]) + [
"src/test/mock_actor.cc",
],
copts = COPTS,
includes = [
"streaming/src/test",
],
Expand Down
3 changes: 0 additions & 3 deletions streaming/src/util/streaming_logging.cc
Expand Up @@ -2,9 +2,6 @@
#include <sys/types.h>
#include <unistd.h>

#include "glog/log_severity.h"
#include "glog/logging.h"

#include "streaming_logging.h"

namespace ray {
Expand Down

0 comments on commit 7a24144

Please sign in to comment.