cc_toolchain_base_features.bzl 3.8 KB

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