Crates.io | ffiber |
lib.rs | ffiber |
version | 0.1.0 |
source | src |
created_at | 2022-08-01 23:12:17.227436 |
updated_at | 2022-08-01 23:12:17.227436 |
description | Enable FFI for calling Rust from C by translating Rust-y library interfaces to extern C functions. |
homepage | https://github.com/ygina/ffiber/tree/master |
repository | https://github.com/ygina/ffiber/tree/master |
max_upload_size | |
id | 637102 |
size | 62,613 |
ffiber generates C bindings from Rust libraries with Rust-y function interfaces.
When calling C from Rust, the more common direction, it is recommended to write a safe wrapping module around low-level C bindings to ensure memory safety and security invariants at the Rust level. When calling Rust from C, Rust library developers should first write their libraries with a safe, Rust-y interface. They can then use ffiber to programmatically generate low-level extern C functions, and a tool like cbindgen to generate the C header file.
ffiber is currently only available as a library (such as in your build.rs).
CDylibCompiler
.add_dependency()
to add crate dependencies, including the library you
are trying to bind.import()
to import the necessary crates, structs, traits, functions
etc. to the generated src/lib.rs.add_extern_c_function()
to generate wrappers around library
functions based on their specifications.If necessary, you can also use the inner SerializationCompiler
to manually
generate code. This may be helpful, for example, to create intermediate
wrapper functions for unimplemented features such as tuple arguments.
Executing this code will generate a crate at your specified path. This crate
has cbindgen
as a build dependency by default. Build this crate to generate a
C header file at its root.
See examples/
.
cargo r --release cornflakes
cd mlx5-datapath-c
cargo b # mlx5_datapath.h
Codebases that use ffiber:
Several features are planned. Comment on an issue if you'd like to help.