BUILD.bazel 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. # Bazel build
  2. # C/C++ documentation: https://docs.bazel.build/versions/master/be/c-cpp.html
  3. load("//bazel:ray.bzl", "COPTS")
  4. cc_binary(
  5. name = "libray_api.so",
  6. copts = COPTS,
  7. linkopts = select({
  8. "@bazel_tools//src/conditions:darwin": [
  9. #TODO(larry): Hide the symbols when we make it work on mac.
  10. ],
  11. "@bazel_tools//src/conditions:windows": [
  12. #TODO(larry): Hide the symbols when we make it work on Windows.
  13. ],
  14. "//conditions:default": [
  15. "-Wl,--version-script,$(location :symbols/ray_api_exported_symbols_linux.lds)",
  16. ],
  17. }),
  18. linkshared = 1,
  19. linkstatic = 1,
  20. visibility = ["//visibility:public"],
  21. deps = [
  22. ":ray_api_lib",
  23. ":symbols/ray_api_exported_symbols_linux.lds",
  24. ],
  25. )
  26. cc_library(
  27. name = "ray_api_lib",
  28. srcs = glob([
  29. "src/ray/api.cc",
  30. "src/ray/api/*.cc",
  31. "src/ray/api/*.h",
  32. "src/ray/app/*.cc",
  33. "src/ray/app/*.h",
  34. "src/ray/runtime/*.cc",
  35. "src/ray/runtime/*.h",
  36. "src/ray/runtime/**/*.cc",
  37. "src/ray/runtime/**/*.h",
  38. "src/ray/runtime/task/*.cc",
  39. "src/ray/runtime/task/*.h",
  40. "src/ray/util/*.cc",
  41. "src/ray/util/*.h",
  42. "src/ray/*.cc",
  43. "src/ray/*.h",
  44. ]),
  45. hdrs = glob([
  46. "include/ray/*.h",
  47. "include/ray/**/*.h",
  48. "include/ray/**/**/*.h",
  49. ]),
  50. copts = COPTS,
  51. linkopts = ["-ldl"],
  52. linkstatic = True,
  53. strip_include_prefix = "include",
  54. visibility = ["//visibility:public"],
  55. deps = [
  56. "//:core_worker_lib",
  57. "//:global_state_accessor_lib",
  58. "//:ray_common",
  59. "//:ray_util",
  60. "@boost//:callable_traits",
  61. "@boost//:dll",
  62. "@com_google_absl//absl/flags:flag",
  63. "@com_google_absl//absl/flags:parse",
  64. "@msgpack",
  65. "@nlohmann_json",
  66. ],
  67. alwayslink = True,
  68. )
  69. cc_library(
  70. name = "ray_cpp_lib",
  71. srcs = [
  72. "libray_api.so",
  73. ],
  74. hdrs = glob([
  75. "include/ray/*.h",
  76. "include/ray/**/*.h",
  77. "include/ray/**/**/*.h",
  78. ]),
  79. strip_include_prefix = "include",
  80. visibility = ["//visibility:public"],
  81. )
  82. cc_binary(
  83. name = "default_worker",
  84. srcs = glob([
  85. "src/ray/worker/default_worker.cc",
  86. ]),
  87. copts = COPTS,
  88. linkstatic = True,
  89. deps = select({
  90. "@bazel_tools//src/conditions:windows": [
  91. # TODO(SongGuyang): Change to use dynamic library
  92. # "ray_cpp_lib" when we make it work on Windows.
  93. "ray_api_lib",
  94. ],
  95. "//conditions:default": [
  96. "ray_cpp_lib",
  97. "@boost//:callable_traits",
  98. "@boost//:optional",
  99. "@msgpack",
  100. "@nlohmann_json",
  101. ],
  102. }),
  103. )
  104. genrule(
  105. name = "ray_cpp_pkg",
  106. srcs = [
  107. "default_worker",
  108. "libray_api.so",
  109. ],
  110. outs = ["ray_cpp_pkg.out"],
  111. cmd = """
  112. WORK_DIR="$$(pwd)" &&
  113. PY_CPP_DIR="$$WORK_DIR/python/ray/cpp" &&
  114. rm -rf $$PY_CPP_DIR &&
  115. BOOST_DIR="$$PY_CPP_DIR/include/boost/" &&
  116. mkdir -p "$$BOOST_DIR" &&
  117. mkdir -p "$$PY_CPP_DIR/lib/" &&
  118. cp -f $(location default_worker) "$$PY_CPP_DIR/" &&
  119. cp -f -r $$WORK_DIR/external/msgpack/include/* "$$PY_CPP_DIR/include" &&
  120. cp -f -r $$WORK_DIR/external/nlohmann_json/single_include/* "$$PY_CPP_DIR/include" &&
  121. cp -f -r "$$WORK_DIR/external/boost/boost/archive" "$$BOOST_DIR" &&
  122. cp -f -r "$$WORK_DIR/external/boost/boost/assert" "$$BOOST_DIR" &&
  123. cp -f -r "$$WORK_DIR/external/boost/boost/bind" "$$BOOST_DIR" &&
  124. cp -f -r "$$WORK_DIR/external/boost/boost/callable_traits" "$$BOOST_DIR" &&
  125. cp -f -r "$$WORK_DIR/external/boost/boost/concept" "$$BOOST_DIR" &&
  126. cp -f -r "$$WORK_DIR/external/boost/boost/config" "$$BOOST_DIR" &&
  127. cp -f -r "$$WORK_DIR/external/boost/boost/container" "$$BOOST_DIR" &&
  128. cp -f -r "$$WORK_DIR/external/boost/boost/container_hash" "$$BOOST_DIR" &&
  129. cp -f -r "$$WORK_DIR/external/boost/boost/core" "$$BOOST_DIR" &&
  130. cp -f -r "$$WORK_DIR/external/boost/boost/detail" "$$BOOST_DIR" &&
  131. cp -f -r "$$WORK_DIR/external/boost/boost/dll" "$$BOOST_DIR" &&
  132. cp -f -r "$$WORK_DIR/external/boost/boost/exception" "$$BOOST_DIR" &&
  133. cp -f -r "$$WORK_DIR/external/boost/boost/filesystem" "$$BOOST_DIR" &&
  134. cp -f -r "$$WORK_DIR/external/boost/boost/functional" "$$BOOST_DIR" &&
  135. cp -f -r "$$WORK_DIR/external/boost/boost/io" "$$BOOST_DIR" &&
  136. cp -f -r "$$WORK_DIR/external/boost/boost/iterator" "$$BOOST_DIR" &&
  137. cp -f -r "$$WORK_DIR/external/boost/boost/lexical_cast" "$$BOOST_DIR" &&
  138. cp -f -r "$$WORK_DIR/external/boost/boost/move" "$$BOOST_DIR" &&
  139. cp -f -r "$$WORK_DIR/external/boost/boost/mpl" "$$BOOST_DIR" &&
  140. cp -f -r "$$WORK_DIR/external/boost/boost/optional" "$$BOOST_DIR" &&
  141. cp -f -r "$$WORK_DIR/external/boost/boost/parameter" "$$BOOST_DIR" &&
  142. cp -f -r "$$WORK_DIR/external/boost/boost/preprocessor" "$$BOOST_DIR" &&
  143. cp -f -r "$$WORK_DIR/external/boost/boost/system" "$$BOOST_DIR" &&
  144. cp -f -r "$$WORK_DIR/external/boost/boost/type_traits" "$$BOOST_DIR" &&
  145. cp -f -r "$$WORK_DIR/external/boost/boost/utility" "$$BOOST_DIR" &&
  146. cp -f -r $$WORK_DIR/external/boost/boost/*.hpp "$$BOOST_DIR" &&
  147. cp -f $(locations libray_api.so) "$$PY_CPP_DIR/lib/" &&
  148. cp -f -r "$$WORK_DIR/cpp/include/ray" "$$PY_CPP_DIR/include" &&
  149. THIRDPARTY_DIR="$$WORK_DIR/cpp/example/thirdparty" &&
  150. rm -rf $$THIRDPARTY_DIR &&
  151. mkdir $$THIRDPARTY_DIR &&
  152. cp -f -r "$$PY_CPP_DIR/include" $$THIRDPARTY_DIR &&
  153. cp -f -r "$$PY_CPP_DIR/lib" $$THIRDPARTY_DIR &&
  154. cp -f -r "$$WORK_DIR/cpp/example" "$$PY_CPP_DIR" &&
  155. echo "$$WORK_DIR" > $@
  156. """,
  157. local = 1,
  158. visibility = ["//visibility:public"],
  159. )
  160. # test
  161. cc_test(
  162. name = "api_test",
  163. srcs = glob([
  164. "src/ray/test/*.cc",
  165. ]),
  166. copts = COPTS,
  167. linkstatic = True,
  168. tags = ["team:core"],
  169. deps = [
  170. "ray_api_lib",
  171. "@com_google_googletest//:gtest_main",
  172. ],
  173. )
  174. cc_test(
  175. name = "cluster_mode_test",
  176. srcs = glob(
  177. [
  178. "src/ray/test/cluster/*.cc",
  179. "src/ray/test/cluster/*.h",
  180. ],
  181. exclude = [
  182. "src/ray/test/cluster/cluster_mode_xlang_test.cc",
  183. ],
  184. ),
  185. args = [
  186. "--ray_code_search_path=$(location plus.so):$(location counter.so):cpp/src/ray/test/cluster",
  187. "--ray_head_args '--include-dashboard false'",
  188. ],
  189. copts = COPTS,
  190. data = [
  191. "counter.so",
  192. "plus.so",
  193. "ray_cpp_pkg",
  194. "src/ray/test/cluster/test_cross_language_invocation.py",
  195. ],
  196. linkstatic = True,
  197. tags = ["team:core"],
  198. deps = [
  199. "ray_api_lib",
  200. "@com_google_googletest//:gtest_main",
  201. ],
  202. )
  203. cc_test(
  204. name = "cluster_mode_xlang_test",
  205. srcs = glob([
  206. "src/ray/test/cluster/cluster_mode_xlang_test.cc",
  207. "src/ray/test/cluster/*.h",
  208. ]),
  209. args = [
  210. "--ray_code_search_path=$(location //java:libio_ray_ray_test.jar)",
  211. "--ray_head_args '--include-dashboard false'",
  212. ],
  213. copts = COPTS,
  214. data = [
  215. "ray_cpp_pkg",
  216. "//java:libio_ray_ray_test.jar",
  217. ],
  218. linkstatic = True,
  219. tags = ["team:core"],
  220. deps = [
  221. "ray_api_lib",
  222. "@com_google_googletest//:gtest_main",
  223. ],
  224. )
  225. cc_binary(
  226. name = "plus.so",
  227. testonly = True,
  228. srcs = [
  229. "src/ray/test/cluster/plus.cc",
  230. "src/ray/test/cluster/plus.h",
  231. ],
  232. copts = COPTS,
  233. linkopts = ["-shared"],
  234. linkstatic = True,
  235. # NOTE(WangTaoTheTonic): For java x-lang tests. See //java:all_tests
  236. # and `CrossLanguageInvocationTest.java`.
  237. visibility = ["//java:__subpackages__"],
  238. deps = [
  239. "ray_cpp_lib",
  240. "@boost//:callable_traits",
  241. "@boost//:optional",
  242. "@msgpack",
  243. "@nlohmann_json",
  244. ],
  245. )
  246. cc_binary(
  247. name = "counter.so",
  248. testonly = True,
  249. srcs = [
  250. "src/ray/test/cluster/counter.cc",
  251. "src/ray/test/cluster/counter.h",
  252. ],
  253. copts = COPTS,
  254. linkopts = ["-shared"],
  255. linkstatic = True,
  256. # NOTE(WangTaoTheTonic): For java x-lang tests. See //java:all_tests
  257. # and `CrossLanguageInvocationTest.java`.
  258. visibility = ["//java:__subpackages__"],
  259. deps = [
  260. "ray_cpp_lib",
  261. "@boost//:callable_traits",
  262. "@boost//:optional",
  263. "@msgpack",
  264. "@nlohmann_json",
  265. ],
  266. )
  267. cc_test(
  268. name = "simple_kv_store",
  269. srcs = glob([
  270. "src/ray/test/examples/simple_kv_store.cc",
  271. ]),
  272. args = [
  273. "--ray_code_search_path=$(location simple_kv_store.so)",
  274. "--ray_head_args '--include-dashboard false'",
  275. ],
  276. copts = COPTS,
  277. data = [
  278. "simple_kv_store.so",
  279. ],
  280. linkstatic = True,
  281. tags = ["team:core"],
  282. deps = [
  283. "ray_api_lib",
  284. ],
  285. )
  286. cc_binary(
  287. name = "simple_kv_store.so",
  288. testonly = True,
  289. srcs = glob([
  290. "src/ray/test/examples/simple_kv_store.cc",
  291. ]),
  292. copts = COPTS,
  293. linkopts = ["-shared"],
  294. linkstatic = True,
  295. deps = [
  296. "ray_cpp_lib",
  297. "@boost//:callable_traits",
  298. "@boost//:optional",
  299. "@msgpack",
  300. "@nlohmann_json",
  301. ],
  302. )
  303. cc_binary(
  304. name = "simple_job",
  305. srcs = [
  306. "src/ray/test/examples/simple_job.cc",
  307. ],
  308. copts = COPTS,
  309. data = [
  310. "simple_job.so",
  311. ],
  312. linkstatic = True,
  313. tags = ["team:core"],
  314. deps = [
  315. ":ray_api_lib",
  316. ],
  317. )
  318. cc_binary(
  319. name = "simple_job.so",
  320. srcs = [
  321. "src/ray/test/examples/simple_job.cc",
  322. ],
  323. copts = COPTS,
  324. linkopts = ["-shared"],
  325. linkstatic = True,
  326. deps = [
  327. "ray_cpp_lib",
  328. "@boost//:callable_traits",
  329. "@boost//:optional",
  330. "@msgpack",
  331. "@nlohmann_json",
  332. ],
  333. )
  334. load("//bazel:python.bzl", "py_test_module_list")
  335. py_test_module_list(
  336. size = "medium",
  337. extra_srcs = [],
  338. files = [
  339. "test_python_call_cpp.py",
  340. ],
  341. tags = [
  342. "exclusive",
  343. "medium_size_python_tests",
  344. "team:core",
  345. ],
  346. deps = [],
  347. )
  348. py_test(
  349. name = "test_submit_cpp_job",
  350. size = "medium",
  351. srcs = ["test_submit_cpp_job.py"],
  352. data = [
  353. "simple_job",
  354. "simple_job.so",
  355. ],
  356. env = {
  357. "SIMPLE_DRIVER_SO_PATH": "$(location simple_job.so)",
  358. "SIMPLE_DRIVER_MAIN_PATH": "$(location simple_job)",
  359. },
  360. tags = ["team:core"],
  361. )