Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support C# and/or expose intermediate representation? #846

Open
yanchith opened this issue Jun 13, 2023 · 11 comments
Open

Support C# and/or expose intermediate representation? #846

yanchith opened this issue Jun 13, 2023 · 11 comments

Comments

@yanchith
Copy link

We have a project, where we generate both C and C# bindings for a Rust library. The API is very C-like, and we take care not to use any fancy features in it.

C# bindings are currently generated for us by csbindgen, which is not on par with cbindgen feature-wise (and its authors don't seem like they want it to be). We thus have to employ a lot of hacks to make it work.

cbindgen, on the other hand already supports most of what we need. Is either adding a new C# backend to cbindgen or exposing the intermediate representation so that people can write their own backends possible and desirable?

We might have to do this anyway, but we'll gladly contribute back.

@fredszaq
Copy link
Contributor

Hi there ! I have a project where I'm exposing a rust lib to java/kotlin using JNA, and I'm toying with the idea of adding support inside cbindgen as well.

From what I see in the current code, the swich between the various supported languages is done via ifs in the implementation of Write for the various types in the ir module. This approach worked well for C and C++ but is already showing its limits with Cython, as there are quite a few cases where the Write impls are filled with if config.language == Language::Cython {

Adding a proper backend abstraction seems the way to go especially if we add C# and Java as supported language, maybe a trait with default impls called at relevant places in the Write impls and implemented for each language ?

What do you think @emilio, is even adding support for new languages something you would consider ? I'm happy to do this refactoring and adding java support if you're OK with it

@emilio
Copy link
Collaborator

emilio commented Jun 19, 2023

Yeah, I'd say a general back-end abstraction (probably an initial refactor would be to add CLike and Cython backends) would be a nice path forward.

@fredszaq
Copy link
Contributor

@yanchith @emilio I just opened #853 that contains a refactoring adding language backend abstraction ! Would be glad to have you thoughts on this, this should be at a point where adding new languages should be doable

@fredszaq
Copy link
Contributor

And here is #857 that contains the java backend, can be some inspiration to add the C# one

@Tacodiva
Copy link

Tacodiva commented Nov 14, 2023

@fredszaq @yanchith Is somebody else working on the C# backend or are you looking for contributers? I'd be happy to give it a crack if you liked. I'm a bit of a Rust novice, but know C# and it's interop stuff very well. I think I'd be able to do it but don't want to jump the gun if somebody else has already made progress on it or the language backend is too unstable for now.

@fredszaq
Copy link
Contributor

Hi @Tacodiva I have no plans to work on the C# backend (I don't know the language). If you use the work in #853 adding a new language should be pretty straightforward if you're familiar with the language ffi :P

By the way ping @emilio I would love to see #853 merged at some point (as well as #857) please tell me if there is anything I can do to make this happen. I understand it is quite a big change and could take some time to review, but it seems like adding new languages support to cbindgen is a hot subject these days (see #867 as well) and it would greatly facilitate this !

@yanchith
Copy link
Author

Hi @Tacodiva , I am not working on the C# backend yet. I was waiting for #853. If you want to give it a go, do it, otherwise I'll get to it eventually :)

@ZhaoXiangXML
Copy link

Hello @yanchith @Tacodiva, #853 is merged now, is anyone working on the C# backend? I'm also interested in it especially for Unity.

@Tacodiva
Copy link

@ZhaoXiangXML I am not currently working on it, I have moved onto other things. Eventually I might circle back around to it and when/if I do I'll open a PR here straight away to indicate I am working on it, but for now I am not.

@yanchith
Copy link
Author

@ZhaoXiangXML Neither am I. Feel free to take it, if you are feeling the initiative.

@ZhaoXiangXML
Copy link

Well in that case I'll see if I can do it myself. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants