#cbindgen #wrapper #type #compatible #conversion #safe #c-abi

ffi_types

C ABI compatible wrappers for cbindgen/bindgen

11 releases

0.0.13 Nov 4, 2024
0.0.12 Jul 30, 2024
0.0.9 Jun 19, 2024
0.0.7 May 13, 2024
0.0.4 Jan 12, 2024

#90 in FFI

Download history 33/week @ 2024-09-11 244/week @ 2024-09-18 33/week @ 2024-09-25 15/week @ 2024-10-02 15/week @ 2024-10-09 20/week @ 2024-10-16 23/week @ 2024-10-23 175/week @ 2024-10-30 39/week @ 2024-11-06 1/week @ 2024-11-13 102/week @ 2024-11-20 12/week @ 2024-11-27 47/week @ 2024-12-04 61/week @ 2024-12-11 10/week @ 2024-12-18

119 downloads per month

BSD-2-Clause

31KB
809 lines

ffi_types

This repository provides C-ABI compatible basic Rust types including box, slice, str and boxed slice/str. By carefully following instructions, the types are bindgen/cbindgen compatible and owned values are safe under C++.

The project consists of 2 parts. A rust crate of #[repr(C)] wrappers of rust types and a header file for C++ (or a few more later).

The conversions are intended to be zero-cost.

TODO: link to docs and examples

CBindgen

Use ffi_types::cbindgen::with_cxx_ffi_types() to add proper configuration to cbindgen::Builder.

Bindgen

Block the provided header to blocklist_file. Replace all root::ffi_types:: to ffi_types:: in generated file.

Not the best choice for FFI

If you start a new project, please check cxx fits in your case.

Since the goal of ffi_types is exposing Rust type to C++ side, you need access to C++ code base.

ffi_types only provides types. Nothing is automatic. You still need to manage bindgen/cbindgen.

MSVC is very picky. ffi_types limits convenience initializers for C-prefixed types for MSVC. It will be less convenient and more unsafe.

Dependencies

~0–8.5MB
~87K SLoC