[LibTooling] High level C++ binding generator for rust

Hi all, I wanted to participate in this years GSoC and I’m looking for potential mentors who can
review my draft proposal

High level C++ binding generator for rust based on LibTooling


Currently many amazing projects are using C++ as there main language.
Many C++ programmers love Rust and wish to use it but are not able to
cause of existing working and well tested code. Rewriting existing
functional Robust and well tested code is not fun all the time and
is not just good engineering

Project goals

- Be flexible (provide C++ API)
- Be performant
- Provide high level Bindings
- Bindings must not introduce overhead
- Work with existing build systems like CMake and Meson to integrate 
  with existing projects


Parsing C++ is hard.

//valid cpp
__attribute((attr)) [[attr4]]
[[some_attrr2, attr3]]  decltype(auto) weridfn() {
    return 3;

Thats where LibTooling plays the main role for this project.
My plan is is to use LibTooling to parse and analyze the C++ code and emit Rust
Bindings to C++.

Passing objects by value will be very unsafe and cause various ABI bugs
such as this one.

Instead we should access objects by pointers which is a great feature of both
Rust and C++. For user convenience, we can provide smart pointers similar to
cxx and ritual crate. Every C++ object created in Rust will live on heap
and hopefully cross language LTO and compiler optimization like Copy-Ellison
will optimize the minuscule overhead away

Binding to template will be hard but we can leverage proc-macros of rust
where we can just call C++ compiler like cpp crate.

When generating bindings for large codebase which constantly changes, It is
very inefficient re-rerun entire our tool from scratch to emit new bindings.
Instead we should build our tool so that it only checks relevant files and
changed decls

Every project has different needs and different build systems. So
Our tool has to be flexible. We can thus provide our tool as C++ or Rust API
which gives more control over how bindings should be generated

Why not

  • Bindgen

    Bindgen is very low level and its primary focus is C. C++ is not completely supported

  • cxx

    Too much boilerplate to maintain

  • ritual

    Project seems to be unmaintained. It create unsafe bindings which are not ergonomic


I intent to finish this project in ~350 Hours

  • Week 1.

    Get familiar with LLVM and LibTooling.

  • Week 2.

    Implement a C++ parser

  • Week 3-4.

    Implement basic bindings between function and classes
    Find and implement the strategies to map C++ namespaces and headers to rust modules and crates

  • Week 5-6.

    Implement bindings for advance entities like overloaded functions, friends,
    abstract classes

  • Week 7.

    Find and implement the strategies to inherit C++ classes in rust and allowing
    overriding base class methods

  • Week 8.

    Implement bindings for templates

  • Week 9.

    Provide C++ API for configuring bindings

  • Week 10.

    Provide integration with CMake and Meson

  • Week 11.

    Implement incremental binding generation

  • Future

    Maintenance, new features, or even new language support

About me

I’m Smit S. Patil currently perusing my bachelors degree in Information Technology
from Sinhgad Collage of Engineering, Pune, India.
I’m a self taught programmer. I’ve been contributing
to KDE project in my free time. I have good experience with C++ and Rust.

I’m comfortable working with mentors from any timezone and understand that there working
time might be different than mine. I wont be able to work during my exams but I’m sure I can
catch up in post-exam time.

1 Like