BUILD 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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(
  5. "@llvm-project//:vars.bzl",
  6. "LLVM_VERSION_MAJOR",
  7. )
  8. load("@rules_python//python:defs.bzl", "py_test")
  9. load("//bazel/cc_rules:defs.bzl", "cc_binary", "cc_library", "cc_test")
  10. load("//bazel/manifest:defs.bzl", "manifest")
  11. load("//toolchain/base:llvm_tools.bzl", "LLVM_MAIN_TOOLS", "LLVM_TOOL_ALIASES")
  12. load(
  13. "//toolchain/base:runtimes_build_info.bzl",
  14. "generate_runtimes_build_vars",
  15. )
  16. load("install_filegroups.bzl", "install_filegroup", "install_symlink", "install_target", "make_install_filegroups")
  17. load("pkg_helpers.bzl", "pkg_naming_variables", "pkg_tar_and_test")
  18. package(default_visibility = ["//visibility:public"])
  19. # Build rules supporting the install data tree for the Carbon toolchain.
  20. #
  21. # This populates a synthetic Carbon toolchain installation under the
  22. # `prefix` directory. For details on its layout, see `install_dirs` below.
  23. cc_library(
  24. name = "busybox_info",
  25. srcs = ["busybox_info.cpp"],
  26. hdrs = ["busybox_info.h"],
  27. deps = [
  28. "//common:error",
  29. "//common:exe_path",
  30. "//common:filesystem",
  31. "@llvm-project//llvm:Support",
  32. ],
  33. )
  34. cc_test(
  35. name = "busybox_info_test",
  36. size = "small",
  37. srcs = ["busybox_info_test.cpp"],
  38. deps = [
  39. ":busybox_info",
  40. "//common:check",
  41. "//common:filesystem",
  42. "//testing/base:gtest_main",
  43. "@googletest//:gtest",
  44. "@llvm-project//llvm:Support",
  45. ],
  46. )
  47. # This target doesn't include prelude libraries. To get a target that has the
  48. # prelude available, use //toolchain.
  49. cc_binary(
  50. name = "carbon-busybox",
  51. srcs = ["busybox_main.cpp"],
  52. deps = [
  53. ":busybox_info",
  54. "//common:all_llvm_targets",
  55. "//common:bazel_working_dir",
  56. "//common:error",
  57. "//common:exe_path",
  58. "//common:init_llvm",
  59. "//common:version_stamp",
  60. "//toolchain/base:install_paths",
  61. "//toolchain/base:llvm_tools_def",
  62. "//toolchain/driver",
  63. "@llvm-project//clang:driver",
  64. "@llvm-project//llvm:Support",
  65. ],
  66. )
  67. clang_aliases = [
  68. "clang",
  69. "clang++",
  70. "clang-cl",
  71. "clang-cpp",
  72. ]
  73. # TODO: Add remaining aliases of LLD for Windows and WASM when we have support
  74. # for them wired up through the busybox.
  75. lld_aliases = [
  76. "ld.lld",
  77. "ld64.lld",
  78. ]
  79. llvm_binaries = clang_aliases + lld_aliases + [
  80. tool.bin_name
  81. for tool in LLVM_MAIN_TOOLS.values()
  82. ] + [
  83. "llvm-" + alias
  84. for (_, aliases) in LLVM_TOOL_ALIASES.items()
  85. for alias in aliases
  86. ]
  87. # Generate a Starlark file with all the build variables needed for our runtimes.
  88. generate_runtimes_build_vars(
  89. name = "staging_bazel/runtimes_build_vars.bzl",
  90. )
  91. # Given a CMake-style install prefix[1], the hierarchy looks like:
  92. #
  93. # - prefix/bin: Binaries intended for direct use.
  94. # - prefix/lib/carbon: Private data and files.
  95. # - prefix/lib/carbon/core: The `Core` package files.
  96. # - prefix/lib/carbon/llvm/bin: LLVM binaries.
  97. #
  98. # This will be how installs are provided on Unix-y platforms, and is loosely
  99. # based on the FHS (Filesystem Hierarchy Standard). See the CMake install prefix
  100. # documentation[1] for more details.
  101. #
  102. # [1]: https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html
  103. install_dirs = {
  104. "bin": [
  105. install_symlink(
  106. "carbon",
  107. "../lib/carbon/carbon-busybox",
  108. is_driver = True,
  109. ),
  110. ],
  111. "lib/carbon": [
  112. install_target("MODULE.bazel", "bazel/install.MODULE.bazel"),
  113. install_target("BUILD", "bazel/install.BUILD"),
  114. install_target("carbon_install.txt", "carbon_install.txt"),
  115. install_target(
  116. "install_digest.txt",
  117. ":install_digest.txt",
  118. executable = False,
  119. is_digest = True,
  120. is_driver = True,
  121. ),
  122. install_target(
  123. "carbon-busybox",
  124. ":carbon-busybox",
  125. executable = True,
  126. is_driver = True,
  127. ),
  128. install_filegroup("bazel", "//bazel/cc_toolchains:installed_cc_toolchain_starlark"),
  129. # TODO: Consider if we want to keep `core` here or group it with
  130. # runtimes. It is a bit of both -- standard library, and runtimes.
  131. install_filegroup("core", "//core:prelude"),
  132. ],
  133. "lib/carbon/bazel": [
  134. install_target("carbon_cc_toolchain_config.bzl", "bazel/carbon_cc_toolchain_config.bzl"),
  135. install_target("carbon_detected_variables.tpl.bzl", "bazel/carbon_detected_variables.tpl.bzl"),
  136. install_target("carbon_runtimes.bzl", "bazel/carbon_runtimes.bzl"),
  137. install_target("carbon_toolchain.bzl", "bazel/carbon_toolchain.bzl"),
  138. install_target("make_include_copts.bzl", "bazel/make_include_copts.bzl"),
  139. install_target("runtimes_build_vars.bzl", "staging_bazel/runtimes_build_vars.bzl"),
  140. install_target("BUILD", "bazel/empty.BUILD"),
  141. ],
  142. "lib/carbon/llvm/bin": [install_symlink(
  143. name,
  144. "../../carbon-busybox",
  145. is_driver = True,
  146. ) for name in llvm_binaries],
  147. "lib/carbon/runtimes": [
  148. install_filegroup(
  149. "builtins",
  150. "//toolchain/runtimes:clang_builtins_runtimes",
  151. remove_prefix = "lib/builtins/",
  152. ),
  153. install_filegroup("libcxx", "//toolchain/runtimes:libcxx"),
  154. install_filegroup("libcxxabi", "//toolchain/runtimes:libcxxabi"),
  155. install_filegroup("libunwind", "//toolchain/runtimes:libunwind"),
  156. install_target("BUILD", "bazel/runtimes.BUILD"),
  157. ],
  158. "lib/carbon/runtimes/libc": [
  159. install_filegroup("internal", "//toolchain/runtimes:libc_internal"),
  160. ],
  161. "lib/carbon/runtimes/libcxx": [
  162. install_filegroup(
  163. "include",
  164. "//toolchain/runtimes:libcxx_gen_files",
  165. remove_prefix = "staging_libcxx/include/",
  166. ),
  167. ],
  168. "lib/carbon/llvm/lib/clang/" + LLVM_VERSION_MAJOR: [
  169. install_target("BUILD", "bazel/clang_resource_dir.BUILD"),
  170. install_filegroup(
  171. "include",
  172. "@llvm-project//clang:builtin_headers_gen",
  173. label = "installed_clang_headers",
  174. remove_prefix = "staging/include/",
  175. ),
  176. ],
  177. "lib/carbon/llvm/lib/clang/" + LLVM_VERSION_MAJOR + "/include": [
  178. install_filegroup(
  179. "fuzzer",
  180. "@llvm-project//compiler-rt:fuzzer_installed_hdrs",
  181. remove_prefix = "include/fuzzer/",
  182. ),
  183. install_filegroup(
  184. "profile",
  185. "@llvm-project//compiler-rt:profile_installed_hdrs",
  186. remove_prefix = "include/profile/",
  187. ),
  188. install_filegroup(
  189. "sanitizer",
  190. "@llvm-project//compiler-rt:sanitizer_installed_hdrs",
  191. remove_prefix = "include/sanitizer/",
  192. ),
  193. ],
  194. }
  195. make_install_filegroups(
  196. name = "install_data",
  197. install_dirs = install_dirs,
  198. no_digest_name = "install_data.no_digest",
  199. no_driver_name = "install_data.no_driver",
  200. pkg_name = "pkg_data",
  201. prefix = "prefix",
  202. )
  203. py_test(
  204. name = "llvm_symlinks_test",
  205. size = "small",
  206. srcs = ["llvm_symlinks_test.py"],
  207. data = [
  208. ":install_data",
  209. "//toolchain/driver:prebuilt_runtimes",
  210. ],
  211. deps = ["@bazel_tools//tools/python/runfiles"],
  212. )
  213. manifest(
  214. name = "install_data_manifest.txt",
  215. srcs = [":install_data"],
  216. )
  217. cc_binary(
  218. name = "make-installation-digest",
  219. srcs = ["make_installation_digest.cpp"],
  220. deps = [
  221. "//common:bazel_working_dir",
  222. "//common:error",
  223. "//common:exe_path",
  224. "//common:filesystem",
  225. "//common:init_llvm",
  226. "//common:map",
  227. "//common:vlog",
  228. "@llvm-project//llvm:Support",
  229. ],
  230. )
  231. manifest(
  232. name = "install_digest_manifest.txt",
  233. srcs = [":install_data.no_digest"],
  234. )
  235. genrule(
  236. name = "gen_digest",
  237. srcs = [
  238. ":install_data.no_digest",
  239. "install_digest_manifest.txt",
  240. ],
  241. outs = [":install_digest.txt"],
  242. cmd = "$(location :make-installation-digest) " +
  243. "$(location install_digest_manifest.txt) $@",
  244. tools = [":make-installation-digest"],
  245. )
  246. # A list of clang's installed builtin header files.
  247. # This is consumed by //toolchain/testing:file_test.
  248. manifest(
  249. name = "clang_headers_manifest.txt",
  250. srcs = [":installed_clang_headers"],
  251. strip_package_dir = True,
  252. )
  253. pkg_naming_variables(
  254. name = "packaging_variables",
  255. )
  256. # We build both a compressed and uncompressed tar file with the same code here.
  257. # This lets us use the tar file in testing as it is fast to create, but ship the
  258. # compressed version as a release.
  259. #
  260. # For manual tests, the tar rules are `carbon_toolchain_tar_rule` and
  261. # `carbon_toolchain_tar_gz_rule`.
  262. pkg_tar_and_test(
  263. srcs = [":pkg_data"],
  264. install_data_manifest = ":install_data_manifest.txt",
  265. name_base = "carbon_toolchain",
  266. package_dir = "carbon_toolchain-$(version)",
  267. package_file_name_base = "carbon_toolchain-$(version)",
  268. package_variables = ":packaging_variables",
  269. stamp = -1, # Allow `--stamp` builds to produce file timestamps.
  270. )