Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.
/ cs-bindgen Public archive

Experiment in using Rust to build a library that can be loaded by Unity across multiple platforms

Notifications You must be signed in to change notification settings

randomPoison/cs-bindgen

Repository files navigation

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

  • Make sure you have the latest version of Rust installed:

    rustup update
    
  • Install the wasm32-unknown-unknown toolchain:

    rustup target add wasm32-unknown-unknown
    
  • Make sure you have the .NET Core CLI installed if you're going to run the integration test suite.

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

About

Experiment in using Rust to build a library that can be loaded by Unity across multiple platforms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published