Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Rust
  3. csbindgen

csbindgen

MITRust1.9.8

A Rust tool that automatically generates C# FFI bindings from Rust or C libraries for .NET and Unity.

GitHubGitHub
934 stars77 forks0 contributors

What is csbindgen?

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.

Target Audience

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.

Value Proposition

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.

Overview

Generate C# FFI from Rust for automatically brings native code and C native library to .NET and Unity.

Use Cases

Best For

  • Integrating Rust libraries into .NET applications for performance-critical operations
  • Calling existing C libraries from C# without writing manual P/Invoke bindings
  • Adding native compression libraries like LZ4 or Zstandard to Unity games
  • Binding physics engines like Bullet or PhysX to .NET or Unity
  • Building cross-platform .NET applications that depend on native code
  • Automating FFI generation for large C APIs to reduce maintenance overhead

Not Ideal For

  • Projects that only need to bind a handful of simple C functions and prefer the control of manual P/Invoke code
  • Teams working exclusively in .NET without any Rust expertise or willingness to adopt Rust's build system
  • Applications requiring runtime or dynamic binding generation, as csbindgen only generates static code at compile time
  • Libraries with C APIs that rely on variadic arguments, which csbindgen explicitly does not support

Pros & Cons

Pros

Automatic Binding Generation

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.

Cross-Platform Build Support

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.

Unity-Specific Optimizations

Configurable output for Unity's callback system (MonoPInvokeCallback) and platform-specific DLL loading, ensuring compatibility and smooth operation in Unity projects.

Comprehensive Type Marshalling

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.

Cons

No Variadic Argument Support

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'.

Complex Rust Toolchain Dependency

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.

Static Generation Limitations

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.

Frequently Asked Questions

Quick Stats

Stars934
Forks77
Contributors0
Open Issues1
Last commit16 days ago
CreatedSince 2023

Tags

#csharp#native-interop#dotnet#unity#cross-platform#bindgen#rust#code-generation#performance

Built With

b
bindgen
R
Rust
C
CMake

Included in

Rust56.6k
Auto-fetched 7 hours ago

Related Projects

RustPythonRustPython

A Python Interpreter written in Rust

Stars22,217
Forks1,466
Last commit17 hours ago
PyO3PyO3

Rust bindings for the Python interpreter

Stars15,944
Forks995
Last commit14 hours ago
wasm-bindgenwasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript

Stars9,098
Forks1,224
Last commit1 day ago
NeonNeon

Rust bindings for writing safe and fast native Node.js modules.

Stars8,419
Forks286
Last commit10 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub