cc_toolchain_features.bzl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. """Helpers to construct ordered sequences of `cc_toolchain` features."""
  5. load(
  6. ":cc_toolchain_base_features.bzl",
  7. "base_features",
  8. "output_flags_feature",
  9. "user_flags_feature",
  10. )
  11. load(
  12. ":cc_toolchain_config_features.bzl",
  13. "target_cpu_features",
  14. "target_os_features",
  15. )
  16. load(
  17. ":cc_toolchain_cpp_features.bzl",
  18. "clang_feature",
  19. "clang_warnings_feature",
  20. )
  21. load(":cc_toolchain_debugging.bzl", "debugging_features")
  22. load(":cc_toolchain_linking.bzl", "linking_features")
  23. load(":cc_toolchain_modules.bzl", "modules_features")
  24. load(":cc_toolchain_optimization.bzl", "optimization_features")
  25. load(":cc_toolchain_sanitizer_features.bzl", "sanitizer_features")
  26. def clang_cc_toolchain_features(
  27. target_os,
  28. target_cpu,
  29. project_features = [],
  30. extra_cpp_features = []):
  31. """Builds a sequence of Clang-oriented `cc_toolchain_config` features.
  32. Returns:
  33. The list of features for calling `create_cc_toolchain_config_info`.
  34. Args:
  35. target_os: Used to select OS-specific features to include.
  36. target_cpu: Used to select CPU-specific features to include.
  37. project_features: Optional list of project-specific features to include.
  38. extra_cpp_features: Optional list of extra C++ features to include, for
  39. example `libcxx_feature` can be passed here to enable using libc++.
  40. """
  41. # The order of the features determines the relative order of flags used.
  42. features = []
  43. features += target_os_features(target_os)
  44. features += target_cpu_features(target_cpu)
  45. features += base_features
  46. features += [
  47. # We always use Clang in the toolchain and enable all of its warnings.
  48. clang_feature,
  49. clang_warnings_feature,
  50. ]
  51. # Enable any extra baseline C++ features here where others can override
  52. # their flags if needed.
  53. features += extra_cpp_features
  54. features += sanitizer_features
  55. features += optimization_features
  56. features += modules_features
  57. features += debugging_features
  58. features += linking_features
  59. # Lastly, we add project features and the user flags so they can override
  60. # anything above, and the output flags last of all for ease of debugging.
  61. features += project_features
  62. features += [
  63. user_flags_feature,
  64. output_flags_feature,
  65. ]
  66. return features