BUILD 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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("install_filegroups.bzl", "install_filegroup", "install_symlink", "install_target", "make_install_filegroups")
  6. load("pkg_helpers.bzl", "pkg_naming_variables", "pkg_tar_and_test")
  7. load("run_tool.bzl", "run_tool")
  8. package(default_visibility = ["//visibility:public"])
  9. # Build rules supporting the install data tree for the Carbon toolchain.
  10. #
  11. # This populates a synthetic Carbon toolchain installation under the
  12. # `prefix_root` directory. For details on its layout, see `install_paths.h`.
  13. # A library for computing install paths for the toolchain. Note that this
  14. # library does *not* include the data itself, as that would form a dependency
  15. # cycle. Each part of the toolchain should add the narrow data file groups to
  16. # their data dependencies, and then use this library to locate them.
  17. cc_library(
  18. name = "install_paths",
  19. srcs = ["install_paths.cpp"],
  20. hdrs = ["install_paths.h"],
  21. deps = [
  22. "//common:check",
  23. "//common:error",
  24. "@bazel_tools//tools/cpp/runfiles",
  25. "@llvm-project//llvm:Support",
  26. ],
  27. )
  28. cc_binary(
  29. name = "test_binary",
  30. testonly = 1,
  31. srcs = ["test_binary.cpp"],
  32. data = [":install_data"],
  33. )
  34. cc_test(
  35. name = "install_paths_test",
  36. size = "small",
  37. srcs = ["install_paths_test.cpp"],
  38. data = [
  39. ":install_data",
  40. ":test_binary",
  41. ],
  42. deps = [
  43. ":install_paths",
  44. "//common:check",
  45. "//common:ostream",
  46. "//testing/base:global_exe_path",
  47. "//testing/base:gtest_main",
  48. "@bazel_tools//tools/cpp/runfiles",
  49. "@googletest//:gtest",
  50. "@llvm-project//llvm:Support",
  51. ],
  52. )
  53. cc_library(
  54. name = "install_paths_test_helpers",
  55. testonly = 1,
  56. srcs = ["install_paths_test_helpers.cpp"],
  57. hdrs = ["install_paths_test_helpers.h"],
  58. deps = [
  59. ":install_paths",
  60. "//testing/base:global_exe_path",
  61. "@llvm-project//llvm:Support",
  62. ],
  63. )
  64. lld_aliases = [
  65. "ld.lld",
  66. "ld64.lld",
  67. "lld-link",
  68. "wasm-ld",
  69. ]
  70. install_dirs = {
  71. "bin": [
  72. install_target(
  73. "carbon",
  74. "//toolchain/driver:carbon",
  75. executable = True,
  76. is_driver = True,
  77. ),
  78. ],
  79. "lib/carbon": [
  80. install_target("carbon_install.txt", "carbon_install.txt"),
  81. install_filegroup("core", "//core:prelude"),
  82. ],
  83. "lib/carbon/llvm/bin": [
  84. install_target(
  85. "lld",
  86. "@llvm-project//lld:lld",
  87. executable = True,
  88. ),
  89. ] + [install_symlink(name, "lld") for name in lld_aliases],
  90. }
  91. make_install_filegroups(
  92. name = "install_data",
  93. install_dirs = install_dirs,
  94. no_driver_name = "install_data.no_driver",
  95. pkg_name = "pkg_data",
  96. prefix = "prefix_root",
  97. )
  98. pkg_naming_variables(
  99. name = "packaging_variables",
  100. )
  101. # We build both a compressed and uncompressed tar file with the same code here.
  102. # This lets us use the tar file in testing as it is fast to create, but ship the
  103. # compressed version as a release.
  104. pkg_tar_and_test(
  105. srcs = [":pkg_data"],
  106. name_base = "carbon_toolchain",
  107. package_dir = "carbon_toolchain-$(version)",
  108. package_file_name_base = "carbon_toolchain-$(version)",
  109. package_variables = ":packaging_variables",
  110. stamp = -1, # Allow `--stamp` builds to produce file timestamps.
  111. test_data = [
  112. ":install_data",
  113. ],
  114. # TODO: This is used to make sure that tar files are in install_data (one
  115. # direction). Replace with a check that the files in install_data and tar
  116. # match (bidirectional).
  117. test_install_marker = "prefix_root/lib/carbon/carbon_install.txt",
  118. )
  119. # Support `bazel run` on specific binaries.
  120. run_tool(
  121. name = "run_carbon",
  122. data = [":install_data"],
  123. tool = "prefix_root/bin/carbon",
  124. )