cs-bindgen
Facilitating high-level interactions between Rust and C#.
Built with 🦀🔪 by a disgruntled Unity developerDeclare functions in Rust and expose them to C#.
#[cs_bindgen]
pub fn greet(name: String) -> String {
format!("Hello, {}!", name)
}
Call into Rust code from C# as if it were idiomatic C#!
var greeting = Example.Greet("Ferris");
// Prints "Hello, Ferris!"
Console.WriteLine(greeting);
Highly experimental! Do not use, even as a joke!
Make sure you have the latest version of Rust installed:
rustup update
Install the wasm32-unknown-unknown
toolchain:
rustup target add wasm32-unknown-unknown
In addition to the usual Rust testing setup that can be run via cargo run
, there's a more complete integration test setup that builds C# bindings into a .NET Core project and uses xUnit to test that the Rust binary can be embedded correctly. To setup the bindings for the tests, first run:
cargo run -p builder
Then, to run the tests, navigate to the integration-tests/TestRunner
directory and run:
dotnet test