cc_toolchain_tools.bzl 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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", "ACTION_NAME_GROUPS")
  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. )
  20. def llvm_tool_paths(llvm_bindir, clang_bindir = None):
  21. if not clang_bindir:
  22. clang_bindir = llvm_bindir
  23. return [
  24. tool_path(name = "ar", path = llvm_bindir + "/llvm-ar"),
  25. tool_path(name = "ld", path = clang_bindir + "/ld.lld"),
  26. tool_path(name = "cpp", path = clang_bindir + "/clang-cpp"),
  27. tool_path(name = "gcc", path = clang_bindir + "/clang++"),
  28. tool_path(name = "dwp", path = llvm_bindir + "/llvm-dwp"),
  29. tool_path(name = "gcov", path = llvm_bindir + "/llvm-cov"),
  30. tool_path(name = "nm", path = llvm_bindir + "/llvm-nm"),
  31. tool_path(name = "objcopy", path = llvm_bindir + "/llvm-objcopy"),
  32. tool_path(name = "objdump", path = llvm_bindir + "/llvm-objdump"),
  33. tool_path(name = "strip", path = llvm_bindir + "/llvm-strip"),
  34. ]
  35. def llvm_action_configs(llvm_bindir, clang_bindir = None):
  36. if not clang_bindir:
  37. clang_bindir = llvm_bindir
  38. return [
  39. action_config(
  40. action_name = name,
  41. enabled = True,
  42. tools = [tool(path = clang_bindir + "/clang")],
  43. )
  44. for name in all_c_compile_actions
  45. ] + [
  46. action_config(
  47. action_name = name,
  48. enabled = True,
  49. tools = [tool(path = clang_bindir + "/clang++")],
  50. )
  51. for name in ACTION_NAME_GROUPS.all_cpp_compile_actions
  52. ] + [
  53. action_config(
  54. action_name = name,
  55. enabled = True,
  56. tools = [tool(path = clang_bindir + "/clang++")],
  57. )
  58. for name in ACTION_NAME_GROUPS.all_cc_link_actions
  59. ] + [
  60. action_config(
  61. action_name = name,
  62. enabled = True,
  63. tools = [tool(path = llvm_bindir + "/llvm-ar")],
  64. )
  65. for name in [ACTION_NAMES.cpp_link_static_library]
  66. ] + [
  67. action_config(
  68. action_name = name,
  69. enabled = True,
  70. tools = [tool(path = llvm_bindir + "/llvm-strip")],
  71. )
  72. for name in [ACTION_NAMES.strip]
  73. ]