defs.bzl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. """Provides helpers for cc rules. Intended for general consumption."""
  5. # The hermetic llvm-symbolizer target.
  6. _llvm_symbolizer = "@llvm-project//llvm:llvm-symbolizer"
  7. def cc_env():
  8. """Returns standard environment settings for a cc_binary.
  9. In use, this should set both `data` and `env`, as in:
  10. ```
  11. load("//bazel/cc_toolchains:defs.bzl", "cc_env", "cc_env_data")
  12. cc_binary(
  13. ...
  14. data = cc_env_data(),
  15. env = cc_env(),
  16. )
  17. ```
  18. We're currently setting this on a target-by-target basis, mainly because
  19. it's difficult to modify default behaviors.
  20. """
  21. env = {"LLVM_SYMBOLIZER_PATH": "$(location {0})".format(_llvm_symbolizer)}
  22. # On macOS, there's a nano zone allocation warning due to asan (arises
  23. # in fastbuild/dbg). This suppresses the warning in `bazel run`.
  24. #
  25. # Concatenation of a dict with a select isn't supported, so we concatenate
  26. # within the select.
  27. # https://github.com/bazelbuild/bazel/issues/12457
  28. return select({
  29. "//bazel/cc_toolchains:macos_asan": env.update({"MallocNanoZone": "0"}),
  30. "//conditions:default": env,
  31. })
  32. def cc_env_data():
  33. """Returns data needed for cc_env().
  34. Set up as a function mainly for parity, and in case we need future changes.
  35. """
  36. return [_llvm_symbolizer]