runtimes.BUILD 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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("@rules_cc//cc:defs.bzl", "cc_library")
  5. load("//bazel:carbon_runtimes.bzl", "carbon_runtimes")
  6. load("//bazel:make_include_copts.bzl", "make_include_copts")
  7. load(
  8. "//bazel:runtimes_build_vars.bzl",
  9. "builtins_aarch64_srcs",
  10. "builtins_aarch64_textual_srcs",
  11. "builtins_copts",
  12. "builtins_i386_srcs",
  13. "builtins_i386_textual_srcs",
  14. "builtins_x86_64_srcs",
  15. "builtins_x86_64_textual_srcs",
  16. "crt_copts",
  17. "crtbegin_src",
  18. "crtend_src",
  19. "libc_internal_libcxx_hdrs",
  20. "libcxx_copts",
  21. "libcxx_hdrs",
  22. "libcxx_linux_srcs",
  23. "libcxx_macos_srcs",
  24. "libcxx_win32_srcs",
  25. "libcxxabi_hdrs",
  26. "libcxxabi_srcs",
  27. "libcxxabi_textual_srcs",
  28. "libunwind_copts",
  29. "libunwind_hdrs",
  30. "libunwind_srcs",
  31. "llvm_version_major",
  32. )
  33. package(default_visibility = ["//visibility:public"])
  34. # Clang looks in a target-triple subdirectory of its resource directory for the
  35. # builtins and CRT files. Triples capture a large range of settings and aren't
  36. # even consistent structurally between platforms, so we expect to have roughly
  37. # one setting per supported target triple. By convention, we name them after the
  38. # target triple.
  39. #
  40. # TODO: Add constraints and other settings so we can select the correct target
  41. # triple for different `libc`s.
  42. #
  43. # TODO: Add other OS and CPU triples.
  44. config_setting(
  45. name = "x86_64-unknown-linux-gnu",
  46. constraint_values = [
  47. "@platforms//os:linux",
  48. "@platforms//cpu:x86_64",
  49. ],
  50. )
  51. config_setting(
  52. name = "aarch64-unknown-linux-gnu",
  53. constraint_values = [
  54. "@platforms//os:linux",
  55. "@platforms//cpu:aarch64",
  56. ],
  57. )
  58. cc_library(
  59. name = "builtins_internal",
  60. hdrs_check = "strict",
  61. textual_hdrs = select({
  62. "@platforms//cpu:aarch64": builtins_aarch64_textual_srcs,
  63. "@platforms//cpu:i386": builtins_i386_textual_srcs,
  64. "@platforms//cpu:x86_64": builtins_x86_64_textual_srcs,
  65. "//conditions:default": [],
  66. }),
  67. )
  68. cc_library(
  69. name = "builtins",
  70. srcs = select({
  71. "@platforms//cpu:aarch64": builtins_aarch64_srcs,
  72. "@platforms//cpu:i386": builtins_i386_srcs,
  73. "@platforms//cpu:x86_64": builtins_x86_64_srcs,
  74. "//conditions:default": [],
  75. }),
  76. copts = builtins_copts + make_include_copts([
  77. "builtins",
  78. ]),
  79. hdrs_check = "strict",
  80. deps = [":builtins_internal"],
  81. )
  82. filegroup(
  83. name = "builtins_archive",
  84. srcs = [":builtins"],
  85. output_group = "archive",
  86. )
  87. filegroup(
  88. name = "libunwind_hdrs",
  89. srcs = libunwind_hdrs,
  90. )
  91. cc_library(
  92. name = "libunwind",
  93. srcs = libunwind_srcs,
  94. hdrs = [":libunwind_hdrs"],
  95. copts = libunwind_copts + [
  96. # We disable all warnings as upstream isn't clean with the common
  97. # warning flags Carbon uses by default.
  98. "-w",
  99. ],
  100. hdrs_check = "strict",
  101. includes = ["libunwind/include"],
  102. linkstatic = 1,
  103. )
  104. filegroup(
  105. name = "libunwind_archive",
  106. srcs = [":libunwind"],
  107. output_group = "archive",
  108. )
  109. cc_library(
  110. name = "libcxxabi_internal",
  111. hdrs_check = "strict",
  112. textual_hdrs = libcxxabi_textual_srcs,
  113. )
  114. cc_library(
  115. name = "libc_internal_libcxx",
  116. hdrs = libc_internal_libcxx_hdrs,
  117. hdrs_check = "strict",
  118. )
  119. filegroup(
  120. name = "libcxx_hdrs",
  121. srcs = [
  122. "libcxx/include/__assertion_handler",
  123. "libcxx/include/__config_site",
  124. ] + libcxx_hdrs + libcxxabi_hdrs,
  125. )
  126. cc_library(
  127. name = "libcxx",
  128. srcs = select({
  129. "@platforms//os:macos": libcxx_macos_srcs,
  130. "@platforms//os:windows": libcxx_win32_srcs,
  131. "//conditions:default": libcxx_linux_srcs,
  132. }) + libcxxabi_srcs,
  133. hdrs = [":libcxx_hdrs"],
  134. copts = libcxx_copts + make_include_copts([
  135. "libcxx/src",
  136. "libc/internal",
  137. ]) + [
  138. # We disable all warnings as upstream isn't clean with the common
  139. # warning flags Carbon uses by default.
  140. "-w",
  141. ],
  142. hdrs_check = "strict",
  143. includes = [
  144. "libcxx/include",
  145. "libcxxabi/include",
  146. ],
  147. linkstatic = 1,
  148. deps = [
  149. ":libc_internal_libcxx",
  150. ":libcxxabi_internal",
  151. ],
  152. )
  153. filegroup(
  154. name = "libcxx_archive",
  155. srcs = [":libcxx"],
  156. output_group = "archive",
  157. )
  158. carbon_runtimes(
  159. name = "carbon_runtimes",
  160. builtins_archive = ":builtins_archive",
  161. clang_hdrs = [
  162. "//llvm/lib/clang/{0}:clang_hdrs".format(llvm_version_major),
  163. ],
  164. crt_copts = crt_copts,
  165. crtbegin_src = select({
  166. "@platforms//os:linux": crtbegin_src,
  167. "//conditions:default": None,
  168. }),
  169. crtend_src = select({
  170. "@platforms//os:linux": crtend_src,
  171. "//conditions:default": None,
  172. }),
  173. libcxx_archive = ":libcxx_archive",
  174. libunwind_archive = ":libunwind_archive",
  175. target_triple = select({
  176. ":aarch64-unknown-linux-gnu": "aarch64-unknown-linux-gnu",
  177. ":x86_64-unknown-linux-gnu": "x86_64-unknown-linux-gnu",
  178. "//conditions:default": "",
  179. }),
  180. )