BUILD 5.7 KB

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