gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/tools/bazeldefs/cc.bzl (about)

     1  """C++ rules."""
     2  
     3  load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", _cc_grpc_library = "cc_grpc_library")
     4  load("@rules_cc//cc:defs.bzl", _cc_binary = "cc_binary", _cc_library = "cc_library", _cc_proto_library = "cc_proto_library", _cc_test = "cc_test")
     5  
     6  cc_library = _cc_library
     7  cc_proto_library = _cc_proto_library
     8  cc_test = _cc_test
     9  cc_toolchain = "@bazel_tools//tools/cpp:current_cc_toolchain"
    10  gtest = "@com_google_googletest//:gtest"
    11  gbenchmark = "@com_google_benchmark//:benchmark"
    12  gbenchmark_internal = "@com_google_benchmark//:benchmark"
    13  grpcpp = "@com_github_grpc_grpc//:grpc++"
    14  vdso_linker_option = "-fuse-ld=gold "
    15  
    16  def _cc_flags_supplier_impl(ctx):
    17      variables = platform_common.TemplateVariableInfo({
    18          "CC_FLAGS": "",
    19      })
    20      return [variables]
    21  
    22  cc_flags_supplier = rule(
    23      implementation = _cc_flags_supplier_impl,
    24  )
    25  
    26  def cc_grpc_library(name, **kwargs):
    27      _cc_grpc_library(name = name, grpc_only = True, **kwargs)
    28  
    29  def cc_binary(name, static = False, tcmalloc = False, **kwargs):
    30      """Run cc_binary.
    31  
    32      Args:
    33          name: name of the target.
    34          static: make a static binary if True
    35          tcmalloc: use TCMalloc if True (not implemented)
    36          **kwargs: the rest of the args.
    37      """
    38      if static:
    39          # How to statically link a c++ program that uses threads, like for gRPC:
    40          # https://gcc.gnu.org/legacy-ml/gcc-help/2010-05/msg00029.html
    41          if "linkopts" not in kwargs:
    42              kwargs["linkopts"] = []
    43          kwargs["linkopts"] += [
    44              "-static",
    45              "-lstdc++",
    46              "-Wl,--whole-archive",
    47              "-lpthread",
    48              "-Wl,--no-whole-archive",
    49          ]
    50      if tcmalloc:
    51          # buildifier: disable=print
    52          print("Warning: tcmalloc can't be enabled")
    53  
    54      _cc_binary(
    55          name = name,
    56          **kwargs
    57      )
    58  
    59  def select_gtest():
    60      return [gtest]  # No select is needed.