cc_toolchain_carbon_project_features.bzl 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. "minimal_optimization_flags",
  28. "minimal_debug_info_flags",
  29. "preserve_call_stacks",
  30. ],
  31. )
  32. def carbon_project_features(cache_key):
  33. return [carbon_project_fastbuild_feature, feature(
  34. name = "project_flags",
  35. enabled = True,
  36. flag_sets = [
  37. flag_set(
  38. actions = all_compile_actions,
  39. flag_groups = [flag_group(flags = [
  40. # Don't warn on external code as we can't
  41. # necessarily patch it easily. Note that these have
  42. # to be initial directories in the `#include` line.
  43. "--system-header-prefix=absl/",
  44. "--system-header-prefix=benchmark/",
  45. "--system-header-prefix=boost/",
  46. "--system-header-prefix=clang-tools-extra/",
  47. "--system-header-prefix=clang/",
  48. "--system-header-prefix=gmock/",
  49. "--system-header-prefix=gtest/",
  50. "--system-header-prefix=libfuzzer/",
  51. "--system-header-prefix=llvm/",
  52. "--system-header-prefix=re2/",
  53. "--system-header-prefix=tools/cpp/",
  54. "--system-header-prefix=tree_sitter/",
  55. ])],
  56. ),
  57. flag_set(
  58. actions = preprocessor_compile_actions,
  59. flag_groups = [flag_group(flags = [
  60. # Pass a cache key as a `-D` flag to avoid unintended Bazel
  61. # cache hits when the underlying toolchain changes.
  62. # TODO: We should consider replacing this by causing changes
  63. # to the installed toolchain to more reliably end up as part
  64. # of the action digest.
  65. "-DBAZEL_COMPILE_CACHE_KEY=\"%s\"" % cache_key,
  66. ])],
  67. ),
  68. flag_set(
  69. actions = [
  70. ACTION_NAMES.c_compile,
  71. ACTION_NAMES.cpp_compile,
  72. ACTION_NAMES.cpp_header_parsing,
  73. ACTION_NAMES.cpp_module_compile,
  74. ],
  75. flag_groups = [flag_group(flags = ["-DHAVE_MALLCTL"])],
  76. with_features = [with_feature_set(["freebsd_target"])],
  77. ),
  78. ],
  79. )]