BUILD 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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_python//python:defs.bzl", "py_binary")
  5. load(
  6. "//toolchain/base:runtimes_build_info.bzl",
  7. "BUILTINS_SRCS_FILEGROUPS",
  8. "BUILTINS_TEXTUAL_SRCS_FILEGROUPS",
  9. "CRT_FILES",
  10. )
  11. load("configure_cmake_file.bzl", "configure_cmake_file")
  12. package(default_visibility = ["//visibility:public"])
  13. exports_files(["carbon_runtimes.bzl"])
  14. # Collect the runtime sources that are collectively installed into the
  15. # `builtins` directory.
  16. filegroup(
  17. name = "clang_builtins_runtimes",
  18. srcs = (
  19. CRT_FILES.values() +
  20. BUILTINS_SRCS_FILEGROUPS +
  21. BUILTINS_TEXTUAL_SRCS_FILEGROUPS
  22. ),
  23. )
  24. py_binary(
  25. name = "configure_cmake_file_impl",
  26. srcs = ["configure_cmake_file_impl.py"],
  27. )
  28. configure_cmake_file(
  29. name = "libcxx_site_config_gen",
  30. src = "@llvm-project//libcxx:include/__config_site.in",
  31. out = "staging_libcxx/include/__config_site",
  32. defines = {
  33. # We can inject custom logic at the end of the site configuration with
  34. # the ABI defines. This can custom set (or re-set) any of the relevant
  35. # configuration defines. Note that while this is sorted here in the
  36. # BUILD file, it is expanded at the _end_ of the configuration header
  37. # and so overrides the other configuration settings.
  38. #
  39. # TODO: This is a lot of C++ code to embed into a BUILD file. Even
  40. # though it moves it farther from the interacting CMake defines, we
  41. # should look at factoring this into a header that is included.
  42. "_LIBCPP_ABI_DEFINES": "\n".join([
  43. # We want to install a single header that works in all build modes,
  44. # so we define the ABI namespace based on how the header is used
  45. # rather than a fixed one. However, we only support use with Clang
  46. # and so we assume `__has_feature` is available and works.
  47. #
  48. # Note that generally, we don't rely on different ABI namespaces for
  49. # functionality -- the distinction is more to make errors when
  50. # linking with the wrong build of the standard library obvious and
  51. # immediate. We only can achieve this for sanitizers that have a
  52. # preprocessor detectable model.
  53. "#if __has_feature(address_sanitizer)",
  54. "# undef _LIBCPP_ABI_NAMESPACE",
  55. "# define _LIBCPP_ABI_NAMESPACE __asan",
  56. # Also mark that libc++ will be instrumented.
  57. "# undef _LIBCPP_INSTRUMENTED_WITH_ASAN",
  58. "# define _LIBCPP_INSTRUMENTED_WITH_ASAN 1",
  59. "#elif __has_feature(memory_sanitizer)",
  60. # TODO: If a track-origins macro becomes available, we should
  61. # distinguish that case, too.
  62. "# undef _LIBCPP_ABI_NAMESPACE",
  63. "# define _LIBCPP_ABI_NAMESPACE __msan",
  64. "#elif __has_feature(thread_sanitizer)",
  65. "# undef _LIBCPP_ABI_NAMESPACE",
  66. "# define _LIBCPP_ABI_NAMESPACE __tsan",
  67. "#elif __has_feature(cfi_sanitizer)",
  68. "# undef _LIBCPP_ABI_NAMESPACE",
  69. "# define _LIBCPP_ABI_NAMESPACE __cfi",
  70. "#endif",
  71. "",
  72. # Establish a default hardening mode where possible.
  73. "#ifndef _LIBCPP_HARDENING_MODE",
  74. "# ifndef NDEBUG",
  75. # !NDEBUG has significant overhead anyway and is explicitly a
  76. # debugging build rather than a production build.
  77. "# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEBUG",
  78. "# else",
  79. # Default to the fast hardening checks.
  80. "# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_FAST",
  81. "# endif",
  82. "#endif",
  83. "",
  84. # CUDA can't call any existing abort implementations, so disable
  85. # hardening there.
  86. "#ifdef __CUDA__",
  87. "# undef _LIBCPP_HARDENING_MODE",
  88. "# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_NONE",
  89. "#endif",
  90. "",
  91. # Setup platform-dependent features using preprocessor logic.
  92. "#ifdef __linux__",
  93. "# undef _LIBCPP_HAS_TIME_ZONE_DATABASE",
  94. "# define _LIBCPP_HAS_TIME_ZONE_DATABASE 1",
  95. "#endif",
  96. "",
  97. # Mixing translation units compiled with different versions of
  98. # libc++ is unsupported. Disable ABI tags to decrease symbol
  99. # lengths.
  100. "#define _LIBCPP_NO_ABI_TAG",
  101. ]),
  102. # No forced ABI.
  103. "_LIBCPP_ABI_FORCE_ITANIUM": "OFF",
  104. "_LIBCPP_ABI_FORCE_MICROSOFT": "OFF",
  105. # We use the unstable ABI and define a custom, Carbon-specific ABI
  106. # namespace. This also matches the mangling prefix used for Carbon
  107. # symbols.
  108. "_LIBCPP_ABI_NAMESPACE": "_C",
  109. # TODO: Fix the need to define _LIBCPP_ABI_VERSION when the unstable
  110. # ABI is selected.
  111. "_LIBCPP_ABI_VERSION": "999",
  112. # Follow hardening mode for the assertion semantics.
  113. "_LIBCPP_ASSERTION_SEMANTIC_DEFAULT": "_LIBCPP_ASSERTION_SEMANTIC_HARDENING_DEPENDENT",
  114. # Enable various features in libc++ available across platforms. We
  115. # describe these in a block to allow the BUILD file to sort them.
  116. #
  117. # - We enable threads, and use auto-detection rather than forcing an
  118. # API.
  119. # - Availability annotations do not apply to Carbon's libc++, so those
  120. # are disabled.
  121. #
  122. # Where there are platform differences in the features, we disable them
  123. # here and re-enable them in the `_LIBCPP_ABI_DEFINES` section using
  124. # custom logic to detect the relevant platform.
  125. "_LIBCPP_HAS_FILESYSTEM": "ON",
  126. "_LIBCPP_HAS_LOCALIZATION": "ON",
  127. "_LIBCPP_HAS_MONOTONIC_CLOCK": "ON",
  128. "_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS": "ON",
  129. "_LIBCPP_HAS_RANDOM_DEVICE": "ON",
  130. "_LIBCPP_HAS_TERMINAL": "ON",
  131. "_LIBCPP_HAS_THREADS": "ON",
  132. "_LIBCPP_HAS_THREAD_API_EXTERNAL": "OFF",
  133. "_LIBCPP_HAS_THREAD_API_PTHREAD": "OFF",
  134. "_LIBCPP_HAS_THREAD_API_WIN32": "OFF",
  135. "_LIBCPP_HAS_TIME_ZONE_DATABASE": "OFF",
  136. "_LIBCPP_HAS_UNICODE": "ON",
  137. "_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS": "OFF",
  138. "_LIBCPP_HAS_WIDE_CHARACTERS": "ON",
  139. # When ASan is enabled, we ensure that libc++ is built with it as well.
  140. # However, we can't set this more carefully here so we set it to off and
  141. # override it below when using ASan.
  142. "_LIBCPP_INSTRUMENTED_WITH_ASAN": "OFF",
  143. # Set the parallel backend to serial.
  144. # TODO: We should revisit this.
  145. "_LIBCPP_PSTL_BACKEND_SERIAL": "1",
  146. },
  147. )
  148. configure_cmake_file(
  149. name = "libcxx_assertion_handler_gen",
  150. src = "@llvm-project//libcxx:vendor/llvm/default_assertion_handler.in",
  151. out = "staging_libcxx/include/__assertion_handler",
  152. defines = {
  153. # Currently the default handler needs no substitutions.
  154. },
  155. )
  156. filegroup(
  157. name = "libcxx",
  158. srcs = [
  159. "@llvm-project//libcxx:libcxx_all_srcs",
  160. "@llvm-project//libcxx:libcxx_hdrs",
  161. ],
  162. )
  163. filegroup(
  164. name = "libcxx_gen_files",
  165. srcs = [
  166. "staging_libcxx/include/__assertion_handler",
  167. "staging_libcxx/include/__config_site",
  168. ],
  169. )
  170. filegroup(
  171. name = "libcxxabi",
  172. srcs = [
  173. "@llvm-project//libcxxabi:libcxxabi_hdrs",
  174. "@llvm-project//libcxxabi:libcxxabi_srcs",
  175. "@llvm-project//libcxxabi:libcxxabi_textual_srcs",
  176. ],
  177. )
  178. filegroup(
  179. name = "libunwind",
  180. srcs = [
  181. "@llvm-project//libunwind:libunwind_hdrs",
  182. "@llvm-project//libunwind:libunwind_srcs",
  183. ],
  184. )
  185. # Currently, we're only installing the subset of LLVM's libc internals needed to
  186. # build libc++. At some point, we should ship LLVM's libc itself, and that will
  187. # likely expand this to cover more of the source. However, we'll still want to
  188. # distinguish between the _internal_ installation and the generated set of
  189. # headers that we inject into the include search for user compiles. The
  190. # `include` subdirectory in this file group is _not_ intended to be exposed to
  191. # user compiles, only to compilation of runtimes.
  192. filegroup(
  193. name = "libc_internal",
  194. srcs = [
  195. "@llvm-project//libc:libcxx_shared_headers_hdrs",
  196. ],
  197. )