this is a cli tool to generate c# bindings from a rust codebase.
cargo install csbinding
csbinding -h
```
USAGE:
csbinding.exe [OPTIONS]
ARGS:
OPTIONS:
-d, --dllname
Under the hood there are some limitations, mostly enforced by my parsing library: csharp_binder. The library will also tries to predict if the bindings generated will be empty and avoid it, no guaranties for now. Maybe later with custom c#
generation
I assume that all *.rs
files in the folder provided will be part of the same dll and as such, only 1 dll name argument is given. If your project crates multiples dll files your will have to edit the bindings with the proper names.
Three types can be exported: Enums, Structs and Functions. Not all of them though. An Enum should be annotated with #[repr(u8)]
or any other bigger Integer. A Struct must be annotated with #[repr(C)]
to have the correct memory representation. A function should also have a pub extern "C"
annotation to be exported properly.
For every rust file that contains exports a new c# file will be generated. It will be better for you to give an output folder for the bindings
Don't export any Rust specific types like static arrays, Vec, String, or slices. Also nothing from std. If you want to export/import lists then do it with pointers and a size arguments.
In the examples folder the are 2 project. One in rust, that generates a library, and one in c# that uses the library to work. Below you can find some examples instruction run will help you run the project. Keep in mind that the are run in windows cmd, adjust them to your terminal environment.
```bash
csbindinglib -o examples\testenv -d printstring.dll examples\print_string
cd examples\print_string cargo b --release
cd .... copy examples\printstring\target\release\printstring.dll examples\test_env
cd examples\test_env dotnet run ```