cc_toolchain_base_features.bzl 3.0 KB

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