Files
2026-07-13 13:17:40 +08:00

481 lines
11 KiB
Python

# Bazel build
# C/C++ documentation: https://docs.bazel.build/versions/master/be/c-cpp.html
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files")
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
load("//bazel:python.bzl", "py_test_module_list")
load("//bazel:ray.bzl", "COPTS")
cc_binary(
name = "libray_api.so",
copts = COPTS,
linkopts = select({
"@platforms//os:osx": [
#TODO(larry): Hide the symbols when we make it work on mac.
],
"@platforms//os:windows": [
#TODO(larry): Hide the symbols when we make it work on Windows.
],
"//conditions:default": [
"-Wl,--version-script,$(location :symbols/ray_api_exported_symbols_linux.lds)",
],
}),
linkshared = 1,
linkstatic = 1,
visibility = ["//visibility:public"],
deps = [
":ray_api_lib",
":symbols/ray_api_exported_symbols_linux.lds",
],
)
cc_library(
name = "ray_api_lib",
srcs = glob([
"src/ray/api/*.cc",
"src/ray/api/*.h",
"src/ray/app/*.cc",
"src/ray/app/*.h",
"src/ray/runtime/*.cc",
"src/ray/runtime/*.h",
"src/ray/runtime/**/*.cc",
"src/ray/runtime/**/*.h",
"src/ray/runtime/task/*.cc",
"src/ray/runtime/task/*.h",
"src/ray/util/*.cc",
"src/ray/util/*.h",
"src/ray/*.cc",
"src/ray/*.h",
]),
hdrs = glob([
"include/ray/*.h",
"include/ray/**/*.h",
"include/ray/**/**/*.h",
]),
copts = COPTS,
linkopts = ["-ldl"],
linkstatic = True,
strip_include_prefix = "include",
visibility = ["//visibility:public"],
deps = [
"//src/ray/asio:instrumented_io_context",
"//src/ray/common:constants",
"//src/ray/common:id",
"//src/ray/common:ray_config",
"//src/ray/common:task_common",
"//src/ray/core_worker:core_worker_lib",
"//src/ray/gcs_rpc_client:global_state_accessor_lib",
"//src/ray/util:cmd_line_utils",
"//src/ray/util:network_util",
"//src/ray/util:process",
"//src/ray/util:process_interface",
"@boost//:callable_traits",
"@boost//:dll",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@msgpack",
"@nlohmann_json",
],
alwayslink = True,
)
cc_library(
name = "ray_cpp_lib",
srcs = [
"libray_api.so",
],
hdrs = glob([
"include/ray/*.h",
"include/ray/**/*.h",
"include/ray/**/**/*.h",
]),
strip_include_prefix = "include",
visibility = ["//visibility:public"],
)
cc_binary(
name = "default_worker",
srcs = [
"src/ray/worker/default_worker.cc",
],
copts = COPTS,
linkstatic = True,
deps = select({
"@platforms//os:windows": [
# TODO(SongGuyang): Change to use dynamic library
# "ray_cpp_lib" when we make it work on Windows.
"ray_api_lib",
],
"//conditions:default": [
"ray_cpp_lib",
"@boost//:callable_traits",
"@boost//:optional",
"@msgpack",
"@nlohmann_json",
],
}),
)
filegroup(
name = "ray_cpp_pkg_files",
srcs = [
"default_worker",
"libray_api.so",
],
visibility = ["//visibility:private"],
)
pkg_files(
name = "ray_cpp_hdrs",
srcs = ["include/ray/api.h"] + glob([
"include/ray/api/*.h",
]),
prefix = "ray/cpp/include/",
strip_prefix = "include",
visibility = ["//visibility:private"],
)
pkg_files(
name = "example_files",
srcs = glob(["example/*"]),
prefix = "ray/cpp/example/",
visibility = ["//visibility:private"],
)
pkg_files(
name = "msgpack_hdrs_files",
srcs = ["@msgpack//:msgpack_hdrs"],
prefix = "ray/cpp/include/",
strip_prefix = "include",
visibility = ["//visibility:private"],
)
pkg_files(
name = "nlohmann_json_hdrs_files",
srcs = ["@nlohmann_json//:nlohmann_json_hdrs"],
prefix = "ray/cpp/include/",
strip_prefix = "single_include",
visibility = ["//visibility:private"],
)
pkg_files(
name = "boost_ray_hdrs_files",
srcs = ["@boost//:boost_ray_hdrs"],
prefix = "ray/cpp/include/boost/",
strip_prefix = "boost",
visibility = ["//visibility:private"],
)
pkg_files(
name = "default_worker_files",
srcs = ["default_worker"],
attributes = pkg_attributes(mode = "755"),
prefix = "ray/cpp/",
visibility = ["//visibility:private"],
)
pkg_files(
name = "libray_api_files",
srcs = ["libray_api.so"],
attributes = pkg_attributes(mode = "755"),
prefix = "ray/cpp/lib/",
visibility = ["//visibility:private"],
)
pkg_zip(
name = "ray_cpp_pkg_zip",
srcs = [
":boost_ray_hdrs_files",
":default_worker_files",
":example_files",
":libray_api_files",
":msgpack_hdrs_files",
":nlohmann_json_hdrs_files",
":ray_cpp_hdrs",
],
out = "ray_cpp_pkg.zip",
visibility = ["//visibility:private"],
)
py_binary(
name = "gen_ray_cpp_pkg",
srcs = ["gen_ray_cpp_pkg.py"],
data = [
":ray_cpp_pkg.zip",
],
visibility = ["//visibility:private"],
deps = [
"//bazel:gen_extract",
],
)
# test
cc_test(
name = "api_test",
srcs = glob([
"src/ray/test/*.cc",
]),
copts = COPTS,
linkstatic = True,
tags = ["team:core"],
deps = [
"ray_api_lib",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "cluster_mode_test",
srcs = glob(
[
"src/ray/test/cluster/*.cc",
"src/ray/test/cluster/*.h",
],
exclude = [
"src/ray/test/cluster/cluster_mode_xlang_test.cc",
],
),
args = [
"--ray_code_search_path=$(location plus.so):$(location counter.so):cpp/src/ray/test/cluster",
"--ray_head_args '--include-dashboard false'",
],
copts = COPTS,
data = [
"counter.so",
"plus.so",
"src/ray/test/cluster/test_cross_language_invocation.py",
":ray_cpp_pkg_files",
],
linkstatic = True,
tags = ["team:core"],
deps = [
"ray_api_lib",
"//src/ray/util:network_util",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "cluster_mode_xlang_test",
srcs = [
"src/ray/test/cluster/cluster_mode_xlang_test.cc",
] + glob([
"src/ray/test/cluster/*.h",
]),
args = [
"--ray_code_search_path=$(location //java:libio_ray_ray_test.jar)",
"--ray_head_args '--include-dashboard false'",
],
copts = COPTS,
data = [
":ray_cpp_pkg_files",
"//java:libio_ray_ray_test.jar",
],
linkstatic = True,
tags = [
"no_macos",
"team:core",
],
deps = [
"ray_api_lib",
"@com_google_googletest//:gtest_main",
],
)
cc_binary(
name = "plus.so",
testonly = True,
srcs = [
"src/ray/test/cluster/plus.cc",
"src/ray/test/cluster/plus.h",
],
copts = COPTS,
linkopts = ["-shared"],
linkstatic = True,
# NOTE(WangTaoTheTonic): For java x-lang tests. See //java:all_tests
# and `CrossLanguageInvocationTest.java`.
visibility = ["//java:__subpackages__"],
deps = [
"ray_cpp_lib",
"@boost//:callable_traits",
"@boost//:optional",
"@msgpack",
"@nlohmann_json",
],
)
cc_binary(
name = "counter.so",
testonly = True,
srcs = [
"src/ray/test/cluster/counter.cc",
"src/ray/test/cluster/counter.h",
],
copts = COPTS,
linkopts = ["-shared"],
linkstatic = True,
# NOTE(WangTaoTheTonic): For java x-lang tests. See //java:all_tests
# and `CrossLanguageInvocationTest.java`.
visibility = ["//java:__subpackages__"],
deps = [
"ray_cpp_lib",
"@boost//:callable_traits",
"@boost//:optional",
"@msgpack",
"@nlohmann_json",
],
)
cc_test(
name = "simple_kv_store",
srcs = [
"src/ray/test/examples/simple_kv_store.cc",
],
args = [
"--ray_code_search_path=$(location simple_kv_store.so)",
"--ray_head_args '--include-dashboard false'",
],
copts = COPTS,
data = [
"simple_kv_store.so",
],
linkstatic = True,
tags = ["team:core"],
deps = [
"ray_api_lib",
],
)
cc_binary(
name = "simple_kv_store.so",
testonly = True,
srcs = [
"src/ray/test/examples/simple_kv_store.cc",
],
copts = COPTS,
linkopts = ["-shared"],
linkstatic = True,
deps = [
"ray_cpp_lib",
"@boost//:callable_traits",
"@boost//:optional",
"@msgpack",
"@nlohmann_json",
],
)
cc_binary(
name = "simple_job",
srcs = [
"src/ray/test/examples/simple_job.cc",
],
copts = COPTS,
data = [
"simple_job.so",
],
linkstatic = True,
tags = ["team:core"],
deps = [
":ray_api_lib",
],
)
cc_binary(
name = "simple_job.so",
srcs = [
"src/ray/test/examples/simple_job.cc",
],
copts = COPTS,
linkopts = ["-shared"],
linkstatic = True,
deps = [
"ray_cpp_lib",
"@boost//:callable_traits",
"@boost//:optional",
"@msgpack",
"@nlohmann_json",
],
)
cc_test(
name = "metric_example",
srcs = [
"src/ray/test/examples/metric_example.cc",
],
args = [
"--ray_code_search_path $(location metric_example.so)",
],
data = [
"metric_example.so",
],
linkstatic = True,
tags = ["team:core"],
deps = [
"ray_cpp_lib",
"@boost//:callable_traits",
"@boost//:optional",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@msgpack",
"@nlohmann_json",
],
)
cc_binary(
name = "metric_example.so",
testonly = True,
srcs = [
"src/ray/test/examples/metric_example.cc",
],
linkopts = ["-shared"],
linkstatic = True,
deps = [
"ray_cpp_lib",
"@boost//:callable_traits",
"@boost//:optional",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@msgpack",
"@nlohmann_json",
],
)
py_test_module_list(
size = "medium",
data = [
"counter.so",
"plus.so",
],
extra_srcs = [],
files = [
"test_python_call_cpp.py",
],
tags = [
"exclusive",
"medium_size_python_tests",
"team:core",
],
deps = [],
)
py_test(
name = "test_submit_cpp_job",
size = "medium",
srcs = ["test_submit_cpp_job.py"],
data = [
"simple_job",
"simple_job.so",
],
env = {
"SIMPLE_DRIVER_SO_PATH": "$(location simple_job.so)",
"SIMPLE_DRIVER_MAIN_PATH": "$(location simple_job)",
},
tags = [
# TODO(ray-core): fix this test on apple silicon macos.
"no_macos",
"team:core",
],
)