BUILD 5.4 KB

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