BUILD 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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("install_filegroups.bzl", "install_filegroup", "install_symlink", "install_target", "make_install_filegroups")
  7. load("pkg_helpers.bzl", "pkg_naming_variables", "pkg_tar_and_test")
  8. load("run_tool.bzl", "run_tool")
  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. lld_aliases = [
  66. "ld.lld",
  67. "ld64.lld",
  68. "lld-link",
  69. "wasm-ld",
  70. ]
  71. # Given a root `prefix_root`, the hierarchy looks like:
  72. #
  73. # - prefix_root/bin: Binaries intended for direct use.
  74. # - prefix_root/lib/carbon: Private data and files.
  75. # - prefix_root/lib/carbon/core: The `Core` package files.
  76. # - prefix_root/lib/carbon/llvm/bin: LLVM binaries.
  77. #
  78. # This will be how installs are provided on Unix-y platforms, and is loosely
  79. # based on the FHS (Filesystem Hierarchy Standard).
  80. install_dirs = {
  81. "bin": [
  82. install_target(
  83. "carbon",
  84. "//toolchain/driver:carbon",
  85. executable = True,
  86. is_driver = True,
  87. ),
  88. ],
  89. "lib/carbon": [
  90. install_target("carbon_install.txt", "carbon_install.txt"),
  91. install_filegroup("core", "//core:prelude"),
  92. ],
  93. "lib/carbon/llvm/bin": [
  94. install_target(
  95. "lld",
  96. "@llvm-project//lld:lld",
  97. executable = True,
  98. ),
  99. ] + [install_symlink(name, "lld") for name in lld_aliases],
  100. }
  101. make_install_filegroups(
  102. name = "install_data",
  103. install_dirs = install_dirs,
  104. no_driver_name = "install_data.no_driver",
  105. pkg_name = "pkg_data",
  106. prefix = "prefix_root",
  107. )
  108. pkg_naming_variables(
  109. name = "packaging_variables",
  110. )
  111. # We build both a compressed and uncompressed tar file with the same code here.
  112. # This lets us use the tar file in testing as it is fast to create, but ship the
  113. # compressed version as a release.
  114. pkg_tar_and_test(
  115. srcs = [":pkg_data"],
  116. name_base = "carbon_toolchain",
  117. package_dir = "carbon_toolchain-$(version)",
  118. package_file_name_base = "carbon_toolchain-$(version)",
  119. package_variables = ":packaging_variables",
  120. stamp = -1, # Allow `--stamp` builds to produce file timestamps.
  121. test_data = [
  122. ":install_data",
  123. ],
  124. # TODO: This is used to make sure that tar files are in install_data (one
  125. # direction). Replace with a check that the files in install_data and tar
  126. # match (bidirectional).
  127. test_install_marker = "prefix_root/lib/carbon/carbon_install.txt",
  128. )
  129. # Support `bazel run` on specific binaries.
  130. run_tool(
  131. name = "run_carbon",
  132. data = [":install_data"],
  133. env = cc_env(),
  134. tool = "prefix_root/bin/carbon",
  135. )