github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/gpus/cuda/build_defs.bzl.tpl (about)

     1  # Macros for building CUDA code.
     2  def if_cuda(if_true, if_false = []):
     3      """Shorthand for select()'ing on whether we're building with CUDA.
     4  
     5      Returns a select statement which evaluates to if_true if we're building
     6      with CUDA enabled.  Otherwise, the select statement evaluates to if_false.
     7  
     8      """
     9      return select({
    10          "@local_config_cuda//cuda:using_nvcc": if_true,
    11          "@local_config_cuda//cuda:using_clang": if_true,
    12          "//conditions:default": if_false,
    13      })
    14  
    15  def cuda_default_copts():
    16      """Default options for all CUDA compilations."""
    17      return if_cuda(["-x", "cuda", "-DGOOGLE_CUDA=1"] + %{cuda_extra_copts})
    18  
    19  def cuda_is_configured():
    20      """Returns true if CUDA was enabled during the configure process."""
    21      return %{cuda_is_configured}
    22  
    23  def if_cuda_is_configured(x):
    24      """Tests if the CUDA was enabled during the configure process.
    25  
    26      Unlike if_cuda(), this does not require that we are building with
    27      --config=cuda. Used to allow non-CUDA code to depend on CUDA libraries.
    28      """
    29      if cuda_is_configured():
    30        return select({"//conditions:default": x})
    31      return select({"//conditions:default": []})
    32  
    33  def cuda_header_library(
    34          name,
    35          hdrs,
    36          include_prefix = None,
    37          strip_include_prefix = None,
    38          deps = [],
    39          **kwargs):
    40      """Generates a cc_library containing both virtual and system include paths.
    41  
    42      Generates both a header-only target with virtual includes plus the full
    43      target without virtual includes. This works around the fact that bazel can't
    44      mix 'includes' and 'include_prefix' in the same target."""
    45  
    46      native.cc_library(
    47          name = name + "_virtual",
    48          hdrs = hdrs,
    49          include_prefix = include_prefix,
    50          strip_include_prefix = strip_include_prefix,
    51          deps = deps,
    52          visibility = ["//visibility:private"],
    53      )
    54  
    55      native.cc_library(
    56          name = name,
    57          textual_hdrs = hdrs,
    58          deps = deps + [":%s_virtual" % name],
    59          **kwargs
    60      )