defs.bzl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. load("@bazel_cc_toolchain//:clang_detected_variables.bzl", "llvm_symbolizer")
  6. def cc_env():
  7. """Returns standard environment settings for a cc_binary.
  8. In use, this looks like:
  9. ```
  10. load("//bazel/cc_toolchains:defs.bzl", "cc_env")
  11. cc_binary(
  12. ...
  13. env = cc_env(),
  14. )
  15. ```
  16. We're currently setting this on a target-by-target basis, mainly because
  17. it's difficult to modify default behaviors.
  18. """
  19. env = {"LLVM_SYMBOLIZER_PATH": llvm_symbolizer}
  20. # On macOS, there's a nano zone allocation warning due to asan (arises
  21. # in fastbuild/dbg). This suppresses the warning in `bazel run`.
  22. #
  23. # Concatenation of a dict with a select isn't supported, so we concatenate
  24. # within the select.
  25. # https://github.com/bazelbuild/bazel/issues/12457
  26. return select({
  27. "//bazel/cc_toolchains:macos_asan": env.update({"MallocNanoZone": "0"}),
  28. "//conditions:default": env,
  29. })