BUILD 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. 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. # This target doesn't include prelude libraries. To get a target that has the
  67. # prelude available, use //toolchain.
  68. cc_binary(
  69. name = "carbon-busybox",
  70. srcs = ["busybox_main.cpp"],
  71. env = cc_env(),
  72. deps = [
  73. ":install_paths",
  74. "//common:all_llvm_targets",
  75. "//common:bazel_working_dir",
  76. "//common:error",
  77. "//common:exe_path",
  78. "//common:init_llvm",
  79. "//common:version_stamp",
  80. "//toolchain/driver",
  81. "@llvm-project//llvm:Support",
  82. ],
  83. )
  84. lld_aliases = [
  85. "ld.lld",
  86. "ld64.lld",
  87. "lld-link",
  88. "wasm-ld",
  89. ]
  90. # Given a root `prefix_root`, the hierarchy looks like:
  91. #
  92. # - prefix_root/bin: Binaries intended for direct use.
  93. # - prefix_root/lib/carbon: Private data and files.
  94. # - prefix_root/lib/carbon/core: The `Core` package files.
  95. # - prefix_root/lib/carbon/llvm/bin: LLVM binaries.
  96. #
  97. # This will be how installs are provided on Unix-y platforms, and is loosely
  98. # based on the FHS (Filesystem Hierarchy Standard).
  99. install_dirs = {
  100. "bin": [
  101. install_symlink(
  102. "carbon",
  103. "../lib/carbon/carbon-busybox",
  104. is_driver = True,
  105. ),
  106. ],
  107. "lib/carbon": [
  108. install_target("carbon_install.txt", "carbon_install.txt"),
  109. install_target(
  110. "carbon-busybox",
  111. ":carbon-busybox",
  112. executable = True,
  113. is_driver = True,
  114. ),
  115. install_filegroup("core", "//core:prelude"),
  116. ],
  117. "lib/carbon/llvm/bin": [
  118. install_target(
  119. "lld",
  120. "@llvm-project//lld:lld",
  121. executable = True,
  122. ),
  123. install_symlink(
  124. "clang",
  125. "../../carbon-busybox",
  126. is_driver = True,
  127. ),
  128. ] + [install_symlink(name, "lld") for name in lld_aliases],
  129. }
  130. make_install_filegroups(
  131. name = "install_data",
  132. install_dirs = install_dirs,
  133. no_driver_name = "install_data.no_driver",
  134. pkg_name = "pkg_data",
  135. prefix = "prefix_root",
  136. )
  137. manifest(
  138. name = "install_data_manifest.txt",
  139. srcs = [":install_data"],
  140. )
  141. pkg_naming_variables(
  142. name = "packaging_variables",
  143. )
  144. # We build both a compressed and uncompressed tar file with the same code here.
  145. # This lets us use the tar file in testing as it is fast to create, but ship the
  146. # compressed version as a release.
  147. #
  148. # For manual tests, the tar rules are `carbon_toolchain_tar_rule` and
  149. # `carbon_toolchain_tar_gz_rule`.
  150. pkg_tar_and_test(
  151. srcs = [":pkg_data"],
  152. install_data_manifest = ":install_data_manifest.txt",
  153. name_base = "carbon_toolchain",
  154. package_dir = "carbon_toolchain-$(version)",
  155. package_file_name_base = "carbon_toolchain-$(version)",
  156. package_variables = ":packaging_variables",
  157. stamp = -1, # Allow `--stamp` builds to produce file timestamps.
  158. )
  159. # Support `bazel run` on specific binaries.
  160. run_tool(
  161. name = "run_carbon",
  162. data = [":install_data"],
  163. env = cc_env(),
  164. tool = "prefix_root/bin/carbon",
  165. )