51 lines · plain
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-exception4 5"""Re-export a cc_library with added LLVM specific settings.6 7This re-exports the dependent libraries in a way that satisfies layering_check8 9cc_library_wrapper(10 name = "library_wrapper",11 deps = [12 "@example//:library",13 ],14 defines = [15 "LLVM_ENABLE_EXAMPLE=1",16 ],17)18"""19 20load("@rules_cc//cc/common:cc_common.bzl", "cc_common")21load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")22 23visibility("private")24 25def _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 36cc_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)51