cc_toolchain_tools.bzl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. """Macros to produce tool-related parts of a `cc_toolchain_config`.
  5. These macros cover both the `actions_config` array and the `tool_paths` array.
  6. They presume an LLVM and Clang toolchain's tools, but support both a single
  7. installation and installations that split the LLVM tools and Clang tools apart.
  8. """
  9. load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
  10. load(
  11. "@rules_cc//cc:cc_toolchain_config_lib.bzl",
  12. "action_config",
  13. "tool",
  14. "tool_path",
  15. )
  16. load(
  17. ":cc_toolchain_actions.bzl",
  18. "all_c_compile_actions",
  19. "all_cpp_compile_actions",
  20. "all_link_actions",
  21. )
  22. def llvm_tool_paths(llvm_bindir, clang_bindir = None):
  23. if not clang_bindir:
  24. clang_bindir = llvm_bindir
  25. return [
  26. tool_path(name = "ar", path = llvm_bindir + "/llvm-ar"),
  27. tool_path(name = "ld", path = clang_bindir + "/ld.lld"),
  28. tool_path(name = "cpp", path = clang_bindir + "/clang-cpp"),
  29. tool_path(name = "gcc", path = clang_bindir + "/clang++"),
  30. tool_path(name = "dwp", path = llvm_bindir + "/llvm-dwp"),
  31. tool_path(name = "gcov", path = llvm_bindir + "/llvm-cov"),
  32. tool_path(name = "nm", path = llvm_bindir + "/llvm-nm"),
  33. tool_path(name = "objcopy", path = llvm_bindir + "/llvm-objcopy"),
  34. tool_path(name = "objdump", path = llvm_bindir + "/llvm-objdump"),
  35. tool_path(name = "strip", path = llvm_bindir + "/llvm-strip"),
  36. ]
  37. def llvm_action_configs(llvm_bindir, clang_bindir = None):
  38. if not clang_bindir:
  39. clang_bindir = llvm_bindir
  40. return [
  41. action_config(
  42. action_name = name,
  43. enabled = True,
  44. tools = [tool(path = clang_bindir + "/clang")],
  45. )
  46. for name in all_c_compile_actions
  47. ] + [
  48. action_config(
  49. action_name = name,
  50. enabled = True,
  51. tools = [tool(path = clang_bindir + "/clang++")],
  52. )
  53. for name in all_cpp_compile_actions
  54. ] + [
  55. action_config(
  56. action_name = name,
  57. enabled = True,
  58. tools = [tool(path = clang_bindir + "/clang++")],
  59. )
  60. for name in all_link_actions
  61. ] + [
  62. action_config(
  63. action_name = name,
  64. enabled = True,
  65. tools = [tool(path = llvm_bindir + "/llvm-ar")],
  66. )
  67. for name in [ACTION_NAMES.cpp_link_static_library]
  68. ] + [
  69. action_config(
  70. action_name = name,
  71. enabled = True,
  72. tools = [tool(path = llvm_bindir + "/llvm-strip")],
  73. )
  74. for name in [ACTION_NAMES.strip]
  75. ]