ray.bzl 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_library_public")
  2. load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
  3. load("@bazel_common//tools/maven:pom_file.bzl", "pom_file")
  4. COPTS_WITHOUT_LOG = select({
  5. "//:opt": ["-DBAZEL_OPT"],
  6. "//conditions:default": [],
  7. }) + select({
  8. "@bazel_tools//src/conditions:windows": [
  9. # TODO(mehrdadn): (How to) support dynamic linking?
  10. "-DRAY_STATIC",
  11. ],
  12. "//conditions:default": [
  13. ],
  14. }) + select({
  15. "//:clang-cl": [
  16. "-Wno-builtin-macro-redefined", # To get rid of warnings caused by deterministic build macros (e.g. #define __DATE__ "redacted")
  17. "-Wno-microsoft-unqualified-friend", # This shouldn't normally be enabled, but otherwise we get: google/protobuf/map_field.h: warning: unqualified friend declaration referring to type outside of the nearest enclosing namespace is a Microsoft extension; add a nested name specifier (for: friend class DynamicMessage)
  18. ],
  19. "//conditions:default": [
  20. ],
  21. })
  22. COPTS = COPTS_WITHOUT_LOG
  23. PYX_COPTS = select({
  24. "//:msvc-cl": [
  25. ],
  26. "//conditions:default": [
  27. # Ignore this warning since CPython and Cython have issue removing deprecated tp_print on MacOS
  28. "-Wno-deprecated-declarations",
  29. ],
  30. }) + select({
  31. "@bazel_tools//src/conditions:windows": [
  32. "/FI" + "src/shims/windows/python-nondebug.h",
  33. ],
  34. "//conditions:default": [
  35. ],
  36. })
  37. PYX_SRCS = [] + select({
  38. "@bazel_tools//src/conditions:windows": [
  39. "src/shims/windows/python-nondebug.h",
  40. ],
  41. "//conditions:default": [
  42. ],
  43. })
  44. def flatbuffer_py_library(name, srcs, outs, out_prefix, includes = [], include_paths = []):
  45. flatbuffer_library_public(
  46. name = name,
  47. srcs = srcs,
  48. outs = outs,
  49. language_flag = "-p",
  50. out_prefix = out_prefix,
  51. include_paths = include_paths,
  52. includes = includes,
  53. )
  54. def define_java_module(
  55. name,
  56. additional_srcs = [],
  57. exclude_srcs = [],
  58. additional_resources = [],
  59. define_test_lib = False,
  60. test_deps = [],
  61. **kwargs):
  62. lib_name = "io_ray_ray_" + name
  63. pom_file_targets = [lib_name]
  64. native.java_library(
  65. name = lib_name,
  66. srcs = additional_srcs + native.glob(
  67. [name + "/src/main/java/**/*.java"],
  68. exclude = exclude_srcs,
  69. ),
  70. resources = native.glob([name + "/src/main/resources/**"]) + additional_resources,
  71. **kwargs
  72. )
  73. if define_test_lib:
  74. test_lib_name = "io_ray_ray_" + name + "_test"
  75. pom_file_targets.append(test_lib_name)
  76. native.java_library(
  77. name = test_lib_name,
  78. srcs = native.glob([name + "/src/test/java/**/*.java"]),
  79. deps = test_deps,
  80. )
  81. pom_file(
  82. name = "io_ray_ray_" + name + "_pom",
  83. targets = pom_file_targets,
  84. template_file = name + "/pom_template.xml",
  85. substitutions = {
  86. "{auto_gen_header}": "<!-- This file is auto-generated by Bazel from pom_template.xml, do not modify it. -->",
  87. },
  88. )
  89. def copy_to_workspace(name, srcs, dstdir = ""):
  90. if dstdir.startswith("/") or dstdir.startswith("\\"):
  91. fail("Subdirectory must be a relative path: " + dstdir)
  92. src_locations = " ".join(["$(locations %s)" % (src,) for src in srcs])
  93. native.genrule(
  94. name = name,
  95. srcs = srcs,
  96. outs = [name + ".out"],
  97. cmd = r"""
  98. mkdir -p -- {dstdir}
  99. for f in {locations}; do
  100. rm -f -- {dstdir}$${{f##*/}}
  101. cp -f -- "$$f" {dstdir}
  102. done
  103. date > $@
  104. """.format(
  105. locations = src_locations,
  106. dstdir = "." + ("/" + dstdir.replace("\\", "/")).rstrip("/") + "/",
  107. ),
  108. local = 1,
  109. tags = ["no-cache"],
  110. )
  111. def native_java_binary(module_name, name, native_binary_name):
  112. """Copy native binary file to different path based on operating systems"""
  113. copy_file(
  114. name = name + "_darwin",
  115. src = native_binary_name,
  116. out = module_name + "/src/main/resources/native/darwin/" + name,
  117. )
  118. copy_file(
  119. name = name + "_linux",
  120. src = native_binary_name,
  121. out = module_name + "/src/main/resources/native/linux/" + name,
  122. )
  123. copy_file(
  124. name = name + "_windows",
  125. src = native_binary_name,
  126. out = module_name + "/src/main/resources/native/windows/" + name,
  127. )
  128. native.filegroup(
  129. name = name,
  130. srcs = select({
  131. "@bazel_tools//src/conditions:darwin": [name + "_darwin"],
  132. "@bazel_tools//src/conditions:windows": [name + "_windows"],
  133. "//conditions:default": [name + "_linux"],
  134. }),
  135. visibility = ["//visibility:public"],
  136. )
  137. def native_java_library(module_name, name, native_library_name):
  138. """Copy native library file to different path based on operating systems"""
  139. copy_file(
  140. name = name + "_darwin",
  141. src = native_library_name,
  142. out = module_name + "/src/main/resources/native/darwin/lib{}.dylib".format(name),
  143. )
  144. copy_file(
  145. name = name + "_linux",
  146. src = native_library_name,
  147. out = module_name + "/src/main/resources/native/linux/lib{}.so".format(name),
  148. )
  149. native.filegroup(
  150. name = name,
  151. srcs = select({
  152. "@bazel_tools//src/conditions:darwin": [name + "_darwin"],
  153. "@bazel_tools//src/conditions:windows": [],
  154. "//conditions:default": [name + "_linux"],
  155. }),
  156. visibility = ["//visibility:public"],
  157. )