Can I use the KDE Framework libraries with Rust?


#1

Hi Rust folks!

I’m looking to do some coding for KDE/Plasma. The KDE Frameworks are massive and extensive, and from browsing the API docs, there’s a documented C++ class for virtually every aspect of the system.

Would I be able to tap into those C++ libraries using Rust? I never learned C++ (I’m an old dog) and I find the concept pretty intimidating.

The language I’m most fluent in is Python. I’ve got a never-finished, always-adding-things project going on in Python & PyQt involving my own REST API allowing my MacBook to manage my media on my Linux box in my basement. So I’m not afraid of new and unusual concepts.

I’ve begun reading The Rust Book and will get Sublime set up in the morning. Hopefully, I’ll have a few Rusty answers by then.

Thanks!


#2

Technically, “yes”, although how ergonomic it will be really depends on the way the library is written.

You’ll probably want to start by checking out bindgen. It’s a tool which actually uses the Clang compiler internals as a library for parsing and inspecting C/C++ code, then tries to generate Rust bindings for calling that code. It works really well for C libraries because most of C is specified, but there are a couple things in C++ which aren’t really translatable to other languages (virtual inheritance, template specialisation, SFINAE, etc).

Once you have access to bindings and function declarations from the KDE libraries you should be able to call them just like any other library. You’re interfacing with C++ though so you’ll spend a bit of time dabbling in unsafe code, which probably isn’t the nicest intro to Rust (the main point of Rust is to write safe code after all).