ray/java/BUILD.bazel

266 lines
7.2 KiB
Text

load("//bazel:ray.bzl", "define_java_module")
load("//bazel:ray.bzl", "native_java_binary")
load("//bazel:ray.bzl", "native_java_library")
load("@rules_proto_grpc//java:defs.bzl", "java_proto_compile")
exports_files([
"testng.xml",
"checkstyle.xml",
"checkstyle-suppressions.xml",
])
all_modules = [
"api",
"runtime",
"test",
]
java_import(
name = "all_modules",
jars = [
"libio_ray_ray_" + module + ".jar"
for module in all_modules
] + [
"libio_ray_ray_" + module + "-src.jar"
for module in all_modules
] + [
"all_tests_deploy.jar",
"all_tests_deploy-src.jar",
],
deps = [
":io_ray_ray_" + module
for module in all_modules
] + [
":all_tests",
],
)
define_java_module(
name = "api",
visibility = ["//visibility:public"],
deps = [
"@maven//:com_sun_xml_bind_jaxb_core",
"@maven//:com_sun_xml_bind_jaxb_impl",
"@maven//:javax_xml_bind_jaxb_api",
"@maven//:log4j_log4j",
"@maven//:org_slf4j_slf4j_log4j12",
],
)
define_java_module(
name = "runtime",
additional_resources = [
":java_native_deps",
],
additional_srcs = [
":all_java_proto",
],
define_test_lib = True,
exclude_srcs = [
"runtime/src/main/java/io/ray/runtime/generated/*.java",
],
test_deps = [
":io_ray_ray_api",
":io_ray_ray_runtime",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:org_testng_testng",
"@maven//:commons_io_commons_io",
"@maven//:javax_xml_bind_jaxb_api",
],
visibility = ["//visibility:public"],
deps = [
":io_ray_ray_api",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_typesafe_config",
"@maven//:commons_io_commons_io",
"@maven//:de_ruedigermoeller_fst",
"@maven//:log4j_log4j",
"@maven//:net_java_dev_jna_jna",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:org_msgpack_msgpack_core",
"@maven//:org_ow2_asm_asm",
"@maven//:org_slf4j_slf4j_api",
"@maven//:org_slf4j_slf4j_log4j12",
"@maven//:org_testng_testng",
"@maven//:redis_clients_jedis",
],
)
define_java_module(
name = "test",
deps = [
":io_ray_ray_api",
":io_ray_ray_runtime",
"@maven//:com_google_code_gson_gson",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_sun_xml_bind_jaxb_core",
"@maven//:com_sun_xml_bind_jaxb_impl",
"@maven//:commons_io_commons_io",
"@maven//:javax_xml_bind_jaxb_api",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:org_slf4j_slf4j_api",
"@maven//:org_testng_testng",
],
)
java_binary(
name = "all_tests",
args = ["java/testng.xml"],
data = ["testng.xml"],
main_class = "org.testng.TestNG",
runtime_deps = [
":io_ray_ray_runtime_test",
":io_ray_ray_test",
],
)
java_proto_compile(
name = "common_java_proto",
deps = ["@//src/ray/protobuf:common_proto"],
)
java_proto_compile(
name = "gcs_java_proto",
deps = ["@//src/ray/protobuf:gcs_proto"],
)
filegroup(
name = "all_java_proto",
srcs = [
":common_java_proto",
":gcs_java_proto",
],
)
native_java_binary("runtime", "raylet", "//:raylet")
native_java_binary("runtime", "plasma_store_server", "//:plasma_store_server")
native_java_binary("runtime", "redis-server", "//:redis-server")
native_java_binary("runtime", "gcs_server", "//:gcs_server")
native_java_binary("runtime", "libray_redis_module.so", "//:libray_redis_module.so")
native_java_library("runtime", "core_worker_library_java", "//:libcore_worker_library_java.so")
filegroup(
name = "java_native_deps",
srcs = [
":core_worker_library_java",
":gcs_server",
":libray_redis_module.so",
":plasma_store_server",
":raylet",
":redis-server",
],
)
# Generates the dependencies needed by maven.
genrule(
name = "cp_java_generated",
srcs = [
":all_java_proto",
":copy_pom_file",
],
outs = ["cp_java_generated.out"],
cmd = """
WORK_DIR="$$(pwd)"
# Copy protobuf-generated files.
rm -rf "$$WORK_DIR/java/runtime/src/main/java/io/ray/runtime/generated"
for f in $(locations //java:all_java_proto); do
unzip "$$f" -x META-INF/MANIFEST.MF -d "$$WORK_DIR/java/runtime/src/main/java"
done
date > $@
""",
local = 1,
tags = ["no-cache"],
)
# Generates the dependencies needed by maven.
genrule(
name = "gen_maven_deps",
srcs = [
":cp_java_generated",
":java_native_deps",
],
outs = ["gen_maven_deps.out"],
cmd = """
WORK_DIR="$${PWD}"
# Copy native dependencies.
OS_NAME=""
case "$${OSTYPE}" in
linux*) OS_NAME="linux";;
darwin*) OS_NAME="darwin";;
*) echo "$${OSTYPE} is not supported currently"; exit 1;;
esac
NATIVE_DEPS_DIR="$$WORK_DIR/java/runtime/native_dependencies/native/$$OS_NAME"
rm -rf "$$NATIVE_DEPS_DIR"
mkdir -p "$$NATIVE_DEPS_DIR"
for f in $(locations //java:java_native_deps); do
chmod +w "$$f"
cp "$$f" "$$NATIVE_DEPS_DIR"
done
date > $@
""",
local = 1,
tags = ["no-cache"],
)
genrule(
name = "copy_pom_file",
srcs = [
"//java:io_ray_ray_" + module + "_pom"
for module in all_modules
],
outs = ["copy_pom_file.out"],
cmd = """
WORK_DIR="$$(pwd)"
cp -f $(location //java:io_ray_ray_api_pom) "$$WORK_DIR/java/api/pom.xml"
cp -f $(location //java:io_ray_ray_runtime_pom) "$$WORK_DIR/java/runtime/pom.xml"
cp -f $(location //java:io_ray_ray_test_pom) "$$WORK_DIR/java/test/pom.xml"
date > $@
""",
local = 1,
tags = ["no-cache"],
)
java_binary(
name = "ray_dist",
# This rule is used to package all Ray Java code and the third-party dependencies into a
# fat jar file. It's not really an executable jar. So we set its `main_class` to empty.
main_class = "",
runtime_deps = [
"//java:io_ray_ray_api",
"//java:io_ray_ray_runtime",
"//streaming/java:io_ray_ray_streaming-api",
"//streaming/java:io_ray_ray_streaming-runtime",
],
)
genrule(
name = "ray_java_pkg",
srcs = [
"//java:ray_dist_deploy.jar",
"//java:gen_maven_deps",
"//streaming/java:gen_maven_deps",
],
outs = ["ray_java_pkg.out"],
cmd = """
WORK_DIR="$$(pwd)"
rm -rf "$$WORK_DIR/python/ray/jars" && mkdir -p "$$WORK_DIR/python/ray/jars"
cp -f $(location //java:ray_dist_deploy.jar) "$$WORK_DIR/python/ray/jars/ray_dist.jar"
chmod +w "$$WORK_DIR/python/ray/jars/ray_dist.jar"
zip -d "$$WORK_DIR/python/ray/jars/ray_dist.jar" \
"native/*/gcs_server" \
"native/*/libray_redis_module.so" \
"native/*/plasma_store_server" \
"native/*/raylet" \
"native/*/redis-server"
date > $@
""",
local = 1,
tags = ["no-cache"],
)