|
1 # Integrating Automatically Generated FFI Bindings |
|
2 |
|
3 There are a number of tools to automatically generate bindings between Rust and different |
|
4 foreign languages. |
|
5 |
|
6 1. [bindgen](#bindgen) |
|
7 2. [cbindgen](#cbindgen-integration) |
|
8 3. [cxx](#cxx-integration) |
|
9 |
|
10 ## bindgen |
|
11 |
|
12 [bindgen] is a tool to automatically generate Rust bindings from C headers. |
|
13 As such, integrating bindgen [via a build-script](https://rust-lang.github.io/rust-bindgen/library-usage.html) |
|
14 works well and their doesn't seem to be a need to create CMake rules for |
|
15 generating the bindings. |
|
16 |
|
17 [bindgen]: https://github.com/rust-lang/rust-bindgen |
|
18 |
|
19 ## cbindgen integration |
|
20 |
|
21 ⚠️⚠️⚠️ **EXPERIMENTAL** ⚠️⚠️⚠️ |
|
22 |
|
23 [cbindgen] is a tool that generates C/C++ headers from Rust code. When compiling C/C++ |
|
24 code that `#include`s such generated headers the buildsystem must be aware of the dependencies. |
|
25 Generating the headers via a build-script is possible, but Corrosion offers no guidance here. |
|
26 |
|
27 Instead, Corrosion offers an experimental function to add CMake rules using cbindgen to generate |
|
28 the headers. |
|
29 This is not available on a stable released version yet, and the details are subject to change. |
|
30 {{#include ../../cmake/Corrosion.cmake:corrosion_cbindgen}} |
|
31 |
|
32 ### Current limitations |
|
33 |
|
34 - The current version regenerates the bindings more often then necessary to be on the safe side, |
|
35 but an upstream PR is open to solve this in a future cbindgen version. |
|
36 |
|
37 ## cxx integration |
|
38 |
|
39 ⚠️⚠️⚠️ **EXPERIMENTAL** ⚠️⚠️⚠️ |
|
40 |
|
41 [cxx] is a tool which generates bindings for C++/Rust interop. |
|
42 |
|
43 {{#include ../../cmake/Corrosion.cmake:corrosion_add_cxxbridge}} |