Hey,
I hope this is the right place to ask this questions, I wasn't sure whether it belongs to "Source Tooling" or not.
I'm currently writing a library to bridge Java and Swift. For that I need various informations about the functions/types etc. in a swift library, to write java binding code.
These information include, but are not limited to:
- Mangled name of functions and types
- The function signature
- the function declaration order (to calculate vtable offsets)
I have found multiple ways to parse some of the information, but they were all lacking something so far.
- Some librarys are shipped/build with a
*.abi.json
file. This file is ideal since it contains everything I need and is easy to parse. However, it doesn't seem to be always existent for swift librarys, so it is not feasable. - Swiftlibrarys seem to get shipped with a
*.swiftinterface
file, which contains all declarations in correct order. This file can be parsed and traversed with something like SwiftSyntax, but it lacks mangled names. I also haven't found any easy to use a name mangler. - Since the
*.swiftinterface
is pretty close to valid swift code, I tried to compile it (with a bit pre-processing) and produce a*.abi.json
file for 1. While this works fine for smaller projects, converting the.swiftinterface
file to valid swift code gets pretty hard. - Using
swift symbolgraph-extract
on the*.swiftdoc
file produces a .json with the function signature, mangled names etc., but the declaration order is messed up thus preventing the calculation of vtable offsets.
These were all the ideas I had and tried. Is there any good way to retrieve all the needed information from a swift library I oversaw?
The last option I see is combining 2. and 4., getting the declaration order from the *.swiftinterface
file and getting the rest from the *.swiftdoc
. However that is a bit complicated and ugly, so I wanted to ask here first whether someone knows a better way.
Thanks in advance!