Live data from Hacker News

Zngur: A C++/Rust interop tool

hkalbasi.github.io

11–20 of 33 posts

Re: Zngur: A C++/Rust interop tool

#11
post #10

Earlier quoted context omitted.

I’m using cxx/cxx-qt in a Rust QT app with substantial interop with Qt/QML and lots of C++ code (because Gpt/Claude make implementing some stuff easier in C++). It’s definitely mature enough because Qt’s libs are no joke. At this point I have a Claude project set up with Cxx documentation and it autogenerates most of my bindings.

Do you have some specific usage of Claude to help? Or how do you use Claude/Gpt for this more precisely?

IMHO, he created RAG from documentation to provide more context for Claude, so he then can call Claude with a task like "Generate bindings in Rust language for C++ class Foo from the Bar library.".

Re: Zngur: A C++/Rust interop tool

#12

I've been learning Rust and really enjoying it, but the primary downside (compared to C++) is the lack of access to the large, well-tested libraries that exist in C++. For example, my work would benefit from using the CGAL library [0], something that be nontrivial to rewrite in Rust. As much as I like Rust, at some point it's a better idea to use C++ to tap into libraries like that. Does anyone have thoughts about ho…

I’m using cxx/cxx-qt in a Rust QT app with substantial interop with Qt/QML and lots of C++ code (because Gpt/Claude make implementing some stuff easier in C++). It’s definitely mature enough because Qt’s libs are no joke. At this point I have a Claude project set up with Cxx documentation and it autogenerates most of my bindings.

How was your experience using Qt with Rust? Is it awkward writing models and QObjects in Rust?

I'm a fan of QML and would love to use Rust with it if pleasant Qt bindings are finally there.

Re: Zngur: A C++/Rust interop tool

#13
post #6

I've been learning Rust and really enjoying it, but the primary downside (compared to C++) is the lack of access to the large, well-tested libraries that exist in C++. For example, my work would benefit from using the CGAL library [0], something that be nontrivial to rewrite in Rust. As much as I like Rust, at some point it's a better idea to use C++ to tap into libraries like that. Does anyone have thoughts about ho…

So, Zngur allows you to use arbitrary Rust types in C++, store them by value in the C++ stack, and call arbitrary Rust methods and functions on them. But it doesn't bridge any C++ type into Rust, since it is not possible with the same ergonomic You want to use C++ libraries from Rust. This only does interop the other way.

It seems to do both:

https://hkalbasi.github.io/zngur/tutorial.html#calling-c-fro...

It sound like your quoted text is just saying that it’s not as ergonomic, you cannot use arbitrary C++ types directly in Rust, but you can use arbitrary Rust types in C++.

Re: Zngur: A C++/Rust interop tool

#14

I've been learning Rust and really enjoying it, but the primary downside (compared to C++) is the lack of access to the large, well-tested libraries that exist in C++. For example, my work would benefit from using the CGAL library [0], something that be nontrivial to rewrite in Rust. As much as I like Rust, at some point it's a better idea to use C++ to tap into libraries like that. Does anyone have thoughts about ho…

I’m using cxx/cxx-qt in a Rust QT app with substantial interop with Qt/QML and lots of C++ code (because Gpt/Claude make implementing some stuff easier in C++). It’s definitely mature enough because Qt’s libs are no joke. At this point I have a Claude project set up with Cxx documentation and it autogenerates most of my bindings.

Can you talk more any you Claude use?

Re: Zngur: A C++/Rust interop tool

#15
This kind of tools are great, as C++ isn't going away any time soon, and Rust is decades away to be relevant in some domains, specially those where C++ only recently took over C.

Re: Zngur: A C++/Rust interop tool

#16

I've been learning Rust and really enjoying it, but the primary downside (compared to C++) is the lack of access to the large, well-tested libraries that exist in C++. For example, my work would benefit from using the CGAL library [0], something that be nontrivial to rewrite in Rust. As much as I like Rust, at some point it's a better idea to use C++ to tap into libraries like that. Does anyone have thoughts about ho…

Zngur allows you to write functions operating over Rust types, adding methods to Rust types and implementing Rust traits for C++ and Rust types inside C++. So you can write a rusty wrapper for the C++ library inside C++.

If you want to immediately use a C++ library in Rust with minimal manual effort, check out autocxx [0]. Its generated api isn't very idiomatic Rust, and it uses Pin, moveit, ... but it covers a good percent of C++ apis and you can also make an idiomatic wrapper for it in Rust.

[0] https://docs.rs/autocxx/latest/autocxx/

Re: Zngur: A C++/Rust interop tool

#17

Earlier quoted context omitted.

I’m using cxx/cxx-qt in a Rust QT app with substantial interop with Qt/QML and lots of C++ code (because Gpt/Claude make implementing some stuff easier in C++). It’s definitely mature enough because Qt’s libs are no joke. At this point I have a Claude project set up with Cxx documentation and it autogenerates most of my bindings.

Can you talk more any you Claude use?

Not the GP, but I use Claude with aider (https://aider.chat/) to write much of my chore code. At one point I even used it to write a whole mobile app, even though I have no experience with mobile.

Re: Zngur: A C++/Rust interop tool

#18
post #6

I've been learning Rust and really enjoying it, but the primary downside (compared to C++) is the lack of access to the large, well-tested libraries that exist in C++. For example, my work would benefit from using the CGAL library [0], something that be nontrivial to rewrite in Rust. As much as I like Rust, at some point it's a better idea to use C++ to tap into libraries like that. Does anyone have thoughts about ho…

So, Zngur allows you to use arbitrary Rust types in C++, store them by value in the C++ stack, and call arbitrary Rust methods and functions on them. But it doesn't bridge any C++ type into Rust, since it is not possible with the same ergonomic You want to use C++ libraries from Rust. This only does interop the other way.

For calling C++ libraries from Rust, there is also https://crates.io/crates/cpp

Re: Zngur: A C++/Rust interop tool

#19
Having only glanced at the code I can’t offer much insight beyond “looks plausible”.

A far more important point is to address is that any FFI story with C++ that’s well executed is going to be great for the Rust ecosystem, and historically the community’s commitment to C++ interop has seemed tepid at best.

Even if one admits that Rust is strictly better than C++ for problems in the relevant domains, which seems an extraordinary claim that exceeds extraordinary evidence, there is still an ocean of C++ that we just can’t rewrite in even a decade, maybe not in a century.

There are use cases where Rust is just strictly a better choice: anything with an attack surface like a shell or an SSH daemon, or probably even a browser is an obvious candidate for a language with better reasoning about common attack vectors. I trust my Rust user land a lot more than my C userland.

But the “rewrite everything in Rust and push that via bad interop” is limiting the adoption of a cool language.

I’m a big fan of efforts to be more incremental.

Post reply on HN