1 unstable release
0.1.0 | Jul 13, 2019 |
---|
#5 in #csharp
24KB
589 lines
csharpbindgen
csharpbindgen is a Rust library for generating low-level C# bindings from Rust code.
For more details, consult the online documentation or clone this repository and
run cargo doc --open
.
lib.rs
:
csharpbindgen is a library for generating low-level C# bindings from Rust code.
It is currently in a very primitive state, largely designed for use by the Unity Pathfinder plugin and missing many features.
Quick start
The library is intended for use via a Cargo build script.
Here's an example of a simple program that converts some simple Rust code into C#:
let rust = r#"
pub unsafe extern "C" fn my_func(foo: i32) -> f32 { /* ... */ }
"#;
let code = csharpbindgen::Builder::new("MyDll", rust.to_string())
.class_name("MyStuff")
.generate()
.unwrap();
println!("{}", code);
This will print out something like the following C# code:
// This file has been auto-generated, please do not edit it.
using System;
using System.Runtime.InteropServices;
internal class MyStuff {
[DllImport("MyDll")]
internal static extern float my_func(Int32 foo);
}
For a more complete example, see the Unity Pathfinder plugin's build.rs
.
Dependencies
~2MB
~45K SLoC