![Latest Version]
![docs]
![MIT]
[](https://github.com/ralfbiedert/interoptopus)
The polyglot bindings generator for your library.
```rust use interoptopus::{ffifunction, ffitype, inventory};
pub struct Vec2 { pub x: f32, pub y: f32, }
pub extern "C" fn my_function(input: Vec2) { println!("{}", input.x); }
inventory!(ffiinventory, [], [myfunction], [], []);
```
| Language | Crate | Sample Output | | --- | --- | --- | | C# | interoptopusbackendcsharp | Interop.cs | | C | interoptopusbackendc | myheader.h | | Python1 | interoptopusbackendcpythoncffi | reference.py | | Other | Write your own backend2 | - |
1 Using Python CFFI.
2 Create your own backend in just a few hours. No pull request needed. Pinkie promise.
If you want to ... - create a new API see the hello world, - understand what's possible, see the reference project, - support a new language, copy the C backend.
cargo build
+ cargo test
.Gated behind feature flags, these enable:
derive
- Proc macros such as ffi_type
, ...serde
- Serde attributes on internal types.log
- Invoke log on FFI errors.See the reference project for an overview:
- functions (extern "C"
functions and delegates)
- types (composites, enums, opaques, references, ...)
- constants (primitive constants; results of const evaluation)
- patterns (ASCII pointers, options, slices, classes, ...)
Generated low-level bindings are "zero cost" w.r.t. hand-crafted bindings for that language.
That said, even hand-crafted bindings encounter some target-specific overhead at the FFI boundary (e.g., marshalling or pinning in managed languages) For C# that cost can be nanoseconds, for Python CFFI it can be microseconds.
See this C# call-cost table🔥 for ballpark figures.
DotNet
and Unity
(incl. Burst).Also see our upgrade instructions.
PRs are welcome.