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 is not yet supported.
10 "//conditions:default": if_false,
13 def _cc_headers_only_impl(ctx):
14 return CcInfo(compilation_context = ctx.attr.src[CcInfo].compilation_context)
16 cc_headers_only = rule(
17 implementation = _cc_headers_only_impl,
24 doc = "Provides the headers from 'src' without linking anything.",
28 def mlir_c_api_cc_library(
36 """Macro that generates three targets for MLIR C API libraries.
38 * A standard cc_library target ("Name"),
39 * A header-only cc_library target ("NameHeaders")
40 * An implementation cc_library target tagged `alwayslink` suitable for
41 inclusion in a shared library built with cc_binary() ("NameObjects").
43 In order to avoid duplicate symbols, it is important that
44 mlir_c_api_cc_library targets only depend on other mlir_c_api_cc_library
45 targets via the "capi_deps" parameter. This makes it so that "FooObjects"
46 depend on "BarObjects" targets and "Foo" targets depend on "Bar" targets.
47 Don't cross the streams.
49 capi_header_deps = ["%sHeaders" % d for d in capi_deps]
50 capi_object_deps = ["%sObjects" % d for d in capi_deps]
55 deps = deps + capi_deps + header_deps,
59 name = name + "Headers",
61 deps = header_deps + capi_header_deps,
65 name = name + "Objects",
68 deps = deps + capi_object_deps + capi_header_deps + header_deps,