cc_toolchain_modules.bzl 2.4 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. """Definitions of C++ and Clang header modules toolchain features."""
  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. )
  13. use_module_maps = feature(
  14. name = "use_module_maps",
  15. requires = [feature_set(features = ["module_maps"])],
  16. flag_sets = [
  17. flag_set(
  18. actions = [
  19. ACTION_NAMES.c_compile,
  20. ACTION_NAMES.cpp_compile,
  21. ACTION_NAMES.cpp_header_parsing,
  22. ACTION_NAMES.cpp_module_compile,
  23. ],
  24. flag_groups = [
  25. # These flag groups are separate so they do not expand to
  26. # the cross product of the variables.
  27. flag_group(flags = ["-fmodule-name=%{module_name}"]),
  28. flag_group(
  29. flags = ["-fmodule-map-file=%{module_map_file}"],
  30. ),
  31. ],
  32. ),
  33. ],
  34. )
  35. # Tell bazel we support module maps in general, so they will be generated
  36. # for all c/c++ rules.
  37. # Note: not all C++ rules support module maps; thus, do not imply this
  38. # feature from other features - instead, require it.
  39. module_maps = feature(
  40. name = "module_maps",
  41. enabled = True,
  42. implies = [
  43. # "module_map_home_cwd",
  44. # "module_map_without_extern_module",
  45. # "generate_submodules",
  46. ],
  47. )
  48. layering_check = feature(
  49. name = "layering_check",
  50. implies = ["use_module_maps"],
  51. flag_sets = [flag_set(
  52. actions = [
  53. ACTION_NAMES.c_compile,
  54. ACTION_NAMES.cpp_compile,
  55. ACTION_NAMES.cpp_header_parsing,
  56. ACTION_NAMES.cpp_module_compile,
  57. ],
  58. flag_groups = [
  59. flag_group(flags = [
  60. "-fmodules-strict-decluse",
  61. "-Wprivate-header",
  62. ]),
  63. flag_group(
  64. iterate_over = "dependent_module_map_files",
  65. flags = ["-fmodule-map-file=%{dependent_module_map_files}"],
  66. ),
  67. ],
  68. )],
  69. )
  70. # Note that the order of features is significant in this list and determines the
  71. # relative order of flags from the features listed.
  72. modules_features = [
  73. layering_check,
  74. module_maps,
  75. use_module_maps,
  76. ]