libuv.BUILD 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. # Copyright 2021 gRPC authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. load("@bazel_skylib//lib:selects.bzl", "selects")
  15. config_setting(
  16. name = "darwin",
  17. values = {"cpu": "darwin"},
  18. )
  19. config_setting(
  20. name = "darwin_x86_64",
  21. values = {"cpu": "darwin_x86_64"},
  22. )
  23. config_setting(
  24. name = "darwin_arm64",
  25. values = {"cpu": "darwin_arm64"},
  26. )
  27. config_setting(
  28. name = "darwin_arm64e",
  29. values = {"cpu": "darwin_arm64e"},
  30. )
  31. config_setting(
  32. name = "windows",
  33. values = {"cpu": "x64_windows"},
  34. )
  35. config_setting(
  36. name = "freebsd",
  37. constraint_values = ["@platforms//os:freebsd"],
  38. )
  39. # Android is not officially supported through C++.
  40. # This just helps with the build for now.
  41. config_setting(
  42. name = "android",
  43. values = {
  44. "crosstool_top": "//external:android/crosstool",
  45. },
  46. )
  47. # iOS is not officially supported through C++.
  48. # This just helps with the build for now.
  49. config_setting(
  50. name = "ios_x86_64",
  51. values = {"cpu": "ios_x86_64"},
  52. )
  53. config_setting(
  54. name = "ios_armv7",
  55. values = {"cpu": "ios_armv7"},
  56. )
  57. config_setting(
  58. name = "ios_armv7s",
  59. values = {"cpu": "ios_armv7s"},
  60. )
  61. config_setting(
  62. name = "ios_arm64",
  63. values = {"cpu": "ios_arm64"},
  64. )
  65. # The following architectures are found in
  66. # https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java
  67. config_setting(
  68. name = "tvos_x86_64",
  69. values = {"cpu": "tvos_x86_64"},
  70. )
  71. config_setting(
  72. name = "tvos_arm64",
  73. values = {"cpu": "tvos_arm64"},
  74. )
  75. config_setting(
  76. name = "watchos_i386",
  77. values = {"cpu": "watchos_i386"},
  78. )
  79. config_setting(
  80. name = "watchos_x86_64",
  81. values = {"cpu": "watchos_x86_64"},
  82. )
  83. config_setting(
  84. name = "watchos_armv7k",
  85. values = {"cpu": "watchos_armv7k"},
  86. )
  87. config_setting(
  88. name = "watchos_arm64_32",
  89. values = {"cpu": "watchos_arm64_32"},
  90. )
  91. selects.config_setting_group(
  92. name = "apple",
  93. match_any = [
  94. ":darwin",
  95. ":darwin_x86_64",
  96. ":darwin_arm64",
  97. ":darwin_arm64e",
  98. "ios_x86_64",
  99. "ios_armv7",
  100. "ios_armv7s",
  101. "ios_arm64",
  102. "tvos_x86_64",
  103. "tvos_arm64",
  104. "watchos_i386",
  105. "watchos_x86_64",
  106. "watchos_armv7k",
  107. "watchos_arm64_32",
  108. ],
  109. )
  110. COMMON_LIBUV_HEADERS = [
  111. "include/uv.h",
  112. "include/uv/errno.h",
  113. "include/uv/threadpool.h",
  114. "include/uv/version.h",
  115. "include/uv/tree.h",
  116. ]
  117. UNIX_LIBUV_HEADERS = [
  118. "include/uv/unix.h",
  119. "src/unix/atomic-ops.h",
  120. "src/unix/internal.h",
  121. "src/unix/spinlock.h",
  122. ]
  123. LINUX_LIBUV_HEADERS = [
  124. "include/uv/linux.h",
  125. "src/unix/linux-syscalls.h",
  126. ]
  127. ANDROID_LIBUV_HEADERS = [
  128. "include/uv/android-ifaddrs.h",
  129. ]
  130. DARWIN_LIBUV_HEADERS = [
  131. "include/uv/darwin.h",
  132. ]
  133. WINDOWS_LIBUV_HEADERS = [
  134. "include/uv/win.h",
  135. "src/win/atomicops-inl.h",
  136. "src/win/handle-inl.h",
  137. "src/win/internal.h",
  138. "src/win/req-inl.h",
  139. "src/win/stream-inl.h",
  140. "src/win/winapi.h",
  141. "src/win/winsock.h",
  142. ]
  143. COMMON_LIBUV_SOURCES = [
  144. "src/fs-poll.c",
  145. "src/heap-inl.h",
  146. "src/idna.c",
  147. "src/idna.h",
  148. "src/inet.c",
  149. "src/queue.h",
  150. "src/strscpy.c",
  151. "src/strscpy.h",
  152. "src/threadpool.c",
  153. "src/timer.c",
  154. "src/uv-data-getter-setters.c",
  155. "src/uv-common.c",
  156. "src/uv-common.h",
  157. "src/version.c",
  158. ]
  159. UNIX_LIBUV_SOURCES = [
  160. "src/unix/async.c",
  161. "src/unix/atomic-ops.h",
  162. "src/unix/core.c",
  163. "src/unix/dl.c",
  164. "src/unix/fs.c",
  165. "src/unix/getaddrinfo.c",
  166. "src/unix/getnameinfo.c",
  167. "src/unix/internal.h",
  168. "src/unix/loop.c",
  169. "src/unix/loop-watcher.c",
  170. "src/unix/pipe.c",
  171. "src/unix/poll.c",
  172. "src/unix/process.c",
  173. "src/unix/signal.c",
  174. "src/unix/spinlock.h",
  175. "src/unix/stream.c",
  176. "src/unix/tcp.c",
  177. "src/unix/thread.c",
  178. "src/unix/tty.c",
  179. "src/unix/udp.c",
  180. ]
  181. LINUX_LIBUV_SOURCES = [
  182. "src/unix/linux-core.c",
  183. "src/unix/linux-inotify.c",
  184. "src/unix/linux-syscalls.c",
  185. "src/unix/linux-syscalls.h",
  186. "src/unix/procfs-exepath.c",
  187. "src/unix/proctitle.c",
  188. "src/unix/sysinfo-loadavg.c",
  189. "src/unix/sysinfo-memory.c",
  190. ]
  191. ANDROID_LIBUV_SOURCES = [
  192. "src/unix/android-ifaddrs.c",
  193. "src/unix/pthread-fixes.c",
  194. ]
  195. DARWIN_LIBUV_SOURCES = [
  196. "src/unix/bsd-ifaddrs.c",
  197. "src/unix/darwin.c",
  198. "src/unix/fsevents.c",
  199. "src/unix/kqueue.c",
  200. "src/unix/darwin-proctitle.c",
  201. "src/unix/proctitle.c",
  202. ]
  203. WINDOWS_LIBUV_SOURCES = [
  204. "src/win/async.c",
  205. "src/win/atomicops-inl.h",
  206. "src/win/core.c",
  207. "src/win/detect-wakeup.c",
  208. "src/win/dl.c",
  209. "src/win/error.c",
  210. "src/win/fs-event.c",
  211. "src/win/fs.c",
  212. "src/win/getaddrinfo.c",
  213. "src/win/getnameinfo.c",
  214. "src/win/handle.c",
  215. "src/win/handle-inl.h",
  216. "src/win/internal.h",
  217. "src/win/loop-watcher.c",
  218. "src/win/pipe.c",
  219. "src/win/poll.c",
  220. "src/win/process-stdio.c",
  221. "src/win/process.c",
  222. "src/win/req-inl.h",
  223. "src/win/signal.c",
  224. "src/win/stream.c",
  225. "src/win/stream-inl.h",
  226. "src/win/tcp.c",
  227. "src/win/thread.c",
  228. "src/win/tty.c",
  229. "src/win/udp.c",
  230. "src/win/util.c",
  231. "src/win/winapi.c",
  232. "src/win/winapi.h",
  233. "src/win/winsock.c",
  234. "src/win/winsock.h",
  235. ]
  236. cc_library(
  237. name = "libuv",
  238. srcs = select({
  239. ":android": COMMON_LIBUV_SOURCES + UNIX_LIBUV_SOURCES + LINUX_LIBUV_SOURCES + ANDROID_LIBUV_SOURCES,
  240. ":apple": COMMON_LIBUV_SOURCES + UNIX_LIBUV_SOURCES + DARWIN_LIBUV_SOURCES,
  241. ":windows": COMMON_LIBUV_SOURCES + WINDOWS_LIBUV_SOURCES,
  242. "//conditions:default": COMMON_LIBUV_SOURCES + UNIX_LIBUV_SOURCES + LINUX_LIBUV_SOURCES,
  243. }),
  244. hdrs = select({
  245. ":android": COMMON_LIBUV_HEADERS + UNIX_LIBUV_HEADERS + LINUX_LIBUV_HEADERS + ANDROID_LIBUV_HEADERS,
  246. ":apple": COMMON_LIBUV_HEADERS + UNIX_LIBUV_HEADERS + DARWIN_LIBUV_HEADERS,
  247. ":windows": COMMON_LIBUV_HEADERS + WINDOWS_LIBUV_HEADERS,
  248. "//conditions:default": COMMON_LIBUV_HEADERS + UNIX_LIBUV_HEADERS + LINUX_LIBUV_HEADERS,
  249. }),
  250. copts = [
  251. "-D_LARGEFILE_SOURCE",
  252. "-D_FILE_OFFSET_BITS=64",
  253. "-D_GNU_SOURCE",
  254. "-pthread",
  255. "--std=gnu89",
  256. "-pedantic",
  257. "-Wno-error",
  258. "-Wno-strict-aliasing",
  259. "-Wstrict-aliasing",
  260. "-O2",
  261. "-Wno-implicit-function-declaration",
  262. "-Wno-unused-function",
  263. "-Wno-unused-variable",
  264. ] + select({
  265. ":apple": [],
  266. ":windows": [
  267. "-DWIN32_LEAN_AND_MEAN",
  268. "-D_WIN32_WINNT=0x0600",
  269. ],
  270. "//conditions:default": [
  271. "-Wno-tree-vrp",
  272. "-Wno-omit-frame-pointer",
  273. "-D_DARWIN_USE_64_BIT_INODE=1",
  274. "-D_DARWIN_UNLIMITED_SELECT=1",
  275. ],
  276. }),
  277. includes = [
  278. "include",
  279. "src",
  280. ],
  281. linkopts = select({
  282. ":windows": [
  283. "-Xcrosstool-compilation-mode=$(COMPILATION_MODE)",
  284. "-Wl,Iphlpapi.lib",
  285. "-Wl,Psapi.lib",
  286. "-Wl,User32.lib",
  287. "-Wl,Userenv.lib",
  288. ],
  289. "//conditions:default": [],
  290. }),
  291. visibility = [
  292. "//visibility:public",
  293. ],
  294. )