ray_deps_setup.bzl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
  2. load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
  3. def urlsplit(url):
  4. """ Splits a URL like "https://example.com/a/b?c=d&e#f" into a tuple:
  5. ("https", ["example", "com"], ["a", "b"], ["c=d", "e"], "f")
  6. A trailing slash will result in a correspondingly empty final path component.
  7. """
  8. split_on_anchor = url.split("#", 1)
  9. split_on_query = split_on_anchor[0].split("?", 1)
  10. split_on_scheme = split_on_query[0].split("://", 1)
  11. if len(split_on_scheme) <= 1: # Scheme is optional
  12. split_on_scheme = [None] + split_on_scheme[:1]
  13. split_on_path = split_on_scheme[1].split("/")
  14. return {
  15. "scheme": split_on_scheme[0],
  16. "netloc": split_on_path[0].split("."),
  17. "path": split_on_path[1:],
  18. "query": split_on_query[1].split("&") if len(split_on_query) > 1 else None,
  19. "fragment": split_on_anchor[1] if len(split_on_anchor) > 1 else None,
  20. }
  21. def auto_http_archive(
  22. *,
  23. name = None,
  24. url = None,
  25. urls = True,
  26. build_file = None,
  27. build_file_content = None,
  28. strip_prefix = True,
  29. **kwargs):
  30. """ Intelligently choose mirrors based on the given URL for the download.
  31. Either url or urls is required.
  32. If name == None , it is auto-deduced, but this is NOT recommended.
  33. If urls == True , mirrors are automatically chosen.
  34. If build_file == True , it is auto-deduced.
  35. If strip_prefix == True , it is auto-deduced.
  36. """
  37. DOUBLE_SUFFIXES_LOWERCASE = [("tar", "bz2"), ("tar", "gz"), ("tar", "xz")]
  38. mirror_prefixes = ["https://mirror.bazel.build/", "https://storage.googleapis.com/bazel-mirror"]
  39. canonical_url = url if url != None else urls[0]
  40. url_parts = urlsplit(canonical_url)
  41. url_except_scheme = (canonical_url.replace(url_parts["scheme"] + "://", "") if url_parts["scheme"] != None else canonical_url)
  42. url_path_parts = url_parts["path"]
  43. url_filename = url_path_parts[-1]
  44. url_filename_parts = (url_filename.rsplit(".", 2) if (tuple(url_filename.lower().rsplit(".", 2)[-2:]) in
  45. DOUBLE_SUFFIXES_LOWERCASE) else url_filename.rsplit(".", 1))
  46. is_github = url_parts["netloc"] == ["github", "com"]
  47. if name == None: # Deduce "com_github_user_project_name" from "https://github.com/user/project-name/..."
  48. name = "_".join(url_parts["netloc"][::-1] + url_path_parts[:2]).replace("-", "_")
  49. # auto appending ray project namespace prefix for 3rd party library reusing.
  50. if build_file == True:
  51. build_file = "@com_github_ray_project_ray//%s:%s" % ("bazel", "BUILD." + name)
  52. if urls == True:
  53. prefer_url_over_mirrors = is_github
  54. urls = [
  55. mirror_prefix + url_except_scheme
  56. for mirror_prefix in mirror_prefixes
  57. if not canonical_url.startswith(mirror_prefix)
  58. ]
  59. urls.insert(0 if prefer_url_over_mirrors else len(urls), canonical_url)
  60. else:
  61. print("No implicit mirrors used for %s because urls were explicitly provided" % name)
  62. if strip_prefix == True:
  63. prefix_without_v = url_filename_parts[0]
  64. if prefix_without_v.startswith("v") and prefix_without_v[1:2].isdigit():
  65. # GitHub automatically strips a leading 'v' in version numbers
  66. prefix_without_v = prefix_without_v[1:]
  67. strip_prefix = (url_path_parts[1] + "-" + prefix_without_v if is_github and url_path_parts[2:3] == ["archive"] else url_filename_parts[0])
  68. return http_archive(
  69. name = name,
  70. url = url,
  71. urls = urls,
  72. build_file = build_file,
  73. build_file_content = build_file_content,
  74. strip_prefix = strip_prefix,
  75. **kwargs
  76. )
  77. def ray_deps_setup():
  78. # Explicitly bring in protobuf dependency to work around
  79. # https://github.com/ray-project/ray/issues/14117
  80. # This is copied from grpc's bazel/grpc_deps.bzl
  81. http_archive(
  82. name = "com_google_protobuf",
  83. sha256 = "76a33e2136f23971ce46c72fd697cd94dc9f73d56ab23b753c3e16854c90ddfd",
  84. strip_prefix = "protobuf-2c5fa078d8e86e5f4bd34e6f4c9ea9e8d7d4d44a",
  85. urls = [
  86. # https://github.com/protocolbuffers/protobuf/commits/v23.4
  87. "https://github.com/protocolbuffers/protobuf/archive/2c5fa078d8e86e5f4bd34e6f4c9ea9e8d7d4d44a.tar.gz",
  88. ],
  89. patches = [
  90. "@com_github_grpc_grpc//third_party:protobuf.patch",
  91. ],
  92. patch_args = ["-p1"],
  93. )
  94. # NOTE(lingxuan.zlx): 3rd party dependencies could be accessed, so it suggests
  95. # all of http/git_repository should add prefix for patches defined in ray directory.
  96. auto_http_archive(
  97. name = "com_github_antirez_redis",
  98. build_file = "@com_github_ray_project_ray//bazel:BUILD.redis",
  99. patch_args = ["-p1"],
  100. url = "https://github.com/redis/redis/archive/refs/tags/7.2.3.tar.gz",
  101. sha256 = "afd656dbc18a886f9a1cc08a550bf5eb89de0d431e713eba3ae243391fb008a6",
  102. patches = [
  103. "@com_github_ray_project_ray//thirdparty/patches:redis-quiet.patch",
  104. ],
  105. workspace_file_content = 'workspace(name = "com_github_antirez_redis")',
  106. )
  107. auto_http_archive(
  108. name = "com_github_redis_hiredis",
  109. build_file = "@com_github_ray_project_ray//bazel:BUILD.hiredis",
  110. url = "https://github.com/redis/hiredis/archive/60e5075d4ac77424809f855ba3e398df7aacefe8.tar.gz",
  111. sha256 = "b6d6f799b7714d85316f9ebfb76a35a78744f42ea3b6774289d882d13a2f0383",
  112. patches = [
  113. "@com_github_ray_project_ray//thirdparty/patches:hiredis-windows-msvc.patch",
  114. ],
  115. )
  116. auto_http_archive(
  117. name = "com_github_spdlog",
  118. build_file = "@com_github_ray_project_ray//bazel:BUILD.spdlog",
  119. urls = ["https://github.com/gabime/spdlog/archive/v1.12.0.zip"],
  120. sha256 = "6174bf8885287422a6c6a0312eb8a30e8d22bcfcee7c48a6d02d1835d7769232",
  121. )
  122. auto_http_archive(
  123. name = "com_github_tporadowski_redis_bin",
  124. build_file = "@com_github_ray_project_ray//bazel:BUILD.redis",
  125. strip_prefix = None,
  126. url = "https://github.com/tporadowski/redis/releases/download/v5.0.9/Redis-x64-5.0.9.zip",
  127. sha256 = "b09565b22b50c505a5faa86a7e40b6683afb22f3c17c5e6a5e35fc9b7c03f4c2",
  128. )
  129. auto_http_archive(
  130. name = "rules_jvm_external",
  131. url = "https://github.com/bazelbuild/rules_jvm_external/archive/2.10.tar.gz",
  132. sha256 = "5c1b22eab26807d5286ada7392d796cbc8425d3ef9a57d114b79c5f8ef8aca7c",
  133. )
  134. auto_http_archive(
  135. name = "bazel_common",
  136. url = "https://github.com/google/bazel-common/archive/084aadd3b854cad5d5e754a7e7d958ac531e6801.tar.gz",
  137. sha256 = "a6e372118bc961b182a3a86344c0385b6b509882929c6b12dc03bb5084c775d5",
  138. )
  139. http_archive(
  140. name = "bazel_skylib",
  141. sha256 = "9f38886a40548c6e96c106b752f242130ee11aaa068a56ba7e56f4511f33e4f2",
  142. urls = [
  143. "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.6.1/bazel-skylib-1.6.1.tar.gz",
  144. "https://github.com/bazelbuild/bazel-skylib/releases/download/1.6.1/bazel-skylib-1.6.1.tar.gz",
  145. ],
  146. )
  147. auto_http_archive(
  148. name = "com_github_nelhage_rules_boost",
  149. # If you update the Boost version, remember to update the 'boost' rule.
  150. url = "https://github.com/nelhage/rules_boost/archive/57c99395e15720e287471d79178d36a85b64d6f6.tar.gz",
  151. sha256 = "490d11425393eed068966a4990ead1ff07c658f823fd982fddac67006ccc44ab",
  152. )
  153. auto_http_archive(
  154. name = "com_github_google_flatbuffers",
  155. url = "https://github.com/google/flatbuffers/archive/63d51afd1196336a7d1f56a988091ef05deb1c62.tar.gz",
  156. sha256 = "3f469032571d324eabea88d7014c05fec8565a5877dbe49b2a52d8d1a0f18e63",
  157. )
  158. auto_http_archive(
  159. name = "com_google_googletest",
  160. url = "https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz",
  161. sha256 = "8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7",
  162. )
  163. auto_http_archive(
  164. name = "com_github_gflags_gflags",
  165. url = "https://github.com/gflags/gflags/archive/e171aa2d15ed9eb17054558e0b3a6a413bb01067.tar.gz",
  166. sha256 = "b20f58e7f210ceb0e768eb1476073d0748af9b19dfbbf53f4fd16e3fb49c5ac8",
  167. )
  168. auto_http_archive(
  169. name = "cython",
  170. build_file = True,
  171. url = "https://github.com/cython/cython/archive/refs/tags/0.29.37.tar.gz",
  172. sha256 = "824eb14045d85c5af677536134199dd6709db8fb0835452fd2d54bc3c8df8887",
  173. )
  174. auto_http_archive(
  175. name = "com_github_johnynek_bazel_jar_jar",
  176. url = "https://github.com/johnynek/bazel_jar_jar/archive/171f268569384c57c19474b04aebe574d85fde0d.tar.gz",
  177. sha256 = "97c5f862482a05f385bd8f9d28a9bbf684b0cf3fae93112ee96f3fb04d34b193",
  178. )
  179. auto_http_archive(
  180. name = "io_opencensus_cpp",
  181. url = "https://github.com/census-instrumentation/opencensus-cpp/archive/5e5f2632c84e2230fb7ccb8e336f603d2ec6aa1b.zip",
  182. sha256 = "1b88d6663f05c6a56c1604eb2afad22831d5f28a76f6fab8f37187f1e4ace425",
  183. patches = [
  184. "@com_github_ray_project_ray//thirdparty/patches:opencensus-cpp-harvest-interval.patch",
  185. "@com_github_ray_project_ray//thirdparty/patches:opencensus-cpp-shutdown-api.patch",
  186. ],
  187. patch_args = ["-p1"],
  188. )
  189. # OpenCensus depends on Abseil so we have to explicitly pull it in.
  190. # This is how diamond dependencies are prevented.
  191. auto_http_archive(
  192. name = "com_google_absl",
  193. sha256 = "5366d7e7fa7ba0d915014d387b66d0d002c03236448e1ba9ef98122c13b35c36",
  194. strip_prefix = "abseil-cpp-20230125.3",
  195. urls = [
  196. "https://github.com/abseil/abseil-cpp/archive/20230125.3.tar.gz",
  197. ],
  198. )
  199. # OpenCensus depends on jupp0r/prometheus-cpp
  200. auto_http_archive(
  201. name = "com_github_jupp0r_prometheus_cpp",
  202. url = "https://github.com/jupp0r/prometheus-cpp/archive/60eaa4ea47b16751a8e8740b05fe70914c68a480.tar.gz",
  203. sha256 = "ec825b802487ac18b0d98e2e8b7961487b12562f8f82e424521d0a891d9e1373",
  204. patches = [
  205. "@com_github_ray_project_ray//thirdparty/patches:prometheus-windows-headers.patch",
  206. # https://github.com/jupp0r/prometheus-cpp/pull/225
  207. "@com_github_ray_project_ray//thirdparty/patches:prometheus-windows-zlib.patch",
  208. "@com_github_ray_project_ray//thirdparty/patches:prometheus-windows-pollfd.patch",
  209. ],
  210. )
  211. auto_http_archive(
  212. name = "com_github_grpc_grpc",
  213. # NOTE: If you update this, also update @boringssl's hash.
  214. url = "https://github.com/grpc/grpc/archive/refs/tags/v1.57.1.tar.gz",
  215. sha256 = "0762f809b9de845e6a7c809cabccad6aa4143479fd43b396611fe5a086c0aeeb",
  216. patches = [
  217. "@com_github_ray_project_ray//thirdparty/patches:grpc-cython-copts.patch",
  218. ],
  219. )
  220. http_archive(
  221. name = "openssl",
  222. strip_prefix = "openssl-1.1.1f",
  223. sha256 = "186c6bfe6ecfba7a5b48c47f8a1673d0f3b0e5ba2e25602dd23b629975da3f35",
  224. urls = [
  225. "https://openssl.org/source/old/1.1.1/openssl-1.1.1f.tar.gz",
  226. ],
  227. build_file = "@rules_foreign_cc_thirdparty//openssl:BUILD.openssl.bazel",
  228. )
  229. http_archive(
  230. name = "rules_foreign_cc",
  231. sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
  232. strip_prefix = "rules_foreign_cc-0.9.0",
  233. url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
  234. )
  235. # Using shallow_since allows the rule to clone down fewer commits.
  236. # Reference: https://bazel.build/rules/lib/repo/git
  237. git_repository(
  238. name = "rules_perl",
  239. remote = "https://github.com/bazelbuild/rules_perl.git",
  240. commit = "022b8daf2bb4836ac7a50e4a1d8ea056a3e1e403",
  241. shallow_since = "1663780239 -0700",
  242. )
  243. http_archive(
  244. name = "rules_foreign_cc_thirdparty",
  245. sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
  246. strip_prefix = "rules_foreign_cc-0.9.0/examples/third_party",
  247. url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
  248. )
  249. http_archive(
  250. # This rule is used by @com_github_grpc_grpc, and using a GitHub mirror
  251. # provides a deterministic archive hash for caching. Explanation here:
  252. # https://github.com/grpc/grpc/blob/1ff1feaa83e071d87c07827b0a317ffac673794f/bazel/grpc_deps.bzl#L189
  253. # Ensure this rule matches the rule used by grpc's bazel/grpc_deps.bzl
  254. name = "boringssl",
  255. sha256 = "0675a4f86ce5e959703425d6f9063eaadf6b61b7f3399e77a154c0e85bad46b1",
  256. strip_prefix = "boringssl-342e805bc1f5dfdd650e3f031686d6c939b095d9",
  257. urls = [
  258. "https://github.com/google/boringssl/archive/342e805bc1f5dfdd650e3f031686d6c939b095d9.tar.gz",
  259. ],
  260. )
  261. # The protobuf version we use to auto generate python and java code.
  262. # This can be different from the protobuf version that Ray core uses internally.
  263. # Generally this should be a lower version since protobuf guarantees that
  264. # code generated by protoc of version X can be used with protobuf library of version >= X.
  265. # So the version here effectively determines the lower bound of python/java
  266. # protobuf library that Ray supports.
  267. http_archive(
  268. name = "com_google_protobuf_rules_proto_grpc",
  269. strip_prefix = "protobuf-3.19.4",
  270. urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.4.tar.gz"],
  271. sha256 = "3bd7828aa5af4b13b99c191e8b1e884ebfa9ad371b0ce264605d347f135d2568",
  272. )
  273. auto_http_archive(
  274. name = "rules_proto_grpc",
  275. url = "https://github.com/rules-proto-grpc/rules_proto_grpc/archive/a74fef39c5fe636580083545f76d1eab74f6450d.tar.gz",
  276. sha256 = "2f6606151ec042e23396f07de9e7dcf6ca9a5db1d2b09f0cc93a7fc7f4008d1b",
  277. repo_mapping = {
  278. "@com_google_protobuf": "@com_google_protobuf_rules_proto_grpc",
  279. },
  280. )
  281. auto_http_archive(
  282. name = "msgpack",
  283. build_file = True,
  284. url = "https://github.com/msgpack/msgpack-c/archive/8085ab8721090a447cf98bb802d1406ad7afe420.tar.gz",
  285. sha256 = "83c37c9ad926bbee68d564d9f53c6cbb057c1f755c264043ddd87d89e36d15bb",
  286. patches = [
  287. "@com_github_ray_project_ray//thirdparty/patches:msgpack-windows-iovec.patch",
  288. ],
  289. )
  290. http_archive(
  291. name = "io_opencensus_proto",
  292. strip_prefix = "opencensus-proto-0.3.0/src",
  293. urls = ["https://github.com/census-instrumentation/opencensus-proto/archive/v0.3.0.tar.gz"],
  294. sha256 = "b7e13f0b4259e80c3070b583c2f39e53153085a6918718b1c710caf7037572b0",
  295. )
  296. http_archive(
  297. name = "nlohmann_json",
  298. strip_prefix = "json-3.9.1",
  299. urls = ["https://github.com/nlohmann/json/archive/v3.9.1.tar.gz"],
  300. sha256 = "4cf0df69731494668bdd6460ed8cb269b68de9c19ad8c27abc24cd72605b2d5b",
  301. build_file = "@com_github_ray_project_ray//bazel:BUILD.nlohmann_json",
  302. )
  303. auto_http_archive(
  304. name = "rapidjson",
  305. url = "https://github.com/Tencent/rapidjson/archive/v1.1.0.zip",
  306. build_file = True,
  307. sha256 = "8e00c38829d6785a2dfb951bb87c6974fa07dfe488aa5b25deec4b8bc0f6a3ab",
  308. )
  309. # Hedron's Compile Commands Extractor for Bazel
  310. # https://github.com/hedronvision/bazel-compile-commands-extractor
  311. http_archive(
  312. name = "hedron_compile_commands",
  313. # Replace the commit hash in both places (below) with the latest, rather than using the stale one here.
  314. # Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
  315. url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/2e8b7654fa10c44b9937453fa4974ed2229d5366.tar.gz",
  316. strip_prefix = "bazel-compile-commands-extractor-2e8b7654fa10c44b9937453fa4974ed2229d5366",
  317. # When you first run this tool, it'll recommend a sha256 hash to put here with a message like: "DEBUG: Rule 'hedron_compile_commands' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = ..."
  318. sha256 = "7fbbbc05c112c44e9b406612e6a7a7f4789a6918d7aacefef4c35c105286930c",
  319. )
  320. http_archive(
  321. name = "jemalloc",
  322. urls = ["https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2"],
  323. build_file = "@com_github_ray_project_ray//bazel:BUILD.jemalloc",
  324. sha256 = "2db82d1e7119df3e71b7640219b6dfe84789bc0537983c3b7ac4f7189aecfeaa",
  325. strip_prefix = "jemalloc-5.3.0",
  326. )