Hello,
I'm happy to let you know that there's now enough pieces of combined documentation of multiple targets in place across Swift-DocC, Swift-DocC Render, and the Swift-DocC Plugin to enable you to try out an early, and still experimental, version of this feature for the use-case of hosting combined documentation for a Swift package together.
I've created a tiny Swift package example that hosts its combined documentation on GitHub Pages as a preview of what's supported today with the latests Swift-DocC Plugin version (1.4.2) and the Swift-DocC and Swift-DocC Render in the latest main Swift development toolchain. Below is a screenshot of one of those pages:
A few things you may notice on this page:
- The navigation hierarchy on the left-hand side displays the hierarchies for both targets in this package. This means that Quick Navigation—activated via the
/
key/button—can navigate to pages in both targets. - The top of the navigation hierarchy, displays the name of this Swift package. Clicking on this element takes you to a minimal synthesized landing page for these targets. The same page can be reached at
/documentation
. - The content of this page (from the "Outer" target) contains authored symbol links to pages from the "Inner" target. These symbol links are written with a leading slash followed by the module name and the rest of the path to the symbol. For example:
/Inner/InnerClass
. - The "Inherits From" and "Conforms To" symbol relationships are automatically turned into links to those symbols (from the other target). If you navigate to
someProperty
orsomeFunction()
you may also notice that theInnerValue
elements in their declarations is a link to that page.
Try this yourself
Building combined documentation for multiple targets with the Swift-DocC Plugin is easy. When you add the new --enable-experimental-combined-documentation
flag to your existing swift package generate-documentation
call and specify one or more targets using --target <target-name>
or --product <product-name>
, the plugin will build all the specified targets, configure them to support linking to their target dependencies' documentation, and output a documentation archive with their combined documentation.
If you're using a main Swift development toolchain you'll get a combined navigation hierarchy and a minimal synthesized landing page, like in the example above. You can download a Swift toolchain for your platform and follow the instructions on that page or use the Swiftly CLI to install a Swift development toolchain. You can use the development toolchain to build documentation with the Swift-DocC plugin by passing the toolchain path to the swift package
CLI:
swift package \
--toolchain /path/to/the-toolchain \
generate-documentation \
--enable-experimental-combined-documentation \
...
You can also use a Swift 6.0 toolchain but if you do, each target will get a separate navigation hierarchy and you won't have any landing page. You can still write links from targets to their dependencies and symbol relationships are still automatically turned into links. Note: the Swift 6.0 toolchain won't receive any further updates related to combined documentation.
We'd love for you to try this on your Swift packages and give us your feedback on what's already there, suggest enhancements, and help us find bugs. Note that this feature is experimental and may receive breaking changes.
One feature that's mentioned in the combined documentation of multiple targets thread which isn't available yet is the ability to write your own landing page and package-level articles (that aren't about to any particular target). We have some ideas for how we want to do this but we want to discuss those ideas—in a separate, future Forums thread—and wanted to let you try out what's already available before that.