rules_swift
rules_swift copied to clipboard
Expose additional utilities through swift_common for custom swift libraries
3rd party consumers of rules_swift may wish to create custom rules which behave similar to swift_library from the perspective of other rules and tools.
Right now this is a fairly complex process as you would need to reimplement or fork some logic which is currently internal to rules_swift. It is easy to make mistakes, or this logic could diverge from the rules_swift implementation over time.
I want to provide, through swift_common, an API which is basically just "give us a list of swift source files and their dependencies, and we'll compile them for you and create the necessary providers".
This PR does exactly that, and provides an example demonstrating how easy it is to create such a rule using these utilities from swift_common.
One question you might ask is, "Why not just create a macro which runs your custom rule to create swift source file(s) as outputs, and pass those to a real swift_library target?"
This can work for some simpler use cases, but when your rule does complex logic involving aspects and other custom rules, things break down quickly. It also creates additional targets in the build graph which could be confusing for consumers.