cc_toolchain_base_features.bzl 2.7 KB

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