BUILD 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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_busybox_wrapper", "install_filegroup", "install_symlink", "install_target", "make_install_filegroups")
  8. load("pkg_helpers.bzl", "pkg_naming_variables", "pkg_tar_and_test")
  9. load("run_tool.bzl", "run_tool")
  10. package(default_visibility = ["//visibility:public"])
  11. # Build rules supporting the install data tree for the Carbon toolchain.
  12. #
  13. # This populates a synthetic Carbon toolchain installation under the
  14. # `prefix_root` directory. For details on its layout, see `install_dirs` below.
  15. # A library for computing install paths for the toolchain. Note that this
  16. # library does *not* include the data itself, as that would form a dependency
  17. # cycle. Each part of the toolchain should add the narrow data file groups to
  18. # their data dependencies, and then use this library to locate them.
  19. cc_library(
  20. name = "install_paths",
  21. srcs = ["install_paths.cpp"],
  22. hdrs = ["install_paths.h"],
  23. deps = [
  24. "//common:check",
  25. "//common:error",
  26. "@bazel_tools//tools/cpp/runfiles",
  27. "@llvm-project//llvm:Support",
  28. ],
  29. )
  30. cc_binary(
  31. name = "test_binary",
  32. testonly = 1,
  33. srcs = ["test_binary.cpp"],
  34. data = [":install_data"],
  35. )
  36. cc_test(
  37. name = "install_paths_test",
  38. size = "small",
  39. srcs = ["install_paths_test.cpp"],
  40. data = [
  41. ":install_data",
  42. ":test_binary",
  43. ],
  44. deps = [
  45. ":install_paths",
  46. "//common:check",
  47. "//common:ostream",
  48. "//testing/base:global_exe_path",
  49. "//testing/base:gtest_main",
  50. "@bazel_tools//tools/cpp/runfiles",
  51. "@googletest//:gtest",
  52. "@llvm-project//llvm:Support",
  53. ],
  54. )
  55. cc_library(
  56. name = "install_paths_test_helpers",
  57. testonly = 1,
  58. srcs = ["install_paths_test_helpers.cpp"],
  59. hdrs = ["install_paths_test_helpers.h"],
  60. deps = [
  61. ":install_paths",
  62. "//testing/base:global_exe_path",
  63. "@llvm-project//llvm:Support",
  64. ],
  65. )
  66. cc_library(
  67. name = "busybox_info",
  68. hdrs = ["busybox_info.h"],
  69. deps = [
  70. "//common:error",
  71. "@llvm-project//llvm:Support",
  72. ],
  73. )
  74. cc_test(
  75. name = "busybox_info_test",
  76. size = "small",
  77. srcs = ["busybox_info_test.cpp"],
  78. deps = [
  79. ":busybox_info",
  80. "//common:check",
  81. "//testing/base:gtest_main",
  82. "@googletest//:gtest",
  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_busybox_wrapper(
  122. "carbon",
  123. "../lib/carbon/carbon-busybox",
  124. ),
  125. ],
  126. "lib/carbon": [
  127. install_target("carbon_install.txt", "carbon_install.txt"),
  128. install_target(
  129. "carbon-busybox",
  130. ":carbon-busybox",
  131. executable = True,
  132. is_driver = True,
  133. ),
  134. install_filegroup("core", "//core:prelude"),
  135. ],
  136. "lib/carbon/llvm/bin": [
  137. install_target(
  138. "lld",
  139. "@llvm-project//lld:lld",
  140. executable = True,
  141. ),
  142. install_busybox_wrapper(
  143. "clang",
  144. "../../carbon-busybox",
  145. [
  146. "clang",
  147. "--",
  148. ],
  149. ),
  150. ] + [install_symlink(name, "lld") for name in lld_aliases],
  151. }
  152. make_install_filegroups(
  153. name = "install_data",
  154. install_dirs = install_dirs,
  155. no_driver_name = "install_data.no_driver",
  156. pkg_name = "pkg_data",
  157. prefix = "prefix_root",
  158. )
  159. manifest(
  160. name = "install_data_manifest.txt",
  161. srcs = [":install_data"],
  162. )
  163. pkg_naming_variables(
  164. name = "packaging_variables",
  165. )
  166. # We build both a compressed and uncompressed tar file with the same code here.
  167. # This lets us use the tar file in testing as it is fast to create, but ship the
  168. # compressed version as a release.
  169. #
  170. # For manual tests, the tar rules are `carbon_toolchain_tar_rule` and
  171. # `carbon_toolchain_tar_gz_rule`.
  172. pkg_tar_and_test(
  173. srcs = [":pkg_data"],
  174. install_data_manifest = ":install_data_manifest.txt",
  175. name_base = "carbon_toolchain",
  176. package_dir = "carbon_toolchain-$(version)",
  177. package_file_name_base = "carbon_toolchain-$(version)",
  178. package_variables = ":packaging_variables",
  179. stamp = -1, # Allow `--stamp` builds to produce file timestamps.
  180. )
  181. # Support `bazel run` on specific binaries.
  182. run_tool(
  183. name = "run_carbon",
  184. data = [":install_data"],
  185. env = cc_env(),
  186. tool = "prefix_root/bin/carbon",
  187. )