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

(Maybe?) port binding generator to Rust libclang

Open tgolsson opened this issue 4 years ago • 4 comments

The current binding generator in C++ is hard to compile and use, which increases friction if we want to upgrade PhysX version of expose more functionality.

I tried using the approximately equivalent Python libclang bindings to regenerate a 1:1 match of the current output but found that some info was missing around inheritance and fields, which would've lead to a complete breakage of physx-sys, which would be a hard sell.

We should investigate whether the Rust libclangd can be used to generate a more similar version of the bindings and struct-tests.

tgolsson avatar Mar 04 '21 21:03 tgolsson

Has bindgen been looked at? It can generate C++ bindings with the major restrictions being around templates.

Hentropy avatar Apr 07 '21 16:04 Hentropy

Ping @h3r2tic, who wrote the current impl. Did you investigate that?

tgolsson avatar Apr 07 '21 16:04 tgolsson

Yup! It was the first thing I tried, and at least back then bindgen gave up on most of PhysX. I don't think it had any way of handling ABI differences between platforms either.

h3r2tic avatar Apr 07 '21 17:04 h3r2tic

Digging into bindgen for C++ a bit more, this issue pops out because physx-sys had an issue like that, as well as an issue similar to what @tgolsson encountered with fields. This PR proposes changing bindgen from libclang to libtooling to resolve those issues because the latter exposes the information necessary to generate bindings appropriately, but it appears to have stalled. One of the issues raised on that PR was build difficulties, like the ones raised in this issue. The issues @h3r2tic mentioned are fixable via a pretty hefty bindings.h but that may be preferable to duplicating translation code.

Another option is generating a cxx::bridge, perhaps using bindgen since cxx has at least some support for that. However, cxx is still somewhat immature so I'm not sure how viable it is for something as beefy as PhysX.

Hentropy avatar Apr 07 '21 20:04 Hentropy

#183 transitioned pxbind to a Rust project that just clang's AST JSON output, much easier and no requirements on big clunky libraries.

Jake-Shadle avatar Mar 04 '23 08:03 Jake-Shadle