BUILD 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. srcs = ["busybox_info.cpp"],
  74. hdrs = ["busybox_info.h"],
  75. deps = [
  76. "//common:error",
  77. "//common:exe_path",
  78. "@llvm-project//llvm:Support",
  79. ],
  80. )
  81. cc_test(
  82. name = "busybox_info_test",
  83. size = "small",
  84. srcs = ["busybox_info_test.cpp"],
  85. deps = [
  86. ":busybox_info",
  87. "//common:check",
  88. "//testing/base:gtest_main",
  89. "@googletest//:gtest",
  90. "@llvm-project//llvm:Support",
  91. ],
  92. )
  93. # This target doesn't include prelude libraries. To get a target that has the
  94. # prelude available, use //toolchain.
  95. cc_binary(
  96. name = "carbon-busybox",
  97. srcs = ["busybox_main.cpp"],
  98. deps = [
  99. ":busybox_info",
  100. ":install_paths",
  101. "//common:all_llvm_targets",
  102. "//common:bazel_working_dir",
  103. "//common:error",
  104. "//common:exe_path",
  105. "//common:init_llvm",
  106. "//common:version_stamp",
  107. "//toolchain/base:llvm_tools_def",
  108. "//toolchain/driver",
  109. "@llvm-project//llvm:Support",
  110. ],
  111. )
  112. clang_aliases = [
  113. "clang",
  114. "clang++",
  115. "clang-cl",
  116. "clang-cpp",
  117. ]
  118. # TODO: Add remaining aliases of LLD for Windows and WASM when we have support
  119. # for them wired up through the busybox.
  120. lld_aliases = [
  121. "ld.lld",
  122. "ld64.lld",
  123. ]
  124. llvm_binaries = clang_aliases + lld_aliases + [
  125. tool.bin_name
  126. for tool in LLVM_MAIN_TOOLS.values()
  127. ] + [
  128. "llvm-" + alias
  129. for (_, aliases) in LLVM_TOOL_ALIASES.items()
  130. for alias in aliases
  131. ]
  132. filegroup(
  133. name = "clang_headers",
  134. srcs = ["@llvm-project//clang:builtin_headers_gen"],
  135. )
  136. # Given a root `prefix_root`, the hierarchy looks like:
  137. #
  138. # - prefix_root/bin: Binaries intended for direct use.
  139. # - prefix_root/lib/carbon: Private data and files.
  140. # - prefix_root/lib/carbon/core: The `Core` package files.
  141. # - prefix_root/lib/carbon/llvm/bin: LLVM binaries.
  142. #
  143. # This will be how installs are provided on Unix-y platforms, and is loosely
  144. # based on the FHS (Filesystem Hierarchy Standard).
  145. install_dirs = {
  146. "bin": [
  147. install_symlink(
  148. "carbon",
  149. "../lib/carbon/carbon-busybox",
  150. is_driver = True,
  151. ),
  152. ],
  153. "lib/carbon": [
  154. install_target("carbon_install.txt", "carbon_install.txt"),
  155. install_target(
  156. "carbon-busybox",
  157. ":carbon-busybox",
  158. executable = True,
  159. is_driver = True,
  160. ),
  161. install_filegroup("core", "//core:prelude"),
  162. ],
  163. "lib/carbon/llvm/bin": [install_symlink(
  164. name,
  165. "../../carbon-busybox",
  166. is_driver = True,
  167. ) for name in llvm_binaries],
  168. "lib/carbon/llvm/lib/clang/" + LLVM_VERSION_MAJOR: [
  169. install_filegroup("include", ":clang_headers", "staging/include/"),
  170. ],
  171. }
  172. make_install_filegroups(
  173. name = "install_data",
  174. install_dirs = install_dirs,
  175. no_driver_name = "install_data.no_driver",
  176. pkg_name = "pkg_data",
  177. prefix = "prefix_root",
  178. )
  179. py_test(
  180. name = "llvm_symlinks_test",
  181. size = "small",
  182. srcs = ["llvm_symlinks_test.py"],
  183. data = [":install_data"],
  184. )
  185. manifest(
  186. name = "install_data_manifest.txt",
  187. srcs = [":install_data"],
  188. )
  189. pkg_naming_variables(
  190. name = "packaging_variables",
  191. )
  192. # We build both a compressed and uncompressed tar file with the same code here.
  193. # This lets us use the tar file in testing as it is fast to create, but ship the
  194. # compressed version as a release.
  195. #
  196. # For manual tests, the tar rules are `carbon_toolchain_tar_rule` and
  197. # `carbon_toolchain_tar_gz_rule`.
  198. pkg_tar_and_test(
  199. srcs = [":pkg_data"],
  200. install_data_manifest = ":install_data_manifest.txt",
  201. name_base = "carbon_toolchain",
  202. package_dir = "carbon_toolchain-$(version)",
  203. package_file_name_base = "carbon_toolchain-$(version)",
  204. package_variables = ":packaging_variables",
  205. stamp = -1, # Allow `--stamp` builds to produce file timestamps.
  206. )