blob: 9cced889ade7e14283dde268f5d1a4c1a286590f [file] [log] [blame]
# Part of the Crubit project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""A rule that generates bindings source files for a given C++ library."""
load(
"//rs_bindings_from_cc/bazel_support:rust_bindings_from_cc_utils.bzl",
"GeneratedBindingsInfo",
)
load(
"//rs_bindings_from_cc/bazel_support:rust_bindings_from_cc_aspect.bzl",
"rust_bindings_from_cc_aspect",
)
def _generate_bindings_impl(ctx):
if not GeneratedBindingsInfo in ctx.attr.cc_library:
fail("Bindings were not generated for the given cc_library.")
bindings = ctx.attr.cc_library[GeneratedBindingsInfo]
return OutputGroupInfo(
cc_file = [bindings.cc_file],
rust_file = [bindings.rust_file],
)
generate_bindings = rule(
attrs = {
"cc_library": attr.label(providers = [CcInfo], aspects = [rust_bindings_from_cc_aspect]),
},
implementation = _generate_bindings_impl,
)