Rosica Dejanovska | 807f1bd | 2021-11-09 11:58:01 +0000 | [diff] [blame] | 1 | # 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 | |
| 7 | load( |
Marcel Hlopko | daf0703 | 2022-09-15 09:26:51 -0700 | [diff] [blame] | 8 | "//rs_bindings_from_cc/bazel_support:providers.bzl", |
Rosica Dejanovska | 807f1bd | 2021-11-09 11:58:01 +0000 | [diff] [blame] | 9 | "GeneratedBindingsInfo", |
Rosica Dejanovska | 67e8243 | 2022-02-02 10:49:27 +0000 | [diff] [blame] | 10 | ) |
| 11 | load( |
| 12 | "//rs_bindings_from_cc/bazel_support:rust_bindings_from_cc_aspect.bzl", |
Rosica Dejanovska | 807f1bd | 2021-11-09 11:58:01 +0000 | [diff] [blame] | 13 | "rust_bindings_from_cc_aspect", |
| 14 | ) |
| 15 | |
| 16 | def _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 Dejanovska | 1e63aed | 2022-09-05 08:08:17 -0700 | [diff] [blame] | 23 | namespaces_file = [bindings.namespaces_file], |
Rosica Dejanovska | 807f1bd | 2021-11-09 11:58:01 +0000 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | generate_bindings = rule( |
| 27 | attrs = { |
| 28 | "cc_library": attr.label(providers = [CcInfo], aspects = [rust_bindings_from_cc_aspect]), |
| 29 | }, |
| 30 | implementation = _generate_bindings_impl, |
| 31 | ) |