uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Support for C#

Open CBenoit opened this issue 4 years ago • 4 comments

Hello,

I’m very interested in seeing a C# bindgen target for uniffi-rs. I’m not sure it’s on the roadmap for Mozilla, but would you integrate it in the main repo if someone made a PR? I’ll have to work on consuming Rust libraries from C# at work, and I would like to avoid boilerplate code using a bindings generator and could spend some time investigating writing one for uniffi-rs.

Cheers.

Keywords: csharp bindgen

┆Issue is synchronized with this Jira Task ┆Issue Number: UNIFFI-90

CBenoit avatar Sep 13 '21 18:09 CBenoit

Hi - thanks for your interest. I think your question is best summarized by this comment, the tl;dr of which is:

  • We like the idea of additional bindings, but we don't really like the idea of including all supported bindings in the main repo, nor taking on an expectation that every binding must work at all times due to the stop-energy that would impose on making changes to the core of the tool.
  • We've made a very small start at working on this in #997 (and somewhat related is #1002), but they've fallen off the priority list - we should pick it up again.

IOW, I think we'd support this, but would ideally love for this effort to help work out how we can keep it out of the main repo, or at least advance a plan to move it out. Or a more formal way of allowing them to remain in the repo but have their status clear. Or something :)

mhammond avatar Sep 14 '21 00:09 mhammond

/cc @badboy - do I recall correctly that Glean has some amount of C# bindings code? It might form a good starting point for someone wanting to explore automated bindings generation.

rfk avatar Sep 14 '21 02:09 rfk

/cc @badboy - do I recall correctly that Glean has some amount of C# bindings code? It might form a good starting point for someone wanting to explore automated bindings generation.

We do! -> glean-core/csharp However that part of the codebase is unmaintained, sort of deprecated and doesn't implement all the features of Glean. It might still be a good start to learn what UniFFI needs to generate.

badboy avatar Sep 14 '21 09:09 badboy

Thank you for the prompt answer!

I understand the idea. Indeed, splitting backends into separate crates sounds very good. My understanding is that we could build a backend in a totally separate crate and repository and maybe depend on older versions of uniffi-rs while core is evolving at its own (hopefully faster) pace.

However, I’m not sure I’ll be able to spend time working much on things other than the bindgen backend code so I’ll probably rely on a cbindgensome C headers to C# wrapper generator pipeline for now.

If it can be of help at some point, here are some C# wrapper generators around C headers :

This example of Rust/C# hybrid application could also be another reference with the handwritten C# wrapper code.

CBenoit avatar Sep 14 '21 10:09 CBenoit

C# bindings generator is available at https://github.com/NordSecurity/uniffi-bindgen-cs

Feel free to take it for a spin :wink:

arg0d avatar Mar 01 '23 08:03 arg0d