install.BUILD 8.2 KB

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