Recently, we wanted call swift-demangle from code, but calling out to the
process frequently was a bit too slow, and meant parsing the output of
-tree-only, since we wanted to access module and class names, for example.
Fortunately there's libswiftDemangle.dylib for this, but it's a C++ API.
Compiling against it requires #includeing headers from both Swift and LLVM.
Using CMake, both Swift and LLVM can easily be added as dependencies, but we build this project with SwiftPM. To build with SwiftPM, we imported the necessary headers. Roughly, here are the steps to determine which specific Swift and LLVM headers were required, so that they could be imported to the repo.
- Created a small CMake project with Swift and LLVM as dependencies
- Ran
ninja -vto see theclangcommands - Found the command that compiles
CSwiftDemangle.cpp - Manually ran the
clangcompile with-Hflag added, to show all#included headers - Grepped this output for the paths matching my Swift checkout
The matching paths from step 5 were the files I imported into our repo.
Wow, this is awesome!