Do the toolchains on Swift.org come with symbol graph (
*.symbols.json) files? Or are the symbol graph files for those toolchains available for download? If so, where can I find them?
If there’s no download of symbol graphs available, is it possible to generate one without also building the whole swift compiler from scratch (i.e. with a prebuilt swift compiler)?
I’m building a prototype tool with SymbolKit which relies on symbol graphs and I’d like to incorporate knowledge about the standard library into my tool. I understand the standard library’s documentation isn’t built with docc yet but that’s fine by me. I’m really just looking for the relationships between symbols which is encoded in SymbolKit.
swift-symbolgraph-extract is what you're looking for. it can emit all of the standard library modules.
Thanks @taylorswift! Yes - I actually managed to find this tool just about the same time you posted by following links from your post about entrapta, so you've helped me find this twice!
For anyone who finds this post in the future, the incantation to extract the symbol graph for the currently installed/selected macOS SDK on macOS is this:
swift symbolgraph-extract -output-dir testout/ -target x86_64-apple-macos -sdk "$(xcrun --show-sdk-path --sdk macosx)" -module-name Swift
You can change the
-target to whatever triple you want as long as it comports with the SDK you choose.
As for extracting from a specific downloaded toolchain, you can do this too as long as your local version of Swift can read swiftmodules of that version of Swift (I believe the guarantee here is that newer versions of Swift will always be able to read swiftmodules produced by earlier versions of Swift — so if you've got Swift 5.5 you could extract the symbolgraph for Swift 5.4, but not Swift 5.6 — but I haven't tested this). For linux toolchains, this is super easy. Just download the tool chain and unzip it somewhere, then run the following (setting
$PATH_TO_TOOLCHAIN to the path to the unzipped toolchain):
swift symbolgraph-extract -output-dir testout/ -target x86_64-unknown-linux-gnu -resource-dir $PATH_TO_TOOLCHAIN/usr/lib/swift -I $PATH_TO_TOOLCHAIN/usr/lib/swift/linux/ -module-name Swift
Again, you can modify the triple to match the toolchain you downloaded and an error message will explain what triple you should use instead if you get it wrong).
I realized after doing all this that of course you can do it all with Docker images very easily if you want to:
docker run --volume ~/testout:/symbolgraphs swift:amazonlinux2 swift symbolgraph-extract -module-name Swift -target x86_64-unknown-linux-gnu -output-dir /symbolgraphs will put the Swift.symbols.json file for amazonlinux2 into
~/testout without managing any downloads at all.