blob: 078fd60a8992f2cddd46af9acbaa5dd1423e94bb [file] [log] [blame]
Rosica Dejanovska807f1bd2021-11-09 11:58:01 +00001# Part of the Crubit project, under the Apache License v2.0 with LLVM
2# Exceptions. See /LICENSE for license information.
3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5"""A rule that generates bindings source files for a given C++ library."""
6
7load(
Marcel Hlopkodaf07032022-09-15 09:26:51 -07008 "//rs_bindings_from_cc/bazel_support:providers.bzl",
Rosica Dejanovska807f1bd2021-11-09 11:58:01 +00009 "GeneratedBindingsInfo",
Rosica Dejanovska67e82432022-02-02 10:49:27 +000010)
11load(
12 "//rs_bindings_from_cc/bazel_support:rust_bindings_from_cc_aspect.bzl",
Rosica Dejanovska807f1bd2021-11-09 11:58:01 +000013 "rust_bindings_from_cc_aspect",
14)
15
16def _generate_bindings_impl(ctx):
17 if not GeneratedBindingsInfo in ctx.attr.cc_library:
18 fail("Bindings were not generated for the given cc_library.")
19 bindings = ctx.attr.cc_library[GeneratedBindingsInfo]
20 return OutputGroupInfo(
21 cc_file = [bindings.cc_file],
22 rust_file = [bindings.rust_file],
Rosica Dejanovska1e63aed2022-09-05 08:08:17 -070023 namespaces_file = [bindings.namespaces_file],
Rosica Dejanovska807f1bd2021-11-09 11:58:01 +000024 )
25
26generate_bindings = rule(
27 attrs = {
28 "cc_library": attr.label(providers = [CcInfo], aspects = [rust_bindings_from_cc_aspect]),
29 },
30 implementation = _generate_bindings_impl,
31)