randomPoison / cs-bindgen

Experiment in using Rust to build a library that can be loaded by Unity across multiple platforms
4 stars 0 forks source link

cs-bindgen

Facilitating high-level interactions between Rust and C#.

Built with 🦀🔪 by a disgruntled Unity developer

Example

Declare 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);

Status

Highly experimental! Do not use, even as a joke!

Setup

Running Integration Tests

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