| 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 |
| 4 |
|
| 5 |
"""Re-export a cc_library with added LLVM specific settings. |
| 6 |
|
| 7 |
This re-exports the dependent libraries in a way that satisfies layering_check |
| 8 |
|
| 9 |
cc_library_wrapper( |
| 10 |
name = "library_wrapper", |
| 11 |
deps = [ |
| 12 |
"@example//:library", |
| 13 |
], |
| 14 |
defines = [ |
| 15 |
"LLVM_ENABLE_EXAMPLE=1", |
| 16 |
], |
| 17 |
) |
| 18 |
""" |
| 19 |
|
| 20 |
load("@rules_cc//cc/common:cc_common.bzl", "cc_common") |
| 21 |
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") |
| 22 |
|
| 23 |
visibility("private") |
| 24 |
|
| 25 |
def _cc_library_wrapper_impl(ctx): |
| 26 |
all_cc_infos = [dep[CcInfo] for dep in ctx.attr.deps] |
| 27 |
if ctx.attr.defines: |
| 28 |
all_cc_infos.append(CcInfo( |
| 29 |
compilation_context = cc_common.create_compilation_context( |
| 30 |
defines = depset(ctx.attr.defines), |
| 31 |
), |
| 32 |
)) |
| 33 |
|
| 34 |
return cc_common.merge_cc_infos(direct_cc_infos = all_cc_infos) |
| 35 |
|
| 36 |
cc_library_wrapper = rule( |
| 37 |
implementation = _cc_library_wrapper_impl, |
| 38 |
attrs = { |
| 39 |
"deps": attr.label_list( |
| 40 |
doc = "Dependencies to cc_library targets to re-export.", |
| 41 |
providers = [CcInfo], |
| 42 |
), |
| 43 |
"defines": attr.string_list( |
| 44 |
doc = "Additional preprocessor definitions to add to all dependent targets.", |
| 45 |
default = [], |
| 46 |
), |
| 47 |
}, |
| 48 |
doc = "Re-export a cc_library with added LLVM specific settings.", |
| 49 |
provides = [CcInfo], |
| 50 |
) |