1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 """Rules and macros for MLIR"""
7 def if_cuda_available(if_true, if_false = []):
9 # CUDA auto-detection is not yet supported.
10 "//mlir:enable_cuda_config": if_true,
11 "//conditions:default": if_false,
14 def _cc_headers_only_impl(ctx):
15 return CcInfo(compilation_context = ctx.attr.src[CcInfo].compilation_context)
17 cc_headers_only = rule(
18 implementation = _cc_headers_only_impl,
25 doc = "Provides the headers from 'src' without linking anything.",
29 def mlir_c_api_cc_library(
37 """Macro that generates three targets for MLIR C API libraries.
39 * A standard cc_library target ("Name"),
40 * A header-only cc_library target ("NameHeaders")
41 * An implementation cc_library target tagged `alwayslink` suitable for
42 inclusion in a shared library built with cc_binary() ("NameObjects").
44 In order to avoid duplicate symbols, it is important that
45 mlir_c_api_cc_library targets only depend on other mlir_c_api_cc_library
46 targets via the "capi_deps" parameter. This makes it so that "FooObjects"
47 depend on "BarObjects" targets and "Foo" targets depend on "Bar" targets.
48 Don't cross the streams.
50 capi_header_deps = ["%sHeaders" % d for d in capi_deps]
51 capi_object_deps = ["%sObjects" % d for d in capi_deps]
56 deps = deps + capi_deps + header_deps,
60 name = name + "Headers",
62 deps = header_deps + capi_header_deps,
66 name = name + "Objects",
69 deps = deps + capi_object_deps + capi_header_deps + header_deps,