cc_toolchain_carbon_project_features.bzl 3.2 KB

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