BUILD.bazel 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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",
  23. ":symbols/ray_api_exported_symbols_linux.lds",
  24. ":symbols/ray_api_exported_symbols_mac.lds",
  25. ],
  26. )
  27. cc_library(
  28. name = "ray_api",
  29. srcs = glob([
  30. "src/ray/api.cc",
  31. "src/ray/api/*.cc",
  32. "src/ray/api/*.h",
  33. "src/ray/app/*.cc",
  34. "src/ray/app/*.h",
  35. "src/ray/runtime/*.cc",
  36. "src/ray/runtime/*.h",
  37. "src/ray/runtime/**/*.cc",
  38. "src/ray/runtime/**/*.h",
  39. "src/ray/runtime/task/*.cc",
  40. "src/ray/runtime/task/*.h",
  41. "src/ray/util/*.cc",
  42. "src/ray/util/*.h",
  43. "src/ray/*.cc",
  44. "src/ray/*.h",
  45. ]),
  46. hdrs = glob([
  47. "include/ray/*.h",
  48. "include/ray/**/*.h",
  49. "include/ray/**/**/*.h",
  50. ]),
  51. copts = COPTS,
  52. linkopts = ["-ldl"],
  53. linkstatic = True,
  54. strip_include_prefix = "include",
  55. visibility = ["//visibility:public"],
  56. deps = [
  57. "//:core_worker_lib",
  58. "//:global_state_accessor_lib",
  59. "//:ray_common",
  60. "//:ray_util",
  61. "@boost//:callable_traits",
  62. "@boost//:dll",
  63. "@com_google_absl//absl/flags:flag",
  64. "@com_google_absl//absl/flags:parse",
  65. "@msgpack",
  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",
  94. ],
  95. "//conditions:default": [
  96. "ray_cpp_lib",
  97. "@boost//:callable_traits",
  98. "@boost//:optional",
  99. "@msgpack",
  100. ],
  101. }),
  102. )
  103. genrule(
  104. name = "ray_cpp_pkg",
  105. srcs = [
  106. "default_worker",
  107. "ray_api",
  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/boost/boost/archive" "$$BOOST_DIR" &&
  121. cp -f -r "$$WORK_DIR/external/boost/boost/assert" "$$BOOST_DIR" &&
  122. cp -f -r "$$WORK_DIR/external/boost/boost/bind" "$$BOOST_DIR" &&
  123. cp -f -r "$$WORK_DIR/external/boost/boost/callable_traits" "$$BOOST_DIR" &&
  124. cp -f -r "$$WORK_DIR/external/boost/boost/concept" "$$BOOST_DIR" &&
  125. cp -f -r "$$WORK_DIR/external/boost/boost/config" "$$BOOST_DIR" &&
  126. cp -f -r "$$WORK_DIR/external/boost/boost/container" "$$BOOST_DIR" &&
  127. cp -f -r "$$WORK_DIR/external/boost/boost/container_hash" "$$BOOST_DIR" &&
  128. cp -f -r "$$WORK_DIR/external/boost/boost/core" "$$BOOST_DIR" &&
  129. cp -f -r "$$WORK_DIR/external/boost/boost/detail" "$$BOOST_DIR" &&
  130. cp -f -r "$$WORK_DIR/external/boost/boost/dll" "$$BOOST_DIR" &&
  131. cp -f -r "$$WORK_DIR/external/boost/boost/exception" "$$BOOST_DIR" &&
  132. cp -f -r "$$WORK_DIR/external/boost/boost/filesystem" "$$BOOST_DIR" &&
  133. cp -f -r "$$WORK_DIR/external/boost/boost/functional" "$$BOOST_DIR" &&
  134. cp -f -r "$$WORK_DIR/external/boost/boost/io" "$$BOOST_DIR" &&
  135. cp -f -r "$$WORK_DIR/external/boost/boost/iterator" "$$BOOST_DIR" &&
  136. cp -f -r "$$WORK_DIR/external/boost/boost/lexical_cast" "$$BOOST_DIR" &&
  137. cp -f -r "$$WORK_DIR/external/boost/boost/move" "$$BOOST_DIR" &&
  138. cp -f -r "$$WORK_DIR/external/boost/boost/mpl" "$$BOOST_DIR" &&
  139. cp -f -r "$$WORK_DIR/external/boost/boost/optional" "$$BOOST_DIR" &&
  140. cp -f -r "$$WORK_DIR/external/boost/boost/parameter" "$$BOOST_DIR" &&
  141. cp -f -r "$$WORK_DIR/external/boost/boost/preprocessor" "$$BOOST_DIR" &&
  142. cp -f -r "$$WORK_DIR/external/boost/boost/system" "$$BOOST_DIR" &&
  143. cp -f -r "$$WORK_DIR/external/boost/boost/type_traits" "$$BOOST_DIR" &&
  144. cp -f -r "$$WORK_DIR/external/boost/boost/utility" "$$BOOST_DIR" &&
  145. cp -f -r $$WORK_DIR/external/boost/boost/*.hpp "$$BOOST_DIR" &&
  146. cp -f $(locations libray_api.so) "$$PY_CPP_DIR/lib/" &&
  147. cp -f -r "$$WORK_DIR/cpp/include/ray" "$$PY_CPP_DIR/include" &&
  148. THIRDPARTY_DIR="$$WORK_DIR/cpp/example/thirdparty" &&
  149. rm -rf $$THIRDPARTY_DIR &&
  150. mkdir $$THIRDPARTY_DIR &&
  151. cp -f -r "$$PY_CPP_DIR/include" $$THIRDPARTY_DIR &&
  152. cp -f -r "$$PY_CPP_DIR/lib" $$THIRDPARTY_DIR &&
  153. cp -f -r "$$WORK_DIR/cpp/example" "$$PY_CPP_DIR" &&
  154. echo "$$WORK_DIR" > $@
  155. """,
  156. local = 1,
  157. visibility = ["//visibility:public"],
  158. )
  159. # test
  160. cc_test(
  161. name = "api_test",
  162. srcs = glob([
  163. "src/ray/test/*.cc",
  164. ]),
  165. copts = COPTS,
  166. linkstatic = True,
  167. tags = ["team:core"],
  168. deps = [
  169. "ray_api",
  170. "@boost//:filesystem",
  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",
  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",
  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. ],
  244. )
  245. cc_binary(
  246. name = "counter.so",
  247. testonly = True,
  248. srcs = [
  249. "src/ray/test/cluster/counter.cc",
  250. "src/ray/test/cluster/counter.h",
  251. ],
  252. copts = COPTS,
  253. linkopts = ["-shared"],
  254. linkstatic = True,
  255. # NOTE(WangTaoTheTonic): For java x-lang tests. See //java:all_tests
  256. # and `CrossLanguageInvocationTest.java`.
  257. visibility = ["//java:__subpackages__"],
  258. deps = [
  259. "ray_cpp_lib",
  260. "@boost//:callable_traits",
  261. "@boost//:optional",
  262. "@msgpack",
  263. ],
  264. )
  265. cc_test(
  266. name = "simple_kv_store",
  267. srcs = glob([
  268. "src/ray/test/examples/*.cc",
  269. ]),
  270. args = [
  271. "--ray_code_search_path=$(location simple_kv_store.so)",
  272. "--ray_head_args '--include-dashboard false'",
  273. ],
  274. copts = COPTS,
  275. data = [
  276. "simple_kv_store.so",
  277. ],
  278. linkstatic = True,
  279. tags = ["team:core"],
  280. deps = [
  281. "ray_api",
  282. ],
  283. )
  284. cc_binary(
  285. name = "simple_kv_store.so",
  286. testonly = True,
  287. srcs = glob([
  288. "src/ray/test/examples/*.cc",
  289. ]),
  290. copts = COPTS,
  291. linkopts = ["-shared"],
  292. linkstatic = True,
  293. deps = [
  294. "ray_cpp_lib",
  295. "@boost//:callable_traits",
  296. "@boost//:optional",
  297. "@msgpack",
  298. ],
  299. )
  300. load("//bazel:python.bzl", "py_test_module_list")
  301. py_test_module_list(
  302. size = "small",
  303. extra_srcs = [],
  304. files = [
  305. "test_python_call_cpp.py",
  306. ],
  307. tags = [
  308. "exclusive",
  309. "small_size_python_tests",
  310. "team:core",
  311. ],
  312. deps = [],
  313. )