I'm trying to port a C++ library to Rust. One dependency isn't open-source, and I only have access to the header files. rust-bindgen
doesn't generate valid bindings from these header files, and after searching online for a while, I came to the conclusion that I needed to write a wrapper for the aforementioned library. (This header files for this library are from https://github.com/wpilibsuite/ni-libraries, if it matters).
Because of these issues, I can't include the original header files in the wrapper's header files, but I can include the original headers in the actual cpp files.
To use classes, I've just forward-declared them, but some of these headers use typedefs and other fields inside the class as return types. There doesn't seem to be a (good) way to forward-declare or otherwise use these.
I'd like to know if my approach is correct, or if there's a better way to do this and I'm going the wrong way about this (it could be either in C++
or with rust-bindgen
itself).
An example of my current setup:
closed-source.h
class Foo {
Foo* create();
int getBar();
}
wrapper.hpp
class Foo;
Foo* foo_create();
int foo_getBar();
wrapper.cpp
#include "closed-source.h"
#include "wrapper.hpp"
Foo* foo_create() {
return Foo::create();
}
int foo_getBar(Foo* self) {
return self->getBar();
}