cc_toolchain_config_features.bzl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. """Configuration features for other features in a `cc_toolchain_config`.
  5. These features are designed to be used by other features in a
  6. `cc_toolchain_config` that need to configure their behavior in some way. This
  7. can be configuration based on either the target or host of the build, and along
  8. multiple dimensions of each.
  9. """
  10. load(
  11. "@rules_cc//cc:cc_toolchain_config_lib.bzl",
  12. "feature",
  13. )
  14. os_names = [
  15. "freebsd",
  16. "linux",
  17. "macos",
  18. "windows",
  19. ]
  20. def target_os_features(target_os):
  21. if target_os not in os_names:
  22. fail("Unsupported target OS: %s" % target_os)
  23. return [
  24. feature(name = os_name + "_target", enabled = os_name == target_os)
  25. for os_name in os_names
  26. ]
  27. cpu_names = [
  28. "aarch64",
  29. "x86_64",
  30. ]
  31. # Also support canonicalizing different spellings of CPUs to one of the above
  32. # names.
  33. cpu_canonical_name_map = {
  34. "aarch64": "aarch64",
  35. "arm64": "aarch64",
  36. "x86_64": "x86_64",
  37. }
  38. def target_cpu_features(target_cpu):
  39. if target_cpu not in cpu_canonical_name_map:
  40. fail("Unsupported target CPU: %s" % target_cpu)
  41. target_cpu = cpu_canonical_name_map[target_cpu]
  42. return [
  43. feature(name = cpu_name + "_target", enabled = cpu_name == target_cpu)
  44. for cpu_name in cpu_names
  45. ]