-
Notifications
You must be signed in to change notification settings - Fork 0
dobkeratops/cpp2rust
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
limited c++ bindings generator for Rust using clang.
"make" runs demo of sample file to stdout
very limited,will probably need some manual patching over issues
cpp2rust <options> <clang options>
-d debug dump intermediate AST
-cr write cpp2c shim, rust calls to c shim, method wrappers for those.
-n no other output (debug, emit rust translation)
-w set output base filename (default, "output") , will be postfixed with .rs, .cpp
eg
cpp2rust main.cpp -std=c++11 -x c++ -I/usr/include/x86_64-linux/gnu/c++/4.7/ -I/usr/include/clang/3.2/include
C++ INPUT:-
----------
template<typename T>
class Vector{
T *first,*last,*capacity;
...
}
class AstNode {
string name,nodeType;
Vector<AstNode> subNodes;
void dumpNode(int depth);
void foo(int value);
}
GENERATED RUST OUTPUT:-
-----------------------
struct Vector<T> {
first:*T,
last:*T,
capacity:*T
}
struct AstNode {
name:String,
type:NodeType,
subNodes:Vector<AstNode>
}
impl AstNode {
fn dumpNode(self,depth:int){ AstNode_dumpNodes(self,depth)};
fn foo(self,depth:int){ AstNode_foo(self,depth)};
}
extern{fn AstNode_dumpNodes(self_ptr:*AstNode,depth:int);}
extern{fn AstNode_foo(self_ptr:*AstNode,value:int);}
intention is to handle a limited subset of C++ with some manual translation of template implementations, but at least allowing parts of C++ interfaces (templated collection classes and methods) to generate close equivalent interfaces for Rust code - generics, structs,impls.
the main thing is to get some view of c++ structs with collections and member functions, there is no need to handle everything.
methods will be emitted with a C++ -> C wrapper, and the struct impls' will callthrough the C wrapper.
Working with my own C++ sourcebases, I can adapt to whatever subset i support; for personal use i can manually correct/fill in blanks.
see my ealier attempt to add this support to Rust bindgen.
i'm more familiar with c++ so I may get further doing this externally, plus perhaps a dedicated tool between the 2 languages can me more focussed.
About
cpp 2 rust bindings generator
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published