rules_swift
rules_swift copied to clipboard
Provide SwiftFormat toolchain
@cgrindel and I are discussing the best way to provide formatting capabilities for Bazel swift users.
The first facility required is a Bazel repository rule that fetches a prebuilt formatter binary and exposes it as a toolchain constrained on the execution platform. It seems like rules_swift could be a good place to host that code, as it already exposes other swift tools. Of course this new toolchain would be orthogonal to the swift compiler, and only fetched if the user invokes actions which require it.
I'm not sure which formatter(s) should be included. These two seem like the obvious candidates from a quick Googling: https://github.com/nicklockwood/SwiftFormat https://github.com/apple/swift-format
@allevato @keith do you have any strong opinions on whether such a toolchain could be contributed here, or if you'd prefer it live in some other repo?
I think it would be fine for these to live in this repo if the idea is we're providing a target to bazel run like bazel run @rules_swift//:SwiftFormat. On which tool it's probably small enough of a change to just have both and let folks choose which they want to use, as long as it's easy enough to grab some binaries. That might be a bit harder for swift-format because of it's use of SwiftSyntax which requires an external library (which I generally handle with this https://github.com/keith/swift-syntax-bazel)
I ended up just grabbing the SwiftFormat binary directly and select() it based on platform.