cc_toolchain_base_features.bzl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. """Definitions used for the base features of a `cc_toolchain_config`."""
  5. load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
  6. load(
  7. "@rules_cc//cc:cc_toolchain_config_lib.bzl",
  8. "feature",
  9. "feature_set",
  10. "flag_group",
  11. "flag_set",
  12. )
  13. load(
  14. ":cc_toolchain_actions.bzl",
  15. "all_compile_actions",
  16. "all_link_actions",
  17. )
  18. # Declare features that are used by Bazel to model specific build modes.
  19. dbg_feature = feature(name = "dbg")
  20. fastbuild_feature = feature(name = "fastbuild")
  21. host_feature = feature(name = "host")
  22. opt_feature = feature(name = "opt")
  23. # Declare features that control enabling and disabling Bazel logic.
  24. no_legacy_features_feature = feature(name = "no_legacy_features")
  25. supports_pic_feature = feature(name = "supports_pic", enabled = True)
  26. supports_dynamic_linker_feature = feature(
  27. name = "supports_dynamic_linker",
  28. enabled = True,
  29. requires = [feature_set(["linux_target"])],
  30. )
  31. supports_start_end_lib_feature = feature(
  32. name = "supports_start_end_lib",
  33. enabled = True,
  34. requires = [feature_set(["linux_target"])],
  35. )
  36. user_flags_feature = feature(
  37. name = "user_flags",
  38. enabled = True,
  39. flag_sets = [
  40. flag_set(
  41. actions = all_compile_actions,
  42. flag_groups = [flag_group(
  43. expand_if_available = "user_compile_flags",
  44. flags = ["%{user_compile_flags}"],
  45. iterate_over = "user_compile_flags",
  46. )],
  47. ),
  48. flag_set(
  49. actions = all_link_actions,
  50. flag_groups = [flag_group(
  51. expand_if_available = "user_link_flags",
  52. flags = ["%{user_link_flags}"],
  53. iterate_over = "user_link_flags",
  54. )],
  55. ),
  56. ],
  57. )
  58. # TODO: It's not clear this is the right location for these flags, and it is a
  59. # little awkward.
  60. output_flags_feature = feature(
  61. name = "output_flags",
  62. enabled = True,
  63. flag_sets = [
  64. flag_set(
  65. actions = all_compile_actions,
  66. flag_groups = [
  67. # For compile actions we have a single source and so put it at
  68. # the end next to the output.
  69. flag_group(
  70. expand_if_available = "source_file",
  71. flags = ["%{source_file}"],
  72. ),
  73. flag_group(
  74. expand_if_available = "output_file",
  75. flags = ["-o", "%{output_file}"],
  76. ),
  77. ],
  78. ),
  79. flag_set(
  80. actions = all_link_actions,
  81. flag_groups = [flag_group(
  82. expand_if_available = "output_execpath",
  83. flags = ["-o", "%{output_execpath}"],
  84. )],
  85. ),
  86. ],
  87. )
  88. strip_feature = feature(
  89. name = "strip_flags",
  90. enabled = True,
  91. flag_sets = [flag_set(
  92. actions = [ACTION_NAMES.strip],
  93. flag_groups = [
  94. flag_group(
  95. flags = ["-S"],
  96. ),
  97. flag_group(
  98. flags = ["-p"],
  99. ),
  100. flag_group(
  101. expand_if_available = "output_file",
  102. flags = ["-o", "%{output_file}"],
  103. ),
  104. flag_group(
  105. iterate_over = "stripopts",
  106. flags = ["%{stripopts}"],
  107. ),
  108. flag_group(
  109. expand_if_available = "input_file",
  110. flags = ["%{input_file}"],
  111. ),
  112. ],
  113. )],
  114. )
  115. base_features = [
  116. dbg_feature,
  117. fastbuild_feature,
  118. host_feature,
  119. no_legacy_features_feature,
  120. opt_feature,
  121. strip_feature,
  122. supports_pic_feature,
  123. supports_dynamic_linker_feature,
  124. supports_start_end_lib_feature,
  125. ]