install.BUILD 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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", "bool_setting", "int_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_build", "carbon_runtimes_config")
  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. bool_setting(
  41. name = "runtimes_build",
  42. build_setting_default = False,
  43. )
  44. config_setting(
  45. name = "is_runtimes_build",
  46. flag_values = {":runtimes_build": "True"},
  47. )
  48. config_setting(
  49. name = "not_runtimes_build",
  50. flag_values = {":runtimes_build": "False"},
  51. )
  52. int_setting(
  53. name = "bootstrap_stage",
  54. build_setting_default = 1,
  55. )
  56. config_setting(
  57. name = "is_bootstrap_stage_1",
  58. flag_values = {":bootstrap_stage": "1"},
  59. )
  60. filegroup(
  61. name = "llvm_bins",
  62. srcs = glob(["llvm/bin/*"]),
  63. )
  64. filegroup(
  65. name = "clang_hdrs",
  66. srcs = glob(["llvm/lib/clang/{0}/include/*".format(llvm_version_major)]),
  67. )
  68. filegroup(
  69. name = "libcxx_hdrs",
  70. srcs = _libcxx_hdrs + libcxxabi_hdrs,
  71. )
  72. filegroup(
  73. name = "libunwind_hdrs",
  74. srcs = libunwind_hdrs,
  75. )
  76. cc_library(
  77. name = "builtins_internal",
  78. hdrs_check = "strict",
  79. textual_hdrs = select({
  80. "@platforms//cpu:aarch64": builtins_aarch64_textual_srcs,
  81. "@platforms//cpu:i386": builtins_i386_textual_srcs,
  82. "@platforms//cpu:x86_64": builtins_x86_64_textual_srcs,
  83. "//conditions:default": [],
  84. }),
  85. )
  86. cc_library(
  87. name = "builtins",
  88. srcs = select({
  89. "@platforms//cpu:aarch64": builtins_aarch64_srcs,
  90. "@platforms//cpu:i386": builtins_i386_srcs,
  91. "@platforms//cpu:x86_64": builtins_x86_64_srcs,
  92. "//conditions:default": [],
  93. }),
  94. copts = builtins_copts + make_include_copts([
  95. "runtimes/builtins",
  96. ]),
  97. hdrs_check = "strict",
  98. target_compatible_with = select({
  99. ":is_runtimes_build": [],
  100. "//conditions:default": ["@platforms//:incompatible"],
  101. }),
  102. deps = [":builtins_internal"],
  103. )
  104. filegroup(
  105. name = "builtins_archive",
  106. srcs = [":builtins"],
  107. output_group = "archive",
  108. )
  109. cc_library(
  110. name = "libunwind",
  111. srcs = libunwind_srcs,
  112. hdrs = [":libunwind_hdrs"],
  113. copts = libunwind_copts + [
  114. # We disable all warnings as upstream isn't clean with the common
  115. # warning flags Carbon uses by default.
  116. "-w",
  117. ],
  118. hdrs_check = "strict",
  119. includes = ["runtimes/libunwind/include"],
  120. linkstatic = 1,
  121. target_compatible_with = select({
  122. ":is_runtimes_build": [],
  123. "//conditions:default": ["@platforms//:incompatible"],
  124. }),
  125. )
  126. filegroup(
  127. name = "libunwind_archive",
  128. srcs = [":libunwind"],
  129. output_group = "archive",
  130. )
  131. cc_library(
  132. name = "libcxxabi_internal",
  133. hdrs_check = "strict",
  134. target_compatible_with = select({
  135. ":is_runtimes_build": [],
  136. "//conditions:default": ["@platforms//:incompatible"],
  137. }),
  138. textual_hdrs = libcxxabi_textual_srcs,
  139. )
  140. cc_library(
  141. name = "libc_internal_libcxx",
  142. hdrs = libc_internal_libcxx_hdrs,
  143. hdrs_check = "strict",
  144. target_compatible_with = select({
  145. ":is_runtimes_build": [],
  146. "//conditions:default": ["@platforms//:incompatible"],
  147. }),
  148. )
  149. cc_library(
  150. name = "libcxx",
  151. srcs = select({
  152. "@platforms//os:macos": libcxx_macos_srcs,
  153. "@platforms//os:windows": libcxx_win32_srcs,
  154. "//conditions:default": libcxx_linux_srcs,
  155. }) + libcxxabi_srcs,
  156. hdrs = [":libcxx_hdrs"],
  157. copts = libcxx_copts + make_include_copts([
  158. "runtimes/libcxx/src",
  159. "runtimes/libc/internal",
  160. ]) + [
  161. # We disable all warnings as upstream isn't clean with the common
  162. # warning flags Carbon uses by default.
  163. "-w",
  164. ],
  165. hdrs_check = "strict",
  166. includes = [
  167. "runtimes/libcxx/include",
  168. "runtimes/libcxxabi/include",
  169. ],
  170. target_compatible_with = select({
  171. ":is_runtimes_build": [],
  172. "//conditions:default": ["@platforms//:incompatible"],
  173. }),
  174. deps = [
  175. ":libc_internal_libcxx",
  176. ":libcxxabi_internal",
  177. ],
  178. )
  179. filegroup(
  180. name = "libcxx_archive",
  181. srcs = [":libcxx"],
  182. output_group = "archive",
  183. )
  184. carbon_runtimes_config(
  185. name = "runtimes_cfg",
  186. builtins_archive = ":builtins_archive",
  187. clang_hdrs_prefix = "llvm/lib/clang/{0}/include/".format(llvm_version_major),
  188. crt_copts = crt_copts,
  189. crtbegin_src = select({
  190. "@platforms//os:linux": crtbegin_src,
  191. "//conditions:default": None,
  192. }),
  193. crtend_src = select({
  194. "@platforms//os:linux": crtend_src,
  195. "//conditions:default": None,
  196. }),
  197. darwin_os_suffix = select({
  198. # TODO: Add support for tvOS, watchOS, and iOS variants with the
  199. # relevant Bazel constraints.
  200. ":is_macos_arm64": "osx",
  201. ":is_macos_x86_64": "osx",
  202. "//conditions:default": None,
  203. }),
  204. libcxx_archive = ":libcxx_archive",
  205. libunwind_archive = ":libunwind_archive",
  206. target_compatible_with = select({
  207. ":is_runtimes_build": [],
  208. "//conditions:default": ["@platforms//:incompatible"],
  209. }),
  210. target_triple = select({
  211. # TODO: Add other triples (and if needed, constraints) so that we can
  212. # build the correct Clang resource-dir structure for each.
  213. ":is_freebsd_x86_64": "x86_64-unknown-freebsd",
  214. ":is_linux_aarch64": "aarch64-unknown-linux-gnu",
  215. ":is_linux_x86_64": "x86_64-unknown-linux-gnu",
  216. # Note that Darwin OSes are handled by the `darwin_os_suffix` attribute.
  217. "//conditions:default": None,
  218. }),
  219. )
  220. carbon_runtimes_build(
  221. name = "runtimes",
  222. clang_hdrs = [":clang_hdrs"],
  223. config = ":runtimes_cfg",
  224. )
  225. filegroup(
  226. name = "carbon_install_digest_file",
  227. srcs = ["install_digest.txt"],
  228. )
  229. filegroup(
  230. name = "carbon_install_marker_file",
  231. srcs = ["carbon_install.txt"],
  232. )
  233. filegroup(
  234. name = "carbon_busybox_file",
  235. srcs = ["carbon-busybox"],
  236. )
  237. platforms = {
  238. "freebsd": ["x86_64"],
  239. "linux": [
  240. "aarch64",
  241. "x86_64",
  242. ],
  243. "macos": [
  244. "arm64",
  245. "x86_64",
  246. ],
  247. }
  248. [
  249. config_setting(
  250. name = "is_{0}_{1}".format(os, cpu),
  251. constraint_values = [
  252. "@platforms//os:{}".format(os),
  253. "@platforms//cpu:{}".format(cpu),
  254. ],
  255. )
  256. for os, cpus in platforms.items()
  257. for cpu in cpus
  258. ]
  259. carbon_cc_toolchain_suite(
  260. name = "carbon",
  261. all_hdrs = [
  262. ":clang_hdrs",
  263. ":libunwind_hdrs",
  264. ":libcxx_hdrs",
  265. ],
  266. base_files = [
  267. ":carbon_install_digest_file",
  268. ":carbon_install_marker_file",
  269. ":carbon_busybox_file",
  270. ":llvm_bins",
  271. ],
  272. clang_hdrs = [":clang_hdrs"],
  273. platforms = platforms,
  274. runtimes_cfg = ":runtimes_cfg",
  275. )