3 ms·
They've been putting a lot of work into an experimental automatic C++ header generator lately. https://dlang.org/changelog/2.096.0.html#dtoh-improvements https
by gavinray 6y ago
They've been putting a lot of work into an experimental automatic C++ header generator lately.
https://dlang.org/changelog/2.096.0.html#dtoh-improvements https://dlang.org/changelog/2.096.0.html#dtoh-improvements
Each changelog for the last good handful has seen a lot of work in this area.
I recently had to write and learn a bit of C++ for the first time, and tried at all costs to avoid it (FFI/interop from Rust or D).
I wound up biting the bullet and writing C++ but I learned a lot about FFI in general and how interop works, plus your options available in both languages.
D has this new experimental C++ header generator (which is exciting), plus D has always had:
extern (C++)
Which is capable of directly linking + invoking most C++ things (except constructors/destructors, it can't handle those, you need a function which calls the constructor from within C++) just given a type definition.
Then you have "d++", which lets you "#include" C/C++ headers.
Under the hood tries to run an automatic syntax conversion. It can't handle <std> but for simple code it works and can spit out the equivalent D.
https://github.com/atilaneves/dpp https://github.com/atilaneves/dpp
Also you've got "dstep", which is "A tool for converting C and Objective-C headers to D modules"
https://github.com/jacob-carlborg/dstep https://github.com/jacob-carlborg/dstep
And finally you have the somewhat abandoned (but as far as I know mostly functional) Calypso, which is a fork of the LLVM-based D compiler that supports direct interop with C++. It's a pain to build though, haven't gotten around to trying to build it, but it does look wicked cool:
https://github.com/Syniurge/Calypso https://github.com/Syniurge/Calypso
pragma (cppmap, "cppheader.h"); // tells Clang to parse cppheader.h but do not import anything
import (C++) NamespaceA.Class1; // imports NamespaceA::Class1
import (C++) NamespaceA; // imports the full namespace
import (C++) *; // imports the entire translation unit
So I am hopeful about the future of the relationship between C++ and D. I would really have loved to have not written that C++ lol.
- gmueckl 6y agoWhere is that experimental header generator? Are you talking about the -HC command line argument for dmd?
- gavinray 6y agoYeah, -HC from 2.091.0 https://dlang.org/changelog/2.091.0.html#headers https://dlang.org/changelog/2.091.0.html#headers "DMD can now write C++ header files which contain bindings for declarations in existing D files that were marked as extern(C) or extern(C++)."