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 #include
ing 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 -v
to see theclang
commands - Found the command that compiles
CSwiftDemangle.cpp
- Manually ran the
clang
compile with-H
flag added, to show all#include
d 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!