cc_toolchain_carbon_project_features.bzl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. """Defines `cc_toolchain_config` features specific to the Carbon project."""
  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. "with_feature_set",
  13. )
  14. load(
  15. ":cc_toolchain_actions.bzl",
  16. "all_compile_actions",
  17. "preprocessor_compile_actions",
  18. )
  19. # An enabled feature that requires the `fastbuild` compilation. This is used
  20. # to toggle general features on by default, while allowing them to be
  21. # directly enabled and disabled more generally as desired.
  22. carbon_project_fastbuild_feature = feature(
  23. name = "enable_in_fastbuild",
  24. enabled = True,
  25. requires = [feature_set(["fastbuild"])],
  26. implies = [
  27. "asan",
  28. "asan_min_size",
  29. "minimal_optimization_flags",
  30. "minimal_debug_info_flags",
  31. ],
  32. )
  33. def carbon_project_features(cache_key):
  34. return [carbon_project_fastbuild_feature, feature(
  35. name = "project_flags",
  36. enabled = True,
  37. flag_sets = [
  38. flag_set(
  39. actions = all_compile_actions,
  40. flag_groups = [flag_group(flags = [
  41. # Don't warn on external code as we can't
  42. # necessarily patch it easily. Note that these have
  43. # to be initial directories in the `#include` line.
  44. "--system-header-prefix=absl/",
  45. "--system-header-prefix=benchmark/",
  46. "--system-header-prefix=boost/",
  47. "--system-header-prefix=clang-tools-extra/",
  48. "--system-header-prefix=clang/",
  49. "--system-header-prefix=gmock/",
  50. "--system-header-prefix=gtest/",
  51. "--system-header-prefix=libfuzzer/",
  52. "--system-header-prefix=llvm/",
  53. "--system-header-prefix=re2/",
  54. "--system-header-prefix=tools/cpp/",
  55. "--system-header-prefix=tree_sitter/",
  56. ])],
  57. ),
  58. flag_set(
  59. actions = preprocessor_compile_actions,
  60. flag_groups = [flag_group(flags = [
  61. # Pass a cache key as a `-D` flag to avoid unintended Bazel
  62. # cache hits when the underlying toolchain changes.
  63. # TODO: We should consider replacing this by causing changes
  64. # to the installed toolchain to more reliably end up as part
  65. # of the action digest.
  66. "-DBAZEL_COMPILE_CACHE_KEY=\"%s\"" % cache_key,
  67. ])],
  68. ),
  69. flag_set(
  70. actions = [
  71. ACTION_NAMES.c_compile,
  72. ACTION_NAMES.cpp_compile,
  73. ACTION_NAMES.cpp_header_parsing,
  74. ACTION_NAMES.cpp_module_compile,
  75. ],
  76. flag_groups = [flag_group(flags = ["-DHAVE_MALLCTL"])],
  77. with_features = [with_feature_set(["freebsd_target"])],
  78. ),
  79. ],
  80. )]