BUILD 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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("//toolchain/base:runtime_sources.bzl", "BUILTINS_FILEGROUPS", "CRT_FILES")
  13. load("install_filegroups.bzl", "install_filegroup", "install_symlink", "install_target", "make_install_filegroups")
  14. load("pkg_helpers.bzl", "pkg_naming_variables", "pkg_tar_and_test")
  15. package(default_visibility = ["//visibility:public"])
  16. # Build rules supporting the install data tree for the Carbon toolchain.
  17. #
  18. # This populates a synthetic Carbon toolchain installation under the
  19. # `prefix_root` directory. For details on its layout, see `install_dirs` below.
  20. # A library for computing install paths for the toolchain. Note that this
  21. # library does *not* include the data itself, as that would form a dependency
  22. # cycle. Each part of the toolchain should add the narrow data file groups to
  23. # their data dependencies, and then use this library to locate them.
  24. cc_library(
  25. name = "install_paths",
  26. srcs = ["install_paths.cpp"],
  27. hdrs = ["install_paths.h"],
  28. deps = [
  29. "//common:check",
  30. "//common:error",
  31. "//common:filesystem",
  32. "//toolchain/base:llvm_tools",
  33. "@bazel_tools//tools/cpp/runfiles",
  34. "@llvm-project//clang:basic",
  35. "@llvm-project//llvm:Support",
  36. ],
  37. )
  38. cc_binary(
  39. name = "test_binary",
  40. testonly = 1,
  41. srcs = ["test_binary.cpp"],
  42. data = [":install_data"],
  43. )
  44. cc_test(
  45. name = "install_paths_test",
  46. size = "small",
  47. srcs = ["install_paths_test.cpp"],
  48. data = [
  49. ":install_data",
  50. ":test_binary",
  51. ],
  52. deps = [
  53. ":install_paths",
  54. "//common:check",
  55. "//common:error_test_helpers",
  56. "//common:filesystem",
  57. "//common:ostream",
  58. "//testing/base:global_exe_path",
  59. "//testing/base:gtest_main",
  60. "@bazel_tools//tools/cpp/runfiles",
  61. "@googletest//:gtest",
  62. "@llvm-project//llvm:Support",
  63. ],
  64. )
  65. cc_library(
  66. name = "install_paths_test_helpers",
  67. testonly = 1,
  68. srcs = ["install_paths_test_helpers.cpp"],
  69. hdrs = ["install_paths_test_helpers.h"],
  70. deps = [
  71. ":install_paths",
  72. "//testing/base:global_exe_path",
  73. "@llvm-project//llvm:Support",
  74. ],
  75. )
  76. cc_library(
  77. name = "busybox_info",
  78. srcs = ["busybox_info.cpp"],
  79. hdrs = ["busybox_info.h"],
  80. deps = [
  81. "//common:error",
  82. "//common:exe_path",
  83. "//common:filesystem",
  84. "@llvm-project//llvm:Support",
  85. ],
  86. )
  87. cc_test(
  88. name = "busybox_info_test",
  89. size = "small",
  90. srcs = ["busybox_info_test.cpp"],
  91. deps = [
  92. ":busybox_info",
  93. "//common:check",
  94. "//common:filesystem",
  95. "//testing/base:gtest_main",
  96. "@googletest//:gtest",
  97. "@llvm-project//llvm:Support",
  98. ],
  99. )
  100. # This target doesn't include prelude libraries. To get a target that has the
  101. # prelude available, use //toolchain.
  102. cc_binary(
  103. name = "carbon-busybox",
  104. srcs = ["busybox_main.cpp"],
  105. deps = [
  106. ":busybox_info",
  107. ":install_paths",
  108. "//common:all_llvm_targets",
  109. "//common:bazel_working_dir",
  110. "//common:error",
  111. "//common:exe_path",
  112. "//common:init_llvm",
  113. "//common:version_stamp",
  114. "//toolchain/base:llvm_tools_def",
  115. "//toolchain/driver",
  116. "@llvm-project//llvm:Support",
  117. ],
  118. )
  119. clang_aliases = [
  120. "clang",
  121. "clang++",
  122. "clang-cl",
  123. "clang-cpp",
  124. ]
  125. # TODO: Add remaining aliases of LLD for Windows and WASM when we have support
  126. # for them wired up through the busybox.
  127. lld_aliases = [
  128. "ld.lld",
  129. "ld64.lld",
  130. ]
  131. llvm_binaries = clang_aliases + lld_aliases + [
  132. tool.bin_name
  133. for tool in LLVM_MAIN_TOOLS.values()
  134. ] + [
  135. "llvm-" + alias
  136. for (_, aliases) in LLVM_TOOL_ALIASES.items()
  137. for alias in aliases
  138. ]
  139. filegroup(
  140. name = "clang_headers",
  141. srcs = ["@llvm-project//clang:builtin_headers_gen"],
  142. )
  143. # Collect the runtime sources that are collectively installed into the
  144. # `builtins` directory.
  145. filegroup(
  146. name = "clang_builtins_runtimes",
  147. srcs = CRT_FILES.values() + BUILTINS_FILEGROUPS.values(),
  148. )
  149. # Given a root `prefix_root`, the hierarchy looks like:
  150. #
  151. # - prefix_root/bin: Binaries intended for direct use.
  152. # - prefix_root/lib/carbon: Private data and files.
  153. # - prefix_root/lib/carbon/core: The `Core` package files.
  154. # - prefix_root/lib/carbon/llvm/bin: LLVM binaries.
  155. #
  156. # This will be how installs are provided on Unix-y platforms, and is loosely
  157. # based on the FHS (Filesystem Hierarchy Standard).
  158. install_dirs = {
  159. "bin": [
  160. install_symlink(
  161. "carbon",
  162. "../lib/carbon/carbon-busybox",
  163. is_driver = True,
  164. ),
  165. ],
  166. "lib/carbon": [
  167. install_target("carbon_install.txt", "carbon_install.txt"),
  168. install_target(
  169. "carbon-busybox",
  170. ":carbon-busybox",
  171. executable = True,
  172. is_driver = True,
  173. ),
  174. install_filegroup("core", "//core:prelude"),
  175. ],
  176. "lib/carbon/llvm/bin": [install_symlink(
  177. name,
  178. "../../carbon-busybox",
  179. is_driver = True,
  180. ) for name in llvm_binaries],
  181. "lib/carbon/llvm/lib/clang/" + LLVM_VERSION_MAJOR: [
  182. install_filegroup(
  183. "include",
  184. ":clang_headers",
  185. label = "installed_clang_headers",
  186. remove_prefix = "staging/include/",
  187. ),
  188. ],
  189. "lib/carbon/llvm/lib/clang/" + LLVM_VERSION_MAJOR + "/src": [
  190. install_filegroup("builtins", ":clang_builtins_runtimes", "lib/builtins/"),
  191. ],
  192. }
  193. make_install_filegroups(
  194. name = "install_data",
  195. install_dirs = install_dirs,
  196. no_driver_name = "install_data.no_driver",
  197. pkg_name = "pkg_data",
  198. prefix = "prefix_root",
  199. )
  200. py_test(
  201. name = "llvm_symlinks_test",
  202. size = "small",
  203. srcs = ["llvm_symlinks_test.py"],
  204. data = [":install_data"],
  205. )
  206. manifest(
  207. name = "install_data_manifest.txt",
  208. srcs = [":install_data"],
  209. )
  210. # A list of clang's installed builtin header files.
  211. # This is consumed by //toolchain/testing:file_test.
  212. manifest(
  213. name = "clang_headers_manifest.txt",
  214. srcs = [":installed_clang_headers"],
  215. strip_package_dir = True,
  216. )
  217. pkg_naming_variables(
  218. name = "packaging_variables",
  219. )
  220. # We build both a compressed and uncompressed tar file with the same code here.
  221. # This lets us use the tar file in testing as it is fast to create, but ship the
  222. # compressed version as a release.
  223. #
  224. # For manual tests, the tar rules are `carbon_toolchain_tar_rule` and
  225. # `carbon_toolchain_tar_gz_rule`.
  226. pkg_tar_and_test(
  227. srcs = [":pkg_data"],
  228. install_data_manifest = ":install_data_manifest.txt",
  229. name_base = "carbon_toolchain",
  230. package_dir = "carbon_toolchain-$(version)",
  231. package_file_name_base = "carbon_toolchain-$(version)",
  232. package_variables = ":packaging_variables",
  233. stamp = -1, # Allow `--stamp` builds to produce file timestamps.
  234. )