BUILD 6.2 KB

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