C++ roadmap

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Nov 15 09:17:29 UTC 2019


Hi Luke
Thanks for the pointer. This is exactly what we're trying to do; Sundar 
is heroically working through a list of issues with libclang itself when 
it comes to C++ template processing - in other words, libclang is not as 
reliable as we would have liked to do this and it seems we would need to 
patch it a bit to be able to get there. But, that said, the overall 
approach is sound and solid.

More specifically, I was not surprised that Rust considered doing a 
single binding per library (regardless of architecture/compiler) - 
that's always the starting assumption; in Panama we gave up on that long 
ago - the bindings we generate are platform specific - and within a 
platform you can rely on the ABI to give you stable result (for C, not 
for C++, of course). Lowing C++ into C is possible, but, again, while it 
is tempting to assume that you can just treat structs and other types 
"like C structs", the differences between compilers are going to bite 
sooner or later, so it's much saner to come up with an indirection which 
e.g. allows struct access only via native accessors.

_If_ you can trust the layouts generated by libclang (and this talk 
seems to show that this is indeed the case) - then you can do more 
tricks - e.g. use struct/class layouts almost directly (you still need 
some indirection to create them, but field access should be doable once 
you know the offsets _if you can trust them_).

Maurizio

On 14/11/2019 23:59, Luke Hutchison wrote:
> On Sat, Aug 17, 2019 at 1:20 PM Luke Hutchison <luke.hutch at gmail.com 
> <mailto:luke.hutch at gmail.com>> wrote:
>
>     Yes, lowering C++ to C is exactly what I was describing -- for
>     each syntactic construction, generating code that mimics the
>     semantics of that construction, then using partial evaluation to
>     compose these semantics into a set of generated bindings with a
>     simple C function interface.
>
>
> There is a great video here about how Rust bindings for the enormous 
> C++ library PhysX were generated by lowering the C++ API to C using 
> Clang's LibTooling. A similar approach could work for Panama.
>
> https://www.youtube.com/watch?v=RxtXGeDHu0w
> https://github.com/EmbarkStudios/physx-rs/tree/master/physx-sys
>
>


More information about the panama-dev mailing list