A Rust tool that automatically generates C# FFI bindings from Rust or C libraries for .NET and Unity.
csbindgen is a Rust-based tool that automatically generates C# Foreign Function Interface (FFI) bindings from Rust `extern "C"` code or C libraries. It solves the problem of manually writing and maintaining `DllImport` declarations for calling native code from .NET and Unity, ensuring correct calling conventions and platform-specific configurations.
Developers working with .NET or Unity who need to integrate native Rust or C libraries for performance-critical tasks like compression, physics, or networking, and want to avoid the boilerplate and errors of manual FFI binding.
It automates the entire FFI binding process with robust type mapping and cross-platform support, reducing manual effort and potential bugs. Its integration with Rust's build system and compatibility with Unity make it a versatile choice for projects that require high-performance native interop.
Generate C# FFI from Rust for automatically brings native code and C native library to .NET and Unity.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Generates optimized C# DllImport code from Rust extern C functions or C headers, handling calling conventions and platform differences automatically, as shown in examples like lz4_bindgen.cs.
Integrates with Rust's toolchain and crates like cc and cmake to build and link C code, enabling multi-platform deployment for .NET and Unity applications.
Configurable output for Unity's callback system (MonoPInvokeCallback) and platform-specific DLL loading, ensuring compatibility and smooth operation in Unity projects.
Maps a wide range of Rust types to appropriate C# types, including primitives, structs, enums, and function pointers, with support for bitflags and advanced configurations as detailed in the type table.
csbindgen cannot handle C's variadic arguments, limiting its use with libraries that rely on this feature, as explicitly stated in the README under 'Non-Generatable method'.
Requires setting up Rust build dependencies and understanding of build.rs scripts, which adds overhead and a learning curve for .NET-focused teams unfamiliar with Rust.
Bindings are generated at build time, so any changes to the native API require re-generation and rebuild, unlike dynamic binding solutions that adapt at runtime.