mono / CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
MIT License
3.12k stars 512 forks source link

Generate universal (32-bit and 64-bit combined) C# bindings for C #773

Open ddobrev opened 7 years ago

ddobrev commented 7 years ago

Since C compilers do not mangle names of functions, we can easily have universal C# bindings for C by using sequential layouts. We need to complete https://github.com/mono/CppSharp/issues/771 and https://github.com/mono/CppSharp/issues/772 first but then we'll be able to make a really simple change to have sequential layouts generated by default when wrapping C thus getting universal bindings.

jazzay commented 7 years ago

So does this mean currently that the generated code is tied to a specific arch? Do you guys have an estimate of when this might be completed? Also, how does ARM (iOS/Android) fit into this picture? Should I be moving to C based bindings only?

ddobrev commented 7 years ago
  1. Yes;
  2. So far the only estimate we have is June i.e. the Google Summer of Code. However, the two issues this one depends on are not particularly difficult to do so if you'd like to try yourself, we are here to help. Or you could try our support options at https://github.com/mono/CppSharp#support;
  3. We support wrapping iOS and Android;
  4. Only C bindings can be universal and cross-platform because of different C++ mangling and other ABI details per platform. If sharing an identical binding is a crucial requirement to you, then yes, you are forced to use C - and even this will only work after this feature is completed, of course.
jazzay commented 7 years ago

Ok thanks for the information. Will see if I can find some time to help out with this. I will definitely need to go C bindings route, and do not want to go back to writing manual bindings if I can avoid it.

ddobrev commented 7 years ago

This cannot be reliably done, unfortunately. LayoutKind.Sequential is too limited and cannot handle all cases of layouts, even with the correct packing. We are only leaving the option for sequential layouts, off by default and should be used with extreme caution.

ddobrev commented 6 years ago

The remark above is only valid for C++ because of inheritance. We can still safely enable it for C so I am reopening.