install.BUILD 7.9 KB

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