r/cpp • u/TheRavagerSw • Oct 05 '26
I dislike Rust libraries with a C++ API
Cargo compilation model only really works if you are creating a monolithic shared library or an executable. If you are using a library like icu4x or libffi, you can't statically link your dependencies and even if you dynamically link your dependencies, your application size will increase by orders of magnitude because your shared libraries are all statically linked, kinda.
Monolithic shared library approach also doesn't work on all libraries, for example you can't link libraries like oneTBB and OpenMP more than once.
So overall I feel rust compilation model is a "series of hacks" and isn't worth integrating to existing C++ applications, unless you use bazel*, I'm not sure about that but people in google seem to have solved this.
7
u/pedersenk Oct 05 '26
Its refreshing to hear these valid concerns. I also agree and feel this is a big problem, slowing down the uptake of Rust.
But honestly, the vast majority of Rust developers tend not to think about things like this and work on small projects or pull in so much cruft from crates.io that its all a spaghetti mess anyway...
36
u/Sfacm Oct 05 '26
Rewrite it in C++
30
u/PersonalDatabase31 Oct 05 '26
Rewrite it in C++
21
u/AdOnly69 Oct 05 '26
Rewrite it in C++
18
u/tatstytastycakes C++ Fool Oct 05 '26 edited Oct 05 '26
Rewrite it in C++. Literally nobody is telling you that you can't.
35
u/[deleted] Oct 05 '26
Rewrite it in C++
34
u/sooka_bazooka Oct 05 '26
Rewrite it in C++
14
u/blogoman Oct 05 '26
You could post about it.
Or you could rewrite it in C++.
38
u/KFUP Oct 05 '26
Rewrite it in C++
34
u/OccasionThin7697 Oct 05 '26
Rewrite it in C++
34
u/XTBZ Oct 05 '26
Rewrite it in C++
33
u/Zealousideal_Sort521 Oct 05 '26
Rewrite it in C++
22
u/James20k P2005R0 Oct 05 '26
On one hand: I think this thread probably doesn't meet the bar for something we should keep on /r/cpp, but on the other hand I'm a grade A shitpost enthusiast so I'm torn on deleting this. Anyway:
Rewrite it in C++
7
u/Wild_Meeting1428 Oct 05 '26
Layer 8 problem?
7
u/Nothing_from_void Oct 05 '26
yeah isn't that the idea behind bazel, mixing build systems from multiple languages?
1
u/ts826848 Oct 05 '26
Do you mind elaborating on what exactly you mean by "cargo/rust compilation model"? I'm not sure I quite understand what you mean by that.
5
u/Sweet-Area-1539 Oct 06 '26
Rewrite it in Brainfuck
1
u/13steinj Oct 05 '26
No even Bazel does not solve this problem. On could maybe argue Blaze does, but I doubt that / if they have an internal ruleset that avoids this problem.
1
u/UndefinedDefined Oct 13 '26
Just don't use C++ when using Rust - why?
For deployment statically linked dependencies make sense - user is saved, doesn't have to navigate DLL hell, and the application starts in a millisecond without spending time due to relocations.
I think dynamic libs only make sense if your app is plugin-based or if you need to take advantage of existing ecosystem - like creating a Qt/KDE/Gtk/GNOME app on Linux. Rust can use dynamically linked libs btw., it's just not how rust dependencies are linked by design, unless they provide C-API, which is used as a boundary basically.
Try to compile servo via cargo, and try to compile chromium - you will see.