install.BUILD 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. load("@bazel_skylib//rules:common_settings.bzl", "string_list_setting")
  5. load("@rules_cc//cc:defs.bzl", "cc_library")
  6. load("//bazel:carbon_cc_toolchain_config.bzl", "carbon_cc_toolchain_suite")
  7. load("//bazel:carbon_runtimes.bzl", "carbon_runtimes")
  8. load("//bazel:make_include_copts.bzl", "make_include_copts")
  9. load(
  10. "//bazel:runtimes_build_vars.bzl",
  11. "builtins_aarch64_srcs",
  12. "builtins_aarch64_textual_srcs",
  13. "builtins_copts",
  14. "builtins_i386_srcs",
  15. "builtins_i386_textual_srcs",
  16. "builtins_x86_64_srcs",
  17. "builtins_x86_64_textual_srcs",
  18. "crt_copts",
  19. "crtbegin_src",
  20. "crtend_src",
  21. "libc_internal_libcxx_hdrs",
  22. "libcxx_copts",
  23. "libcxx_hdrs",
  24. "libcxx_linux_srcs",
  25. "libcxx_macos_srcs",
  26. "libcxx_win32_srcs",
  27. "libcxxabi_hdrs",
  28. "libcxxabi_srcs",
  29. "libcxxabi_textual_srcs",
  30. "libunwind_copts",
  31. "libunwind_hdrs",
  32. "libunwind_srcs",
  33. "llvm_version_major",
  34. )
  35. _libcxx_hdrs = libcxx_hdrs + [
  36. "runtimes/libcxx/include/__config_site",
  37. "runtimes/libcxx/include/__assertion_handler",
  38. ]
  39. package(default_visibility = ["//visibility:public"])
  40. constraint_setting(name = "runtimes_build")
  41. constraint_value(
  42. name = "is_runtimes_build",
  43. constraint_setting = ":runtimes_build",
  44. )
  45. filegroup(
  46. name = "llvm_bins",
  47. srcs = glob(["llvm/bin/*"]),
  48. )
  49. filegroup(
  50. name = "clang_hdrs",
  51. srcs = glob(["llvm/lib/clang/{0}/include/*".format(llvm_version_major)]),
  52. )
  53. filegroup(
  54. name = "libcxx_hdrs",
  55. srcs = _libcxx_hdrs + libcxxabi_hdrs,
  56. )
  57. filegroup(
  58. name = "libunwind_hdrs",
  59. srcs = libunwind_hdrs,
  60. )
  61. cc_library(
  62. name = "builtins_internal",
  63. hdrs_check = "strict",
  64. textual_hdrs = select({
  65. "@platforms//cpu:aarch64": builtins_aarch64_textual_srcs,
  66. "@platforms//cpu:i386": builtins_i386_textual_srcs,
  67. "@platforms//cpu:x86_64": builtins_x86_64_textual_srcs,
  68. "//conditions:default": [],
  69. }),
  70. )
  71. cc_library(
  72. name = "builtins",
  73. srcs = select({
  74. "@platforms//cpu:aarch64": builtins_aarch64_srcs,
  75. "@platforms//cpu:i386": builtins_i386_srcs,
  76. "@platforms//cpu:x86_64": builtins_x86_64_srcs,
  77. "//conditions:default": [],
  78. }),
  79. copts = builtins_copts + make_include_copts([
  80. "runtimes/builtins",
  81. ]),
  82. hdrs_check = "strict",
  83. target_compatible_with = select({
  84. ":is_runtimes_build": [],
  85. "//conditions:default": ["@platforms//:incompatible"],
  86. }),
  87. deps = [":builtins_internal"],
  88. )
  89. filegroup(
  90. name = "builtins_archive",
  91. srcs = [":builtins"],
  92. output_group = "archive",
  93. )
  94. cc_library(
  95. name = "libunwind",
  96. srcs = libunwind_srcs,
  97. hdrs = [":libunwind_hdrs"],
  98. copts = libunwind_copts + [
  99. # We disable all warnings as upstream isn't clean with the common
  100. # warning flags Carbon uses by default.
  101. "-w",
  102. ],
  103. hdrs_check = "strict",
  104. includes = ["runtimes/libunwind/include"],
  105. linkstatic = 1,
  106. target_compatible_with = select({
  107. ":is_runtimes_build": [],
  108. "//conditions:default": ["@platforms//:incompatible"],
  109. }),
  110. )
  111. filegroup(
  112. name = "libunwind_archive",
  113. srcs = [":libunwind"],
  114. output_group = "archive",
  115. )
  116. cc_library(
  117. name = "libcxxabi_internal",
  118. hdrs_check = "strict",
  119. target_compatible_with = select({
  120. ":is_runtimes_build": [],
  121. "//conditions:default": ["@platforms//:incompatible"],
  122. }),
  123. textual_hdrs = libcxxabi_textual_srcs,
  124. )
  125. cc_library(
  126. name = "libc_internal_libcxx",
  127. hdrs = libc_internal_libcxx_hdrs,
  128. hdrs_check = "strict",
  129. target_compatible_with = select({
  130. ":is_runtimes_build": [],
  131. "//conditions:default": ["@platforms//:incompatible"],
  132. }),
  133. )
  134. cc_library(
  135. name = "libcxx",
  136. srcs = select({
  137. "@platforms//os:macos": libcxx_macos_srcs,
  138. "@platforms//os:windows": libcxx_win32_srcs,
  139. "//conditions:default": libcxx_linux_srcs,
  140. }) + libcxxabi_srcs,
  141. hdrs = [":libcxx_hdrs"],
  142. copts = libcxx_copts + make_include_copts([
  143. "runtimes/libcxx/src",
  144. "runtimes/libc/internal",
  145. ]) + [
  146. # We disable all warnings as upstream isn't clean with the common
  147. # warning flags Carbon uses by default.
  148. "-w",
  149. ],
  150. hdrs_check = "strict",
  151. includes = [
  152. "runtimes/libcxx/include",
  153. "runtimes/libcxxabi/include",
  154. ],
  155. target_compatible_with = select({
  156. ":is_runtimes_build": [],
  157. "//conditions:default": ["@platforms//:incompatible"],
  158. }),
  159. deps = [
  160. ":libc_internal_libcxx",
  161. ":libcxxabi_internal",
  162. ],
  163. )
  164. filegroup(
  165. name = "libcxx_archive",
  166. srcs = [":libcxx"],
  167. output_group = "archive",
  168. )
  169. carbon_runtimes(
  170. name = "runtimes",
  171. builtins_archive = ":builtins_archive",
  172. clang_hdrs = [":clang_hdrs"],
  173. clang_hdrs_prefix = "llvm/lib/clang/{0}/include/".format(llvm_version_major),
  174. crt_copts = crt_copts,
  175. crtbegin_src = select({
  176. "@platforms//os:linux": crtbegin_src,
  177. "//conditions:default": None,
  178. }),
  179. crtend_src = select({
  180. "@platforms//os:linux": crtend_src,
  181. "//conditions:default": None,
  182. }),
  183. darwin_os_suffix = select({
  184. # TODO: Add support for tvOS, watchOS, and iOS variants with the
  185. # relevant Bazel constraints.
  186. ":is_macos_arm64": "osx",
  187. ":is_macos_x86_64": "osx",
  188. "//conditions:default": None,
  189. }),
  190. libcxx_archive = ":libcxx_archive",
  191. libunwind_archive = ":libunwind_archive",
  192. target_compatible_with = select({
  193. ":is_runtimes_build": [],
  194. "//conditions:default": ["@platforms//:incompatible"],
  195. }),
  196. target_triple = select({
  197. # TODO: Add other triples (and if needed, constraints) so that we can
  198. # build the correct Clang resource-dir structure for each.
  199. ":is_freebsd_x86_64": "x86_64-unknown-freebsd",
  200. ":is_linux_aarch64": "aarch64-unknown-linux-gnu",
  201. ":is_linux_x86_64": "x86_64-unknown-linux-gnu",
  202. # Note that Darwin OSes are handled by the `darwin_os_suffix` attribute.
  203. "//conditions:default": None,
  204. }),
  205. )
  206. filegroup(
  207. name = "carbon_install_digest_file",
  208. srcs = ["install_digest.txt"],
  209. )
  210. filegroup(
  211. name = "carbon_install_marker_file",
  212. srcs = ["carbon_install.txt"],
  213. )
  214. filegroup(
  215. name = "carbon_busybox_file",
  216. srcs = ["carbon-busybox"],
  217. )
  218. string_list_setting(
  219. name = "original_platforms",
  220. build_setting_default = [],
  221. )
  222. platforms = {
  223. "freebsd": ["x86_64"],
  224. "linux": [
  225. "aarch64",
  226. "x86_64",
  227. ],
  228. "macos": [
  229. "arm64",
  230. "x86_64",
  231. ],
  232. }
  233. [
  234. config_setting(
  235. name = "is_{0}_{1}".format(os, cpu),
  236. constraint_values = [
  237. "@platforms//os:" + os,
  238. "@platforms//cpu:" + cpu,
  239. ],
  240. )
  241. for os, cpus in platforms.items()
  242. for cpu in cpus
  243. ]
  244. carbon_cc_toolchain_suite(
  245. name = "carbon",
  246. all_hdrs = [
  247. ":clang_hdrs",
  248. ":libunwind_hdrs",
  249. ":libcxx_hdrs",
  250. ],
  251. base_files = [
  252. ":carbon_install_digest_file",
  253. ":carbon_install_marker_file",
  254. ":carbon_busybox_file",
  255. ":llvm_bins",
  256. ],
  257. clang_hdrs = [":clang_hdrs"],
  258. platforms = platforms,
  259. runtimes = ":runtimes",
  260. )