cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

Introduce language backend

Open fredszaq opened this issue 2 years ago • 8 comments

As discussed in #846 this introduces the notion of language backend in order to facilitate the addition of new supported languages to cbindgen

Notable changes:

  • new LanguageBackend trait containing functions to write headers and footers in a source file
  • 2 LanguageBackend impls : CLikeLanguageBackend and CythonLanguageBackend
  • the Source trait is now generic on a LanguageBackend and gets the language backend instead of a config as an argument ( both backend impls, end up wrapping a config)
  • The implementations of Source for the various structs of the ir have been moved to the corresponding backend module as there is now one implementation of Source per LanguageBackend for each relevant ir struct.
  • The implementations of Source for both LanguageBackends come from the existing impls and have been cleaned to contain only the parts relevant to the language of the Backend for which the impl is for

All tests continue to pass without any modification \o/ (those were quite useful during the refacto)

fredszaq avatar Jun 30 '23 14:06 fredszaq

I am not familiar with the codebase, so I can't really review the patch itself. However, looking at clike.rs and cython.rs, this would give me a solid form to fill out to add the C# backend I need. Looking forward 👍

yanchith avatar Jul 02 '23 07:07 yanchith

@emilio Did you have time to take a look ? I'm planning to work on the java-jna backend this week, would be nice to have a confirmation we want to go in this direction ;)

fredszaq avatar Jul 10 '23 12:07 fredszaq

Sorry for the lag getting to this btw :/

emilio avatar Aug 25 '23 15:08 emilio

Thanks for the review ! I think I tried the write_xxx functions in the language backend trait first but was blocked by something. I cannot remember what though. I'll take a look when I'm back from holidays in september

fredszaq avatar Aug 25 '23 21:08 fredszaq

Hi @emilio ! I just rebased the branch and did the changes you asked, this effectively removes the source trait.

fredszaq avatar Sep 06 '23 15:09 fredszaq

Hello, is this MR going to be merged?

ZhaoXiangXML avatar Jan 24 '24 07:01 ZhaoXiangXML

Ping @emilio, I would love to see this merged (and #857) as well. Please tell be what I can do to facilitate this. All the remarks that have been raised till now have been addressed and I'll be pleased to make any other change deemed necessary.

fredszaq avatar Jan 24 '24 10:01 fredszaq

Oh Wow, this was exactly what I was looking for and trying to implement on my own from this night. God thanks I tried searching 'dynamic' on issue list and found this. Great appreciation for your effort and wish it'd be merged onto mainstream as soon as possible, thanks!

kang-sw avatar Jan 30 '24 14:01 kang-sw